Skip to content

Commit c559468

Browse files
committed
Rename Constness variants to match BoundConstness
1 parent dce3d32 commit c559468

File tree

24 files changed

+76
-73
lines changed

24 files changed

+76
-73
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
460460
fn generate_header_error(&self) -> hir::FnHeader {
461461
hir::FnHeader {
462462
safety: hir::Safety::Safe.into(),
463-
constness: hir::Constness::NotConst,
463+
constness: hir::Constness::Never,
464464
asyncness: hir::IsAsync::NotAsync,
465465
abi: ExternAbi::Rust,
466466
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
766766
fn_decl_span: self.lower_span(fn_decl_span),
767767
fn_arg_span: None,
768768
kind: hir::ClosureKind::Coroutine(coroutine_kind),
769-
constness: hir::Constness::NotConst,
769+
constness: hir::Constness::Never,
770770
}))
771771
}
772772

@@ -1193,7 +1193,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11931193
// knows that a `FnDecl` output type like `-> &str` actually means
11941194
// "coroutine that returns &str", rather than directly returning a `&str`.
11951195
kind: hir::ClosureKind::CoroutineClosure(coroutine_desugaring),
1196-
constness: hir::Constness::NotConst,
1196+
constness: hir::Constness::Never,
11971197
});
11981198
hir::ExprKind::Closure(c)
11991199
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,17 +1540,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
15401540

