Skip to content

Commit 26ac456

Browse files
committed
Rename impl_constness to constness
The current code is a basis for `is_const_fn_raw`, and `impl_constness` is no longer a valid name, which is previously used for determining the constness of impls, and not items in general.
1 parent 389352c commit 26ac456

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
1717

1818
pub fn is_parent_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1919
let parent_id = tcx.local_parent(def_id);
20-
tcx.def_kind(parent_id) == DefKind::Impl
21-
&& tcx.impl_constness(parent_id) == hir::Constness::Const
20+
tcx.def_kind(parent_id) == DefKind::Impl && tcx.constness(parent_id) == hir::Constness::Const
2221
}
2322

24-
/// Checks whether the function has a `const` modifier or, in case it is an intrinsic, whether
25-
/// said intrinsic has a `rustc_const_{un,}stable` attribute.
26-
fn impl_constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
23+
/// Checks whether an item is considered to be `const`. If it is a constructor, it is const. If
24+
/// it is a trait impl/function, return if it has a `const` modifier. If it is an intrinsic,
25+
/// report whether said intrinsic has a `rustc_const_{un,}stable` attribute. Otherwise, return
26+
/// `Constness::NotConst`.
27+
fn constness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Constness {
2728
let def_id = def_id.expect_local();
2829
let node = tcx.hir().get_by_def_id(def_id);
2930

@@ -77,5 +78,5 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
7778
}
7879

7980
pub fn provide(providers: &mut Providers) {
80-
*providers = Providers { impl_constness, is_promotable_const_fn, ..*providers };
81+
*providers = Providers { constness, is_promotable_const_fn, ..*providers };
8182
}

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
753753
callee = did;
754754
}
755755

