Skip to content

Commit 5888266

Browse files
committed
Add Constness::Comptime
1 parent 683dd08 commit 5888266

File tree

7 files changed

+19
-8
lines changed

7 files changed

+19
-8
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,7 @@ impl fmt::Display for Safety {
42264226
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
42274227
#[derive(Default)]
42284228
pub enum Constness {
4229+
Comptime,
42294230
Const,
42304231
#[default]
42314232
NotConst,
@@ -4234,6 +4235,7 @@ pub enum Constness {
42344235
impl fmt::Display for Constness {
42354236
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42364237
f.write_str(match *self {
4238+
Self::Comptime => "comptime",
42374239
Self::Const => "const",
42384240
Self::NotConst => "non-const",
42394241
})

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,6 +2571,7 @@ impl<'a> State<'a> {
25712571
match s {
25722572
hir::Constness::NotConst => {}
25732573
hir::Constness::Const => self.word_nbsp("const"),
2574+
hir::Constness::Comptime => { /* printed as an attribute */ }
25742575
}
25752576
}
25762577

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,10 +1524,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15241524
}
15251525
if should_encode_constness(def_kind) {
15261526
let constness = self.tcx.constness(def_id);
1527-
match constness {
1528-
hir::Constness::Const => self.tables.constness.set(def_id.index, constness),
1529-
hir::Constness::NotConst => {}
1530-
}
1527+
self.tables.constness.set(def_id.index, constness)
15311528
}
15321529
if let DefKind::Fn | DefKind::AssocFn = def_kind {
15331530
let asyncness = tcx.asyncness(def_id);

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ impl IsDefault for ty::Asyncness {
3737
impl IsDefault for hir::Constness {
3838
fn is_default(&self) -> bool {
3939
match self {
40-
rustc_hir::Constness::Const => false,
41-
rustc_hir::Constness::NotConst => true,
40+
hir::Constness::Const | hir::Constness::Comptime => false,
41+
hir::Constness::NotConst => true,
4242
}
4343
}
4444
}
@@ -200,6 +200,7 @@ fixed_size_enum! {
200200
hir::Constness {
201201
( NotConst )
202202
( Const )
203+
( Comptime )
203204
}
204205
}
205206

@@ -343,6 +344,7 @@ impl FixedSizeEncoding for hir::Constness {
343344
match b[0] {
344345
0 => hir::Constness::NotConst,
345346
1 => hir::Constness::Const,
347+
2 => hir::Constness::Comptime,
346348
_ => unreachable!(),
347349
}
348350
}
@@ -353,6 +355,7 @@ impl FixedSizeEncoding for hir::Constness {
353355
b[0] = match self {
354356
hir::Constness::NotConst => 0,
355357
hir::Constness::Const => 1,
358+
hir::Constness::Comptime => 2,
356359
}
357360
}
358361
}

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
247247

248248
fn destructor(self, tcx: TyCtxt<'tcx>) -> Option<AdtDestructorKind> {
249249
Some(match tcx.constness(self.destructor(tcx)?.did) {
250+
hir::Constness::Comptime => todo!("FIXME(comptime)"),
250251
hir::Constness::Const => AdtDestructorKind::Const,
251252
hir::Constness::NotConst => AdtDestructorKind::NotConst,
252253
})

compiler/rustc_trait_selection/src/traits/effects.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
435435
.map(|field| ty::TraitRef::new(tcx, destruct_def_id, [field.ty(tcx, args)]))
436436
.collect();
437437
match adt_def.destructor(tcx).map(|dtor| tcx.constness(dtor.did)) {
438+
Some(hir::Constness::Comptime) => todo!("FIXME(comptime)"),
438439
// `Drop` impl exists, but it's not const. Type cannot be `[const] Destruct`.
439440
Some(hir::Constness::NotConst) => return Err(EvaluationFailure::NoSolution),
440441
// `Drop` impl exists, and it's const. Require `Ty: [const] Drop` to hold.
@@ -530,6 +531,8 @@ fn evaluate_host_effect_for_fn_goal<'tcx>(
530531
};
531532

532533
match tcx.constness(def) {
534+
// FIXME(comptime)
535+
hir::Constness::Comptime => Err(EvaluationFailure::NoSolution),
533536
hir::Constness::Const => Ok(tcx
534537
.const_conditions(def)
535538
.instantiate(tcx, args)

src/librustdoc/html/format.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,14 +1471,18 @@ pub(crate) fn print_constness_with_space(
14711471
const_stab: Option<ConstStability>,
14721472
) -> &'static str {
14731473
match c {
1474-
hir::Constness::Const => match (overall_stab, const_stab) {
1474+
hir::Constness::Comptime | hir::Constness::Const => match (overall_stab, const_stab) {
14751475
// const stable...
14761476
(_, Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }))
14771477
// ...or when feature(staged_api) is not set...
14781478
| (_, None)
14791479
// ...or when const unstable, but overall unstable too
14801480
| (None, Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => {
1481-
"const "
1481+
match c {
1482+
hir::Constness::Comptime => "",
1483+
hir::Constness::Const => "const ",
1484+
_ => unreachable!(),
1485+
}
14821486
}
14831487
// const unstable (and overall stable)
14841488
(Some(_), Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => "",

0 commit comments

Comments
 (0)