1
Fork 0

Fix is_foreign_item for StableMIR instance

Change the implementation of `Instance::is_foreign_item` to directly
query the compiler for the instance `def_id` instead of incorrectly
relying on the conversion to `CrateItem`.

Background:

- In pull https://github.com/rust-lang/rust/pull/118524, I fixed the
  conversion from Instance to CrateItem to avoid the conversion if the
  instance didn't have a body available. This broke the `is_foreign_item`.
This commit is contained in:
Celina G. Val 2023-12-06 10:48:18 -08:00
parent f32d29837d
commit 1bcd162465
5 changed files with 7 additions and 7 deletions

View file

@ -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;

View file

@ -120,7 +120,7 @@ impl CrateItem {
}
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<W: io::Write>(&self, w: &mut W) -> io::Result<()> {

View file

@ -40,8 +40,7 @@ impl Instance {
}
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.