15411541
let mut constness = self.lower_constness(h.constness);
15421542
if let Some(&attr_span) = find_attr!(attrs, AttributeKind::Comptime(span) => span) {
1543-
match std::mem::replace(&mut constness, rustc_hir::Constness::Comptime) {
1544-
rustc_hir::Constness::Comptime => {
1543+
match std::mem::replace(&mut constness, rustc_hir::Constness::Always) {
1544+
rustc_hir::Constness::Always => {
15451545
unreachable!("lower_constness cannot produce comptime")
15461546
}
15471547
// A function can't be `const` and `comptime` at the same time
1548-
rustc_hir::Constness::Const => {
1548+
rustc_hir::Constness::Maybe => {
15491549
let Const::Yes(span) = h.constness else { unreachable!() };
15501550
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
15511551
}
15521552
// Good
1553-
rustc_hir::Constness::NotConst => {}
1553+
rustc_hir::Constness::Never => {}
15541554
}
15551555
}
15561556

@@ -1616,8 +1616,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
16161616

16171617
pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
16181618
match c {
1619-
Const::Yes(_) => hir::Constness::Const,
1620-
Const::No => hir::Constness::NotConst,
1619+
Const::Yes(_) => hir::Constness::Maybe,
1620+
Const::No => hir::Constness::Never,
16211621
}
16221622
}
16231623

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ fn build_error_for_const_call<'tcx>(
402402
err.help("const traits are not yet supported on stable Rust");
403403
}
404404
}
405-
} else if ccx.tcx.constness(callee) != hir::Constness::Const {
405+
} else if ccx.tcx.constness(callee) != hir::Constness::Maybe {
406406
let name = ccx.tcx.item_name(callee);
407407
err.span_note(
408408
ccx.tcx.def_span(callee),

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Constness {
1111
let node = tcx.hir_node_by_def_id(def_id);
1212

1313
match node {
14-
Node::Ctor(VariantData::Tuple(..)) => Constness::Const,
14+
Node::Ctor(VariantData::Tuple(..)) => Constness::Maybe,
1515
Node::ForeignItem(item) if let ForeignItemKind::Fn(..) = item.kind => {
1616
// Foreign functions cannot be evaluated at compile-time.
17-
Constness::NotConst
17+
Constness::Never
1818
}
1919
Node::Expr(e) if let ExprKind::Closure(c) = e.kind => c.constness,
2020
// FIXME(fee1-dead): extract this one out and rename this query to `fn_constness` so we don't need `is_const_fn` anymore.
@@ -31,10 +31,10 @@ fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Constness {
3131
..
3232
}) => {
3333
match sig.header.constness {
34-
Constness::Const => Constness::Const,
35-
Constness::Comptime => Constness::Comptime,
34+
Constness::Maybe => Constness::Maybe,
35+
Constness::Always => Constness::Always,
3636
// inherent impl could be const
37-
Constness::NotConst => tcx.constness(tcx.local_parent(def_id)),
37+
Constness::Never => tcx.constness(tcx.local_parent(def_id)),
3838
}
3939
}
4040
Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(..), .. }) => tcx.trait_def(tcx.local_parent(def_id)).constness,

compiler/rustc_hir/src/hir.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4289,18 +4289,21 @@ impl fmt::Display for Safety {
42894289
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
42904290
#[derive(Default)]
42914291
pub enum Constness {
4292+
/// The function can only be called at compile-time
4293+
Always,
4294+
/// The function can be called both at runtime or compile-time
42924295
#[default]
4293-
Const,
4294-
NotConst,
4295-
Comptime,
4296+
Maybe,
4297+
/// The function can only be called at runtime
4298+
Never,
42964299
}
42974300

42984301
impl fmt::Display for Constness {
42994302
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43004303
f.write_str(match *self {
4301-
Self::Comptime => "comptime",
4302-
Self::Const => "const",
4303-
Self::NotConst => "non-const",
4304+
Self::Always => "comptime",
4305+
Self::Maybe => "const",
4306+
Self::Never => "non-const",
43044307
})
43054308
}
43064309
}
@@ -4340,7 +4343,7 @@ impl FnHeader {
43404343
}
43414344

43424345
pub fn is_const(&self) -> bool {
4343-
!matches!(self.constness, Constness::NotConst)
4346+
!matches!(self.constness, Constness::Never)
43444347
}
43454348

43464349
pub fn is_unsafe(&self) -> bool {

compiler/rustc_hir/src/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> FnKind<'a> {
9898
}
9999

100100
pub fn constness(self) -> Constness {
101-
self.header().map_or(Constness::NotConst, |header| header.constness)
101+
self.header().map_or(Constness::Never, |header| header.constness)
102102
}
103103

104104
pub fn asyncness(self) -> IsAsync {

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ fn check_impl_constness(
13631363
constness: hir::Constness,
13641364
hir_trait_ref: &hir::TraitRef<'_>,
13651365
) {
1366-
if let hir::Constness::NotConst = constness {
1366+
if let hir::Constness::Never = constness {
13671367
return;
13681368
}
13691369

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<'a> State<'a> {
698698

699699
match of_trait {
700700
None => {
701-
if let hir::Constness::Const = constness {
701+
if let hir::Constness::Maybe = constness {
702702
self.word_nbsp("const");
703703
}
704704
impl_generics(self)
@@ -715,7 +715,7 @@ impl<'a> State<'a> {
715715

716716
impl_generics(self);
717717

718-
if let hir::Constness::Const = constness {
718+
if let hir::Constness::Maybe = constness {
719719
self.word_nbsp("const");
720720
}
721721

@@ -2524,7 +2524,7 @@ impl<'a> State<'a> {
25242524
hir::FnHeader {
25252525
safety: safety.into(),
25262526
abi,
2527-
constness: hir::Constness::NotConst,
2527+
constness: hir::Constness::Never,
25282528
asyncness: hir::IsAsync::NotAsync,
25292529
},
25302530
name,
@@ -2564,9 +2564,9 @@ impl<'a> State<'a> {
25642564

25652565
fn print_constness(&mut self, s: hir::Constness) {
25662566
match s {
2567-
hir::Constness::NotConst => {}
2568-
hir::Constness::Const => self.word_nbsp("const"),
2569-
hir::Constness::Comptime => { /* printed as an attribute */ }
2567+
hir::Constness::Never => {}
2568+
hir::Constness::Maybe => self.word_nbsp("const"),
2569+
hir::Constness::Always => { /* printed as an attribute */ }
25702570
}
25712571
}
25722572

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
906906
) {
907907
let const_context = self.tcx.hir_body_const_context(self.body_id);
908908

909-
if let hir::Constness::Comptime = self.tcx.constness(callee_did) {
909+
if let hir::Constness::Always = self.tcx.constness(callee_did) {
910910
match const_context {
911911
Some(hir::ConstContext::Const { .. } | hir::ConstContext::Static(_)) => {}
912912
Some(hir::ConstContext::ConstFn) | None => {

0 commit comments

Comments
 (0)