diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 0bd640ee1e3..301ba79bfbe 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -187,9 +187,9 @@ fn item_kind(&self, item: CrateItem) -> ItemKind { new_item_kind(tables.tcx.def_kind(tables[item.0])) } - fn is_foreign_item(&self, item: CrateItem) -> bool { + fn is_foreign_item(&self, item: DefId) -> bool { let tables = self.0.borrow(); - tables.tcx.is_foreign_item(tables[item.0]) + tables.tcx.is_foreign_item(tables[item]) } fn adt_kind(&self, def: AdtDef) -> AdtKind { diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index daf4465963e..1bbcc257dfc 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -60,7 +60,7 @@ pub trait Context { fn item_kind(&self, item: CrateItem) -> ItemKind; /// Returns whether this is a foreign item. - fn is_foreign_item(&self, item: CrateItem) -> bool; + fn is_foreign_item(&self, item: DefId) -> bool; /// Returns the kind of a given algebraic data type fn adt_kind(&self, def: AdtDef) -> AdtKind; diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs index 2099c485c6f..1e7495009d8 100644 --- a/compiler/stable_mir/src/lib.rs +++ b/compiler/stable_mir/src/lib.rs @@ -120,7 +120,7 @@ pub fn ty(&self) -> Ty { } pub fn is_foreign_item(&self) -> bool { - with(|cx| cx.is_foreign_item(*self)) + with(|cx| cx.is_foreign_item(self.0)) } pub fn dump(&self, w: &mut W) -> io::Result<()> { diff --git a/compiler/stable_mir/src/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index 10270c82e63..541a8376a62 100644 --- a/compiler/stable_mir/src/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -40,8 +40,7 @@ pub fn body(&self) -> Option { } pub fn is_foreign_item(&self) -> bool { - let item = CrateItem::try_from(*self); - item.as_ref().is_ok_and(CrateItem::is_foreign_item) + with(|cx| cx.is_foreign_item(self.def.def_id())) } /// Get the instance type with generic substitutions applied and lifetimes erased. diff --git a/tests/ui-fulldeps/stable-mir/check_instance.rs b/tests/ui-fulldeps/stable-mir/check_instance.rs index 976dfee774b..2b590d2eff7 100644 --- a/tests/ui-fulldeps/stable-mir/check_instance.rs +++ b/tests/ui-fulldeps/stable-mir/check_instance.rs @@ -65,7 +65,8 @@ fn test_body(body: mir::Body) { let instance = Instance::resolve(def, &args).unwrap(); let mangled_name = instance.mangled_name(); let body = instance.body(); - assert!(body.is_some() || mangled_name == "setpwent", "Failed: {func:?}"); + assert!(body.is_some() || (mangled_name == "setpwent"), "Failed: {func:?}"); + assert!(body.is_some() ^ instance.is_foreign_item()); } Goto { .. } | Assert { .. } | SwitchInt { .. } | Return | Drop { .. } => { /* Do nothing */