Add impl_constness query

This commit is contained in:
Deadbeef 2021-07-10 11:15:11 +08:00
parent 032cbe4cce
commit 89d190f090
No known key found for this signature in database
GPG Key ID: 6525773485376D92
6 changed files with 29 additions and 3 deletions

View File

@ -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<ty::adjustment::CoerceUnsizedInfo> {
self.get_impl_data(id).coerce_unsized_info
}

View File

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

View File

@ -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))
}

View File

@ -390,6 +390,7 @@ struct TraitData {
#[derive(TyEncodable, TyDecodable)]
struct ImplData {
polarity: ty::ImplPolarity,
constness: hir::Constness,
defaultness: hir::Defaultness,
parent_impl: Option<DefId>,

View File

@ -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()) }
}

View File

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