diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 3860d0daadf9..344c5e8ee618 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -959,6 +959,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { self.get_impl_data(id).defaultness } + fn get_impl_constness(&self, id: DefIndex) -> hir::Constness { + self.get_impl_data(id).constness + } + fn get_coerce_unsized_info(&self, id: DefIndex) -> Option { self.get_impl_data(id).coerce_unsized_info } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 68cf4304b716..c0e85d82f7e2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -168,6 +168,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, is_no_builtins => { cdata.root.no_builtins } symbol_mangling_version => { cdata.root.symbol_mangling_version } impl_defaultness => { cdata.get_impl_defaultness(def_id.index) } + impl_constness => { cdata.get_impl_constness(def_id.index) } reachable_non_generics => { let reachable_non_generics = tcx .exported_symbols(cdata.cnum) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 2478d15e554c..5b10d53159eb 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1412,7 +1412,7 @@ impl EncodeContext<'a, 'tcx> { adt_def.repr, ) } - hir::ItemKind::Impl(hir::Impl { defaultness, .. }) => { + hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => { let trait_ref = self.tcx.impl_trait_ref(def_id); let polarity = self.tcx.impl_polarity(def_id); let parent = if let Some(trait_ref) = trait_ref { @@ -1437,8 +1437,13 @@ impl EncodeContext<'a, 'tcx> { } }); - let data = - ImplData { polarity, defaultness, parent_impl: parent, coerce_unsized_info }; + let data = ImplData { + polarity, + defaultness, + constness, + parent_impl: parent, + coerce_unsized_info, + }; EntryKind::Impl(self.lazy(data)) } diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 379305806234..0d67ff32a3f3 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -390,6 +390,7 @@ struct TraitData { #[derive(TyEncodable, TyDecodable)] struct ImplData { polarity: ty::ImplPolarity, + constness: hir::Constness, defaultness: hir::Defaultness, parent_impl: Option, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 9a2f1149316e..1a1bb37f70a5 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1136,6 +1136,10 @@ rustc_queries! { desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) } } + query impl_constness(def_id: DefId) -> hir::Constness { + desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) } + } + query check_item_well_formed(key: LocalDefId) -> () { desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) } } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index ffde9b79265a..b0d644ae028c 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -168,6 +168,16 @@ fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness { } } +fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness { + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); + let item = tcx.hir().expect_item(hir_id); + if let hir::ItemKind::Impl(impl_) = &item.kind { + impl_.constness + } else { + bug!("`impl_constness` called on {:?}", item); + } +} + /// Calculates the `Sized` constraint. /// /// In fact, there are only a few options for the types in the constraint: @@ -535,6 +545,7 @@ pub fn provide(providers: &mut ty::query::Providers) { instance_def_size_estimate, issue33140_self_ty, impl_defaultness, + impl_constness, conservative_is_privately_uninhabited: conservative_is_privately_uninhabited_raw, ..*providers };