@@ -140,6 +140,29 @@ fn test_stable_mir(_tcx: TyCtxt<'_>) -> ControlFlow<()> {
140140 // Ensure we don't panic trying to get the body of a constant.
141141 foo_const. body ( ) ;
142142
143+ let locals_fn = get_item ( & items, ( DefKind :: Fn , "locals" ) ) . unwrap ( ) ;
144+ let body = locals_fn. body ( ) ;
145+ assert_eq ! ( body. locals( ) . len( ) , 4 ) ;
146+ assert_matches ! (
147+ body. ret_local( ) . ty. kind( ) ,
148+ stable_mir:: ty:: TyKind :: RigidTy ( stable_mir:: ty:: RigidTy :: Char )
149+ ) ;
150+ assert_eq ! ( body. arg_locals( ) . len( ) , 2 ) ;
151+ assert_matches ! (
152+ body. arg_locals( ) [ 0 ] . ty. kind( ) ,
153+ stable_mir:: ty:: TyKind :: RigidTy ( stable_mir:: ty:: RigidTy :: Int ( stable_mir:: ty:: IntTy :: I32 ) )
154+ ) ;
155+ assert_matches ! (
156+ body. arg_locals( ) [ 1 ] . ty. kind( ) ,
157+ stable_mir:: ty:: TyKind :: RigidTy ( stable_mir:: ty:: RigidTy :: Uint ( stable_mir:: ty:: UintTy :: U64 ) )
158+ ) ;
159+ assert_eq ! ( body. inner_locals( ) . len( ) , 1 ) ;
160+ // If conditions have an extra inner local to hold their results
161+ assert_matches ! (
162+ body. inner_locals( ) [ 0 ] . ty. kind( ) ,
163+ stable_mir:: ty:: TyKind :: RigidTy ( stable_mir:: ty:: RigidTy :: Bool )
164+ ) ;
165+
143166 ControlFlow :: Continue ( ( ) )
144167}
145168
@@ -211,6 +234,14 @@ fn generate_input(path: &str) -> std::io::Result<()> {
211234
212235 pub fn assert(x: i32) -> i32 {{
213236 x + 1
237+ }}
238+
239+ pub fn locals(a: i32, _: u64) -> char {{
240+ if a > 5 {{
241+ 'a'
242+ }} else {{
243+ 'b'
244+ }}
214245 }}"#
215246 ) ?;
216247 Ok ( ( ) )
0 commit comments