Skip to content

Commit 6e8f541

Browse files
authored
Rollup merge of #98136 - fee1-dead-contrib:rename_impl_constness, r=oli-obk
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. r? `@oli-obk`
2 parents 3174a69 + 26ac456 commit 6e8f541

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

Diff for: 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
}

Diff for: 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,

Diff for: 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 }

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10631063
};
10641064

10651065
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1066-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1066+
self.tables.constness.set(def_id.index, hir::Constness::Const);
10671067
record_array!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
10681068
assert!(f.did.is_local());
10691069
f.did.index
@@ -1092,7 +1092,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10921092
};
10931093

10941094
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
1095-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1095+
self.tables.constness.set(def_id.index, hir::Constness::Const);
10961096
self.encode_item_type(def_id);
10971097
if variant.ctor_kind == CtorKind::Fn {
10981098
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@@ -1175,7 +1175,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11751175
};
11761176

11771177
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1178-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1178+
self.tables.constness.set(def_id.index, hir::Constness::Const);
11791179
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data)));
11801180
self.encode_item_type(def_id);
11811181
if variant.ctor_kind == CtorKind::Fn {
@@ -1226,7 +1226,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12261226
}
12271227
};
12281228
self.tables.asyncness.set(def_id.index, m_sig.header.asyncness);
1229-
self.tables.impl_constness.set(def_id.index, hir::Constness::NotConst);
1229+
self.tables.constness.set(def_id.index, hir::Constness::NotConst);
12301230
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
12311231
container,
12321232
has_self: trait_item.fn_has_self_parameter,
@@ -1290,7 +1290,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12901290
} else {
12911291
hir::Constness::NotConst
12921292
};
1293-
self.tables.impl_constness.set(def_id.index, constness);
1293+
self.tables.constness.set(def_id.index, constness);
12941294
record!(self.tables.kind[def_id] <- EntryKind::AssocFn(self.lazy(AssocFnData {
12951295
container,
12961296
has_self: impl_item.fn_has_self_parameter,
@@ -1413,7 +1413,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14131413
hir::ItemKind::Fn(ref sig, .., body) => {
14141414
self.tables.asyncness.set(def_id.index, sig.header.asyncness);
14151415
record_array!(self.tables.fn_arg_names[def_id] <- self.tcx.hir().body_param_names(body));
1416-
self.tables.impl_constness.set(def_id.index, sig.header.constness);
1416+
self.tables.constness.set(def_id.index, sig.header.constness);
14171417
EntryKind::Fn
14181418
}
14191419
hir::ItemKind::Macro(ref macro_def, _) => {
@@ -1437,7 +1437,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14371437
hir::ItemKind::Struct(ref struct_def, _) => {
14381438
let adt_def = self.tcx.adt_def(def_id);
14391439
record!(self.tables.repr_options[def_id] <- adt_def.repr());
1440-
self.tables.impl_constness.set(def_id.index, hir::Constness::Const);
1440+
self.tables.constness.set(def_id.index, hir::Constness::Const);
14411441

14421442
// Encode def_ids for each field and method
14431443
// for methods, write all the stuff get_trait_method
@@ -1468,7 +1468,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14681468
}
14691469
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
14701470
self.tables.impl_defaultness.set(def_id.index, *defaultness);
1471-
self.tables.impl_constness.set(def_id.index, *constness);
1471+
self.tables.constness.set(def_id.index, *constness);
14721472

14731473
let trait_ref = self.tcx.impl_trait_ref(def_id);
14741474
if let Some(trait_ref) = trait_ref {
@@ -1934,7 +1934,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19341934
} else {
19351935
hir::Constness::NotConst
19361936
};
1937-
self.tables.impl_constness.set(def_id.index, constness);
1937+
self.tables.constness.set(def_id.index, constness);
19381938
record!(self.tables.kind[def_id] <- EntryKind::ForeignFn);
19391939
}
19401940
hir::ForeignItemKind::Static(..) => {

Diff for: 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?

Diff for: compiler/rustc_middle/src/query/mod.rs

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

Diff for: compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ impl<'tcx> TyCtxt<'tcx> {
23412341
#[inline]
23422342
pub fn is_const_fn_raw(self, def_id: DefId) -> bool {
23432343
matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..))
2344-
&& self.impl_constness(def_id) == hir::Constness::Const
2344+
&& self.constness(def_id) == hir::Constness::Const
23452345
}
23462346

23472347
#[inline]

Diff for: 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

Diff for: 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 {

Diff for: 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)