@@ -27,7 +27,7 @@ use std::ops::ControlFlow;
27
27
const CRATE_NAME : & str = "input" ;
28
28
29
29
/// This function uses the Stable MIR APIs to get information about the test crate.
30
- fn test_stable_mir ( tcx : TyCtxt < ' _ > ) -> ControlFlow < ( ) > {
30
+ fn test_stable_mir ( _tcx : TyCtxt < ' _ > ) -> ControlFlow < ( ) > {
31
31
// Get the local crate using stable_mir API.
32
32
let local = stable_mir:: local_crate ( ) ;
33
33
assert_eq ! ( & local. name, CRATE_NAME ) ;
@@ -36,12 +36,12 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
36
36
37
37
// Find items in the local crate.
38
38
let items = stable_mir:: all_local_items ( ) ;
39
- assert ! ( get_item( tcx , & items, ( DefKind :: Fn , "foo::bar" ) ) . is_some( ) ) ;
39
+ assert ! ( get_item( & items, ( DefKind :: Fn , "foo::bar" ) ) . is_some( ) ) ;
40
40
41
41
// Find the `std` crate.
42
42
assert ! ( stable_mir:: find_crate( "std" ) . is_some( ) ) ;
43
43
44
- let bar = get_item ( tcx , & items, ( DefKind :: Fn , "bar" ) ) . unwrap ( ) ;
44
+ let bar = get_item ( & items, ( DefKind :: Fn , "bar" ) ) . unwrap ( ) ;
45
45
let body = bar. body ( ) ;
46
46
assert_eq ! ( body. locals. len( ) , 2 ) ;
47
47
assert_eq ! ( body. blocks. len( ) , 1 ) ;
@@ -56,7 +56,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
56
56
other => panic ! ( "{other:?}" ) ,
57
57
}
58
58
59
- let foo_bar = get_item ( tcx , & items, ( DefKind :: Fn , "foo_bar" ) ) . unwrap ( ) ;
59
+ let foo_bar = get_item ( & items, ( DefKind :: Fn , "foo_bar" ) ) . unwrap ( ) ;
60
60
let body = foo_bar. body ( ) ;
61
61
assert_eq ! ( body. locals. len( ) , 7 ) ;
62
62
assert_eq ! ( body. blocks. len( ) , 4 ) ;
@@ -66,7 +66,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
66
66
other => panic ! ( "{other:?}" ) ,
67
67
}
68
68
69
- let types = get_item ( tcx , & items, ( DefKind :: Fn , "types" ) ) . unwrap ( ) ;
69
+ let types = get_item ( & items, ( DefKind :: Fn , "types" ) ) . unwrap ( ) ;
70
70
let body = types. body ( ) ;
71
71
assert_eq ! ( body. locals. len( ) , 6 ) ;
72
72
assert_matches ! (
@@ -96,7 +96,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
96
96
) )
97
97
) ;
98
98
99
- let drop = get_item ( tcx , & items, ( DefKind :: Fn , "drop" ) ) . unwrap ( ) ;
99
+ let drop = get_item ( & items, ( DefKind :: Fn , "drop" ) ) . unwrap ( ) ;
100
100
let body = drop. body ( ) ;
101
101
assert_eq ! ( body. blocks. len( ) , 2 ) ;
102
102
let block = & body. blocks [ 0 ] ;
@@ -105,7 +105,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
105
105
other => panic ! ( "{other:?}" ) ,
106
106
}
107
107
108
- let assert = get_item ( tcx , & items, ( DefKind :: Fn , "assert" ) ) . unwrap ( ) ;
108
+ let assert = get_item ( & items, ( DefKind :: Fn , "assert" ) ) . unwrap ( ) ;
109
109
let body = assert. body ( ) ;
110
110
assert_eq ! ( body. blocks. len( ) , 2 ) ;
111
111
let block = & body. blocks [ 0 ] ;
@@ -114,7 +114,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
114
114
other => panic ! ( "{other:?}" ) ,
115
115
}
116
116
117
- let monomorphic = get_item ( tcx , & items, ( DefKind :: Fn , "monomorphic" ) ) . unwrap ( ) ;
117
+ let monomorphic = get_item ( & items, ( DefKind :: Fn , "monomorphic" ) ) . unwrap ( ) ;
118
118
for block in monomorphic. body ( ) . blocks {
119
119
match & block. terminator {
120
120
stable_mir:: mir:: Terminator :: Call { func, .. } => match func {
@@ -154,7 +154,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
154
154
}
155
155
}
156
156
157
- let foo_const = get_item ( tcx , & items, ( DefKind :: Const , "FOO" ) ) . unwrap ( ) ;
157
+ let foo_const = get_item ( & items, ( DefKind :: Const , "FOO" ) ) . unwrap ( ) ;
158
158
// Ensure we don't panic trying to get the body of a constant.
159
159
foo_const. body ( ) ;
160
160
@@ -163,13 +163,11 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
163
163
164
164
// Use internal API to find a function in a crate.
165
165
fn get_item < ' a > (
166
- tcx : TyCtxt ,
167
166
items : & ' a stable_mir:: CrateItems ,
168
167
item : ( DefKind , & str ) ,
169
168
) -> Option < & ' a stable_mir:: CrateItem > {
170
169
items. iter ( ) . find ( |crate_item| {
171
- let def_id = rustc_internal:: item_def_id ( crate_item) ;
172
- tcx. def_kind ( def_id) == item. 0 && tcx. def_path_str ( def_id) == item. 1
170
+ crate_item. kind ( ) . to_string ( ) == format ! ( "{:?}" , item. 0 ) && crate_item. name ( ) == item. 1
173
171
} )
174
172
}
175
173
0 commit comments