756-
if let hir::Constness::NotConst = tcx.impl_constness(data.impl_def_id) {
756+
if let hir::Constness::NotConst = tcx.constness(data.impl_def_id) {
757757
self.check_op(ops::FnCallNonConst {
758758
caller,
759759
callee,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
214214
impl_parent => { table }
215215
impl_polarity => { table_direct }
216216
impl_defaultness => { table_direct }
217-
impl_constness => { table_direct }
217+
constness => { table_direct }
218218
coerce_unsized_info => { table }
219219
mir_const_qualif => { table }
220220
rendered_const => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10701070
};
10711071

10721072
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1073-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1073+
self.tables.constness.set(def_id.index, hir::Constness::Const);
10741074
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
10751075
assert!(f.did.is_local());
10761076
f.did.index
@@ -1099,7 +1099,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10991099
};
11001100

11011101
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1102-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1102+
self.tables.constness.set(def_id.index, hir::Constness::Const);
11031103
self.encode_item_type(def_id);
11041104
if variant.ctor_kind == CtorKind::Fn {
11051105
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@@ -1182,7 +1182,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11821182
};
11831183

11841184
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1185-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1185+
self.tables.constness.set(def_id.index, hir::Constness::Const);
11861186
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data)));
11871187
self.encode_item_type(def_id);
11881188
if variant.ctor_kind == CtorKind::Fn {
@@ -1233,7 +1233,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12331233
}
12341234
};
12351235
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
1236-
self.tables.impl_constness.set(def_id.index, hir::Constness::NotConst);
1236+
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
12371237
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
12381238
container,
12391239
has_self: trait_item.fn_has_self_parameter,
@@ -1297,7 +1297,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12971297
} else {
12981298
hir::Constness::NotConst
12991299
};
1300-
self.tables.impl_constness.set(def_id.index, constness);
1300+
self.tables.constness.set(def_id.index, constness);
13011301
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
13021302
container,
13031303
has_self: impl_item.fn_has_self_parameter,
@@ -1420,7 +1420,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14201420
hir::ItemKind::Fn(ref sig, .., body) => {
14211421
self.tables.asyncness.set(def_id.index, sig.header.asyncness);
14221422
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
1423-
self.tables.impl_constness.set(def_id.index, sig.header.constness);
1423+
self.tables.constness.set(def_id.index, sig.header.constness);
14241424
EntryKind::Fn
14251425
}
14261426
hir::ItemKind::Macro(ref macro_def, _) => {
@@ -1444,7 +1444,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14441444
hir::ItemKind::Struct(ref struct_def, _) => {
14451445
let adt_def = self.tcx.adt_def(def_id);
14461446
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1447-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1447+
self.tables.constness.set(def_id.index, hir::Constness::Const);
14481448

14491449
// Encode def_ids for each field and method
14501450
// for methods, write all the stuff get_trait_method
@@ -1475,7 +1475,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14751475
}
14761476
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
14771477
self.tables.impl_defaultness.set(def_id.index, *defaultness);
1478-
self.tables.impl_constness.set(def_id.index, *constness);
1478+
self.tables.constness.set(def_id.index, *constness);
14791479

14801480
let trait_ref = self.tcx.impl_trait_ref(def_id);
14811481
if let Some(trait_ref) = trait_ref {
@@ -1941,7 +1941,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19411941
} else {
19421942
hir::Constness::NotConst
19431943
};
1944-
self.tables.impl_constness.set(def_id.index, constness);
1944+
self.tables.constness.set(def_id.index, constness);
19451945
record!(self.tables.kind[def_id] <- EntryKind::ForeignFn);
19461946
}
19471947
hir::ForeignItemKind::Static(..) => {

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ define_tables! {
364364
thir_abstract_const: Table<DefIndex, LazyValue<&'static [thir::abstract_const::Node<'static>]>>,
365365
impl_parent: Table<DefIndex, RawDefId>,
366366
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
367-
impl_constness: Table<DefIndex, hir::Constness>,
367+
constness: Table<DefIndex, hir::Constness>,
368368
is_intrinsic: Table<DefIndex, ()>,
369369
impl_defaultness: Table<DefIndex, hir::Defaultness>,
370370
// FIXME(eddyb) perhaps compute this on the fly if cheap enough?

compiler/rustc_middle/src/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ rustc_queries! {
592592
/// not have the feature gate active).
593593
///
594594
/// **Do not call this function manually.** It is only meant to cache the base data for the
595-
/// `is_const_fn` function.
596-
query impl_constness(key: DefId) -> hir::Constness {
597-
desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
595+
/// `is_const_fn` function. Consider using `is_const_fn` or `is_const_fn_raw` instead.
596+
query constness(key: DefId) -> hir::Constness {
597+
desc { |tcx| "checking if item is const: `{}`", tcx.def_path_str(key) }
598598
cache_on_disk_if { key.is_local() }
599599
separate_provide_extern
600600
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2309,7 +2309,7 @@ impl<'tcx> TyCtxt<'tcx> {
23092309
#[inline]
23102310
pub fn is_const_fn_raw(self, def_id: DefId) -> bool {
23112311
matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..))
2312-
&& self.impl_constness(def_id) == hir::Constness::Const
2312+
&& self.constness(def_id) == hir::Constness::Const
23132313
}
23142314

23152315
#[inline]

compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl<'tcx> TyCtxt<'tcx> {
376376
let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| {
377377
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
378378
if validate(self, impl_did).is_ok() {
379-
return Some((*item_id, self.impl_constness(impl_did)));
379+
return Some((*item_id, self.constness(impl_did)));
380380
}
381381
}
382382
None

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
970970

971971
if let Some(impl_def_id) = relevant_impl {
972972
// Check that `impl Drop` is actually const, if there is a custom impl
973-
if self.tcx().impl_constness(impl_def_id) == hir::Constness::Const {
973+
if self.tcx().constness(impl_def_id) == hir::Constness::Const {
974974
candidates.vec.push(ConstDestructCandidate(Some(impl_def_id)));
975975
}
976976
} else {

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11191119
if obligation.is_const() {
11201120
match candidate {
11211121
// const impl
1122-
ImplCandidate(def_id)
1123-
if tcx.impl_constness(def_id) == hir::Constness::Const => {}
1122+
ImplCandidate(def_id) if tcx.constness(def_id) == hir::Constness::Const => {}
11241123
// const param
11251124
ParamCandidate(trait_pred) if trait_pred.is_const_if_const() => {}
11261125
// auto trait impl

0 commit comments

Comments
 (0)