Skip to content

Commit c8f3769

Browse files
committed
Add Constness::Comptime
1 parent c8f22ca commit c8f3769

File tree

12 files changed

+21
-3
lines changed

12 files changed

+21
-3
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,6 +3097,7 @@ impl CoroutineKind {
30973097
#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, Debug)]
30983098
#[derive(HashStable_Generic, Walkable)]
30993099
pub enum Const {
3100+
Comptime(Span),
31003101
Yes(Span),
31013102
No,
31023103
}

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16031603

16041604
pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
16051605
match c {
1606+
Const::Comptime(_) => hir::Constness::Comptime,
16061607
Const::Yes(_) => hir::Constness::Const,
16071608
Const::No => hir::Constness::NotConst,
16081609
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ impl<'a> AstValidator<'a> {
637637
None => (),
638638
}
639639
match constness {
640+
Const::Comptime(span) => report_err(span, "comptime"),
640641
Const::Yes(span) => report_err(span, "const"),
641642
Const::No => (),
642643
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,7 @@ impl<'a> State<'a> {
21092109
match s {
21102110
ast::Const::No => {}
21112111
ast::Const::Yes(_) => self.word_nbsp("const"),
2112+
ast::Const::Comptime(_) => self.word_nbsp("comptime"),
21122113
}
21132114
}
21142115

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4225,13 +4225,15 @@ impl fmt::Display for Safety {
42254225

42264226
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, HashStable_Generic)]
42274227
pub enum Constness {
4228+
Comptime,
42284229
Const,
42294230
NotConst,
42304231
}
42314232

42324233
impl fmt::Display for Constness {
42334234
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42344235
f.write_str(match *self {
4236+
Self::Comptime => "comptime",
42354237
Self::Const => "const",
42364238
Self::NotConst => "non-const",
42374239
})

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,7 @@ impl<'a> State<'a> {
25672567
match s {
25682568
hir::Constness::NotConst => {}
25692569
hir::Constness::Const => self.word_nbsp("const"),
2570+
hir::Constness::Comptime => self.word_nbsp("comptime"),
25702571
}
25712572
}
25722573

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ fixed_size_enum! {
180180
hir::Constness {
181181
( NotConst )
182182
( Const )
183+
( Comptime )
183184
}
184185
}
185186

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_parse/src/parser/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,7 @@ impl<'a> Parser<'a> {
27862786
// that the keyword is already present and the second instance should be removed.
27872787
let wrong_kw = if self.check_keyword(exp!(Const)) {
27882788
match constness {
2789-
Const::Yes(sp) => Some(WrongKw::Duplicated(sp)),
2789+
Const::Comptime(sp) | Const::Yes(sp) => Some(WrongKw::Duplicated(sp)),
27902790
Const::No => {
27912791
recover_constness = Const::Yes(self.token.span);
27922792
match parsing_mode {

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)

0 commit comments

Comments
 (0)