diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2025-08-13 14:36:13 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2025-09-12 15:14:15 -0500 |
| commit | b995a55cafcbcafec51aba6c567b32161fa9c2f1 (patch) | |
| tree | 853fd2e3bc6faedf1af0f98797144eaba922dfa7 /compiler | |
| parent | 9615ec7d108399501d7d48f4aeac46561ef31fc8 (diff) | |
| download | rust-b995a55cafcbcafec51aba6c567b32161fa9c2f1.tar.gz rust-b995a55cafcbcafec51aba6c567b32161fa9c2f1.zip | |
Don't store defaultness for inherent impl items
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_metadata/src/rmeta/encoder.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/assoc.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 4 |
4 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index cb603705ce1..db66938457f 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1725,7 +1725,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let tcx = self.tcx; let item = tcx.associated_item(def_id); - self.tables.defaultness.set_some(def_id.index, item.defaultness(tcx)); + if matches!(item.container, AssocContainer::Trait | AssocContainer::TraitImpl(_)) { + self.tables.defaultness.set_some(def_id.index, item.defaultness(tcx)); + } + record!(self.tables.assoc_container[def_id] <- item.container); if let AssocContainer::Trait = item.container diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 2aa32dfa0d8..0e645a3aae4 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1881,6 +1881,7 @@ rustc_queries! { } /// Returns whether the impl or associated function has the `default` keyword. + /// Note: This will ICE on inherent impl items. Consider using `AssocItem::defaultness`. query defaultness(def_id: DefId) -> hir::Defaultness { desc { |tcx| "looking up whether `{}` has `default`", tcx.def_path_str(def_id) } separate_provide_extern diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 60181783f9b..768646c7630 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -53,7 +53,10 @@ impl AssocItem { /// /// [`type_of`]: crate::ty::TyCtxt::type_of pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness { - tcx.defaultness(self.def_id) + match self.container { + AssocContainer::InherentImpl => hir::Defaultness::Final, + AssocContainer::Trait | AssocContainer::TraitImpl(_) => tcx.defaultness(self.def_id), + } } pub fn expect_trait_impl(&self) -> Result<DefId, ErrorGuaranteed> { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index b3f2bb6d4b5..a5987757dc3 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -93,10 +93,6 @@ fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness { .. }) | hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness, - hir::Node::ImplItem(hir::ImplItem { - impl_kind: hir::ImplItemImplKind::Inherent { .. }, - .. - }) => hir::Defaultness::Final, node => { bug!("`defaultness` called on {:?}", node); } |
