diff options
| author | bors <bors@rust-lang.org> | 2023-03-30 02:59:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-30 02:59:25 +0000 |
| commit | 82bfda848e28d7616c7045d7ced8cee88d2d1a8f (patch) | |
| tree | 616c98d4020a1d6355cecba28f62d3b307ebca30 /tests | |
| parent | 10338571cfa7c2be0aeed309141ced91454d41e1 (diff) | |
| parent | 480e042097573ad518e43cf2ee8f17ecb755693a (diff) | |
| download | rust-82bfda848e28d7616c7045d7ced8cee88d2d1a8f.tar.gz rust-82bfda848e28d7616c7045d7ced8cee88d2d1a8f.zip | |
Auto merge of #109224 - oli-obk:smir, r=pnkfelix
Stable MIR: Add basic MIR body datastructures At this point it will panic on most useful MIR, but you can do basic assignments r? `@pnkfelix`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui-fulldeps/stable-mir/crate-info.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs index 4458ab0162e..99b653f20b6 100644 --- a/tests/ui-fulldeps/stable-mir/crate-info.rs +++ b/tests/ui-fulldeps/stable-mir/crate-info.rs @@ -4,6 +4,7 @@ // ignore-stage-1 // ignore-cross-compile // ignore-remote +// edition: 2021 #![feature(rustc_private)] @@ -30,16 +31,34 @@ fn test_stable_mir(tcx: TyCtxt<'_>) { // Find items in the local crate. let items = stable_mir::all_local_items(); - assert!(has_item(tcx, &items, (DefKind::Fn, "foo_bar"))); - assert!(has_item(tcx, &items, (DefKind::Fn, "foo::bar"))); + assert!(get_item(tcx, &items, (DefKind::Fn, "foo_bar")).is_some()); + assert!(get_item(tcx, &items, (DefKind::Fn, "foo::bar")).is_some()); // Find the `std` crate. assert!(stable_mir::find_crate("std").is_some()); + + let bar = get_item(tcx, &items, (DefKind::Fn, "bar")).unwrap(); + let body = bar.body(); + assert_eq!(body.blocks.len(), 1); + let block = &body.blocks[0]; + assert_eq!(block.statements.len(), 1); + match &block.statements[0] { + stable_mir::mir::Statement::Assign(..) => {} + other => panic!("{other:?}"), + } + match &block.terminator { + stable_mir::mir::Terminator::Return => {} + other => panic!("{other:?}"), + } } // Use internal API to find a function in a crate. -fn has_item(tcx: TyCtxt, items: &stable_mir::CrateItems, item: (DefKind, &str)) -> bool { - items.iter().any(|crate_item| { +fn get_item<'a>( + tcx: TyCtxt, + items: &'a stable_mir::CrateItems, + item: (DefKind, &str), +) -> Option<&'a stable_mir::CrateItem> { + items.iter().find(|crate_item| { let def_id = rustc_internal::item_def_id(crate_item); tcx.def_kind(def_id) == item.0 && tcx.def_path_str(def_id) == item.1 }) @@ -94,6 +113,10 @@ fn generate_input(path: &str) -> std::io::Result<()> { }} }} + pub fn bar(x: i32) -> i32 {{ + x + }} + pub fn foo_bar(x: i32, y: i32) -> i64 {{ let x_64 = foo::bar(x); let y_64 = foo::bar(y); |
