File tree 2 files changed +14
-3
lines changed
compiler/stable_mir/src/mir
tests/ui-fulldeps/stable-mir
2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,14 @@ impl Instance {
39
39
with ( |context| context. instance_body ( self . def ) )
40
40
}
41
41
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
+
42
50
pub fn is_foreign_item ( & self ) -> bool {
43
51
with ( |cx| cx. is_foreign_item ( self . def . def_id ( ) ) )
44
52
}
Original file line number Diff line number Diff line change @@ -64,9 +64,12 @@ fn test_body(body: mir::Body) {
64
64
let RigidTy :: FnDef ( def, args) = ty else { unreachable ! ( ) } ;
65
65
let instance = Instance :: resolve ( def, & args) . unwrap ( ) ;
66
66
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
+ }
70
73
}
71
74
Goto { .. } | Assert { .. } | SwitchInt { .. } | Return | Drop { .. } => {
72
75
/* Do nothing */
You can’t perform that action at this time.
0 commit comments