Skip to content

Commit 8849ac6

Browse files
committed
tcx.is_const_fn doesn't work the way it is described, remove it
Then we can rename the _raw functions to drop their suffix, and instead explicitly use is_stable_const_fn for the few cases where that is really what you want.
1 parent 36dda45 commit 8849ac6

File tree

21 files changed

+55
-64
lines changed

21 files changed

+55
-64
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
731731
}
732732

733733
// Trait functions are not `const fn` so we have to skip them here.
734-
if !tcx.is_const_fn_raw(callee) && !is_trait {
734+
if !tcx.is_const_fn(callee) && !is_trait {
735735
self.check_op(ops::FnCallNonConst {
736736
caller,
737737
callee,

compiler/rustc_const_eval/src/check_consts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn is_safe_to_expose_on_stable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> b
112112
}
113113

114114
// Const-stability is only relevant for `const fn`.
115-
assert!(tcx.is_const_fn_raw(def_id));
115+
assert!(tcx.is_const_fn(def_id));
116116

117117
match tcx.lookup_const_stability(def_id) {
118118
None => {

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
122122

123123
if let Ok(Some(ImplSource::UserDefined(data))) = implsrc {
124124
// FIXME(effects) revisit this
125-
if !tcx.is_const_trait_impl_raw(data.impl_def_id) {
125+
if !tcx.is_const_trait_impl(data.impl_def_id) {
126126
let span = tcx.def_span(data.impl_def_id);
127127
err.subdiagnostic(errors::NonConstImplNote { span });
128128
}
@@ -174,7 +174,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
174174
let note = match self_ty.kind() {
175175
FnDef(def_id, ..) => {
176176
let span = tcx.def_span(*def_id);
177-
if ccx.tcx.is_const_fn_raw(*def_id) {
177+
if ccx.tcx.is_const_fn(*def_id) {
178178
span_bug!(span, "calling const FnDef errored when it shouldn't");
179179
}
180180

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
431431
// sensitive check here. But we can at least rule out functions that are not const at
432432
// all. That said, we have to allow calling functions inside a trait marked with
433433
// #[const_trait]. These *are* const-checked!
434-
// FIXME: why does `is_const_fn_raw` not classify them as const?
435-
if (!ecx.tcx.is_const_fn_raw(def) && !ecx.tcx.is_const_default_method(def))
434+
// FIXME(effects): why does `is_const_fn` not classify them as const?
435+
if (!ecx.tcx.is_const_fn(def) && !ecx.tcx.is_const_default_method(def))
436436
|| ecx.tcx.has_attr(def, sym::rustc_do_not_const_check)
437437
{
438438
// We certainly do *not* want to actually call the fn

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai
15971597
impl_.of_trait.as_ref().map(|ast_trait_ref| {
15981598
let selfty = tcx.type_of(def_id).instantiate_identity();
15991599

1600-
check_impl_constness(tcx, tcx.is_const_trait_impl_raw(def_id.to_def_id()), ast_trait_ref);
1600+
check_impl_constness(tcx, tcx.is_const_trait_impl(def_id.to_def_id()), ast_trait_ref);
16011601

16021602
let trait_ref = icx.lowerer().lower_impl_trait_ref(ast_trait_ref, selfty);
16031603

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
537537
//
538538
// This check is here because there is currently no way to express a trait bound for `FnDef` types only.
539539
if let ty::FnDef(def_id, _args) = *arg_ty.kind() {
540-
if idx == 0 && !self.tcx.is_const_fn_raw(def_id) {
540+
if idx == 0 && !self.tcx.is_const_fn(def_id) {
541541
self.dcx().emit_err(errors::ConstSelectMustBeConst { span });
542542
}
543543
} else {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17511751
// to tell them that in the diagnostic. Does not affect typeck.
17521752
let is_constable = match element.kind {
17531753
hir::ExprKind::Call(func, _args) => match *self.node_ty(func.hir_id).kind() {
1754-
ty::FnDef(def_id, _) if tcx.is_const_fn(def_id) => traits::IsConstable::Fn,
1754+
ty::FnDef(def_id, _) if tcx.is_stable_const_fn(def_id) => traits::IsConstable::Fn,
17551755
_ => traits::IsConstable::No,
17561756
},
17571757
hir::ExprKind::Path(qpath) => {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ fn should_encode_mir(
10811081
&& (generics.requires_monomorphization(tcx)
10821082
|| tcx.cross_crate_inlinable(def_id)));
10831083
// The function has a `const` modifier or is in a `#[const_trait]`.
1084-
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
1084+
let is_const_fn = tcx.is_const_fn(def_id.to_def_id())
10851085
|| tcx.is_const_default_method(def_id.to_def_id());
10861086
(is_const_fn, opt)
10871087
}

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'hir> Map<'hir> {
329329
BodyOwnerKind::Static(mutability) => ConstContext::Static(mutability),
330330

331331
BodyOwnerKind::Fn if self.tcx.is_constructor(def_id) => return None,
332-
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn_raw(def_id) => {
332+
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.tcx.is_const_fn(def_id) => {
333333
ConstContext::ConstFn
334334
}
335335
BodyOwnerKind::Fn if self.tcx.is_const_default_method(def_id) => ConstContext::ConstFn,

compiler/rustc_middle/src/mir/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ where
1717
let mirs = def_ids
1818
.iter()
1919
.flat_map(|def_id| {
20-
if tcx.is_const_fn_raw(*def_id) {
20+
if tcx.is_const_fn(*def_id) {
2121
vec![tcx.optimized_mir(*def_id), tcx.mir_for_ctfe(*def_id)]
2222
} else {
2323
vec![tcx.instance_mir(ty::InstanceKind::Item(*def_id))]

0 commit comments

Comments
 (0)