Skip to content

Commit 89d190f

Browse files
committed
Add impl_constness query
1 parent 032cbe4 commit 89d190f

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
959959
self.get_impl_data(id).defaultness
960960
}
961961

962+
fn get_impl_constness(&self, id: DefIndex) -> hir::Constness {
963+
self.get_impl_data(id).constness
964+
}
965+
962966
fn get_coerce_unsized_info(&self, id: DefIndex) -> Option<ty::adjustment::CoerceUnsizedInfo> {
963967
self.get_impl_data(id).coerce_unsized_info
964968
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
168168
is_no_builtins => { cdata.root.no_builtins }
169169
symbol_mangling_version => { cdata.root.symbol_mangling_version }
170170
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
171+
impl_constness => { cdata.get_impl_constness(def_id.index) }
171172
reachable_non_generics => {
172173
let reachable_non_generics = tcx
173174
.exported_symbols(cdata.cnum)

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ impl EncodeContext<'a, 'tcx> {
14121412
adt_def.repr,
14131413
)
14141414
}
1415-
hir::ItemKind::Impl(hir::Impl { defaultness, .. }) => {
1415+
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
14161416
let trait_ref = self.tcx.impl_trait_ref(def_id);
14171417
let polarity = self.tcx.impl_polarity(def_id);
14181418
let parent = if let Some(trait_ref) = trait_ref {
@@ -1437,8 +1437,13 @@ impl EncodeContext<'a, 'tcx> {
14371437
}
14381438
});
14391439

1440-
let data =
1441-
ImplData { polarity, defaultness, parent_impl: parent, coerce_unsized_info };
1440+
let data = ImplData {
1441+
polarity,
1442+
defaultness,
1443+
constness,
1444+
parent_impl: parent,
1445+
coerce_unsized_info,
1446+
};
14421447

14431448
EntryKind::Impl(self.lazy(data))
14441449
}

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ struct TraitData {
390390
#[derive(TyEncodable, TyDecodable)]
391391
struct ImplData {
392392
polarity: ty::ImplPolarity,
393+
constness: hir::Constness,
393394
defaultness: hir::Defaultness,
394395
parent_impl: Option<DefId>,
395396

compiler/rustc_middle/src/query/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,10 @@ rustc_queries! {
11361136
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
11371137
}
11381138

1139+
query impl_constness(def_id: DefId) -> hir::Constness {
1140+
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
1141+
}
1142+
11391143
query check_item_well_formed(key: LocalDefId) -> () {
11401144
desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key.to_def_id()) }
11411145
}

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness {
168168
}
169169
}
170170

171+
fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
172+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
173+
let item = tcx.hir().expect_item(hir_id);
174+
if let hir::ItemKind::Impl(impl_) = &item.kind {
175+
impl_.constness
176+
} else {
177+
bug!("`impl_constness` called on {:?}", item);
178+
}
179+
}
180+
171181
/// Calculates the `Sized` constraint.
172182
///
173183
/// 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) {
535545
instance_def_size_estimate,
536546
issue33140_self_ty,
537547
impl_defaultness,
548+
impl_constness,
538549
conservative_is_privately_uninhabited: conservative_is_privately_uninhabited_raw,
539550
..*providers
540551
};

0 commit comments

Comments
 (0)