@@ -27,7 +27,7 @@ use std::ops::ControlFlow;
2727const CRATE_NAME : & str = "input" ;
2828
2929/// 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 < ( ) > {
3131 // Get the local crate using stable_mir API.
3232 let local = stable_mir:: local_crate ( ) ;
3333 assert_eq ! ( & local. name, CRATE_NAME ) ;
@@ -36,12 +36,12 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
3636
3737 // Find items in the local crate.
3838 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( ) ) ;
4040
4141 // Find the `std` crate.
4242 assert ! ( stable_mir:: find_crate( "std" ) . is_some( ) ) ;
4343
44- let bar = get_item ( tcx , & items, ( DefKind :: Fn , "bar" ) ) . unwrap ( ) ;
44+ let bar = get_item ( & items, ( DefKind :: Fn , "bar" ) ) . unwrap ( ) ;
4545 let body = bar. body ( ) ;
4646 assert_eq ! ( body. locals. len( ) , 2 ) ;
4747 assert_eq ! ( body. blocks. len( ) , 1 ) ;
@@ -56,7 +56,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
5656 other => panic ! ( "{other:?}" ) ,
5757 }
5858
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 ( ) ;
6060 let body = foo_bar. body ( ) ;
6161 assert_eq ! ( body. locals. len( ) , 7 ) ;
6262 assert_eq ! ( body. blocks. len( ) , 4 ) ;
@@ -66,7 +66,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
6666 other => panic ! ( "{other:?}" ) ,
6767 }
6868
69- let types = get_item ( tcx , & items, ( DefKind :: Fn , "types" ) ) . unwrap ( ) ;
69+ let types = get_item ( & items, ( DefKind :: Fn , "types" ) ) . unwrap ( ) ;
7070 let body = types. body ( ) ;
7171 assert_eq ! ( body. locals. len( ) , 6 ) ;
7272 assert_matches ! (
@@ -96,7 +96,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
9696 ) )
9797 ) ;
9898
99- let drop = get_item ( tcx , & items, ( DefKind :: Fn , "drop" ) ) . unwrap ( ) ;
99+ let drop = get_item ( & items, ( DefKind :: Fn , "drop" ) ) . unwrap ( ) ;
100100 let body = drop. body ( ) ;
101101 assert_eq ! ( body. blocks. len( ) , 2 ) ;
102102 let block = & body. blocks [ 0 ] ;
@@ -105,7 +105,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
105105 other => panic ! ( "{other:?}" ) ,
106106 }
107107
108- let assert = get_item ( tcx , & items, ( DefKind :: Fn , "assert" ) ) . unwrap ( ) ;
108+ let assert = get_item ( & items, ( DefKind :: Fn , "assert" ) ) . unwrap ( ) ;
109109 let body = assert. body ( ) ;
110110 assert_eq ! ( body. blocks. len( ) , 2 ) ;
111111 let block = & body. blocks [ 0 ] ;
@@ -114,7 +114,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
114114 other => panic ! ( "{other:?}" ) ,
115115 }
116116
117- let monomorphic = get_item ( tcx , & items, ( DefKind :: Fn , "monomorphic" ) ) . unwrap ( ) ;
117+ let monomorphic = get_item ( & items, ( DefKind :: Fn , "monomorphic" ) ) . unwrap ( ) ;
118118 for block in monomorphic. body ( ) . blocks {
119119 match & block. terminator {
120120 stable_mir:: mir:: Terminator :: Call { func, .. } => match func {
@@ -154,7 +154,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
154154 }
155155 }
156156
157- let foo_const = get_item ( tcx , & items, ( DefKind :: Const , "FOO" ) ) . unwrap ( ) ;
157+ let foo_const = get_item ( & items, ( DefKind :: Const , "FOO" ) ) . unwrap ( ) ;
158158 // Ensure we don't panic trying to get the body of a constant.
159159 foo_const. body ( ) ;
160160
@@ -163,13 +163,11 @@ fn test_stable_mir(tcx: TyCtxt<'_>) -> ControlFlow<()> {
163163
164164// Use internal API to find a function in a crate.
165165fn get_item < ' a > (
166- tcx : TyCtxt ,
167166 items : & ' a stable_mir:: CrateItems ,
168167 item : ( DefKind , & str ) ,
169168) -> Option < & ' a stable_mir:: CrateItem > {
170169 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
173171 } )
174172}
175173
0 commit comments