This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
compiler/stable_mir/src/mir
tests/ui-fulldeps/stable-mir Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ impl Instance {
3939 with ( |context| context. instance_body ( self . def ) )
4040 }
4141
42+ /// Check whether this instance has a body available.
43+ ///
44+ /// This call is much cheaper than `instance.body().is_some()`, since it doesn't try to build
45+ /// the StableMIR body.
46+ pub fn has_body ( & self ) -> bool {
47+ with ( |cx| cx. has_body ( self . def . def_id ( ) ) )
48+ }
49+
4250 pub fn is_foreign_item ( & self ) -> bool {
4351 with ( |cx| cx. is_foreign_item ( self . def . def_id ( ) ) )
4452 }
Original file line number Diff line number Diff line change @@ -64,9 +64,12 @@ fn test_body(body: mir::Body) {
6464 let RigidTy :: FnDef ( def, args) = ty else { unreachable ! ( ) } ;
6565 let instance = Instance :: resolve ( def, & args) . unwrap ( ) ;
6666 let mangled_name = instance. mangled_name ( ) ;
67- let body = instance. body ( ) ;
68- assert ! ( body. is_some( ) || ( mangled_name == "setpwent" ) , "Failed: {func:?}" ) ;
69- assert ! ( body. is_some( ) ^ instance. is_foreign_item( ) ) ;
67+ assert ! ( instance. has_body( ) || ( mangled_name == "setpwent" ) , "Failed: {func:?}" ) ;
68+ assert ! ( instance. has_body( ) ^ instance. is_foreign_item( ) ) ;
69+ if instance. has_body ( ) {
70+ let body = instance. body ( ) . unwrap ( ) ;
71+ assert ! ( !body. locals( ) . is_empty( ) , "Body must at least have a return local" ) ;
72+ }
7073 }
7174 Goto { .. } | Assert { .. } | SwitchInt { .. } | Return | Drop { .. } => {
7275 /* Do nothing */
You can’t perform that action at this time.
0 commit comments