Add rustc_ty_to_ty basic tests

This commit is contained in:
Santiago Pastorino 2023-07-05 18:50:13 -03:00
parent 284df9fc34
commit 61adcaf87b
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
2 changed files with 20 additions and 0 deletions

View File

@ -9,10 +9,12 @@ impl Ty {
}
}
#[derive(Clone, Debug)]
pub enum TyKind {
RigidTy(RigidTy),
}
#[derive(Clone, Debug)]
pub enum RigidTy {
Bool,
Tuple(Vec<Ty>),

View File

@ -7,6 +7,7 @@
// edition: 2021
#![feature(rustc_private)]
#![feature(assert_matches)]
extern crate rustc_driver;
extern crate rustc_hir;
@ -19,6 +20,7 @@ use rustc_hir::def::DefKind;
use rustc_interface::{interface, Queries};
use rustc_middle::ty::TyCtxt;
use rustc_smir::{rustc_internal, stable_mir};
use std::assert_matches::assert_matches;
use std::io::Write;
const CRATE_NAME: &str = "input";
@ -63,6 +65,18 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
other => panic!("{other:?}"),
}
let types = get_item(tcx, &items, (DefKind::Fn, "types")).unwrap();
let body = types.body();
assert_eq!(body.locals.len(), 2);
assert_matches!(
body.locals[0].kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
);
assert_matches!(
body.locals[1].kind(),
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
);
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
let body = drop.body();
assert_eq!(body.blocks.len(), 2);
@ -153,6 +167,10 @@ fn generate_input(path: &str) -> std::io::Result<()> {
x_64.wrapping_add(y_64)
}}
pub fn types(b: bool) -> bool {{
b
}}
pub fn drop(_: String) {{}}
pub fn assert(x: i32) -> i32 {{