Skip to content

Commit d843820

Browse files
committed
Add Constness::Comptime
1 parent a417515 commit d843820

File tree

8 files changed

+16
-4
lines changed

8 files changed

+16
-4
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,11 +4238,13 @@ pub enum Constness {
42384238
#[default]
42394239
Const,
42404240
NotConst,
4241+
Comptime,
42414242
}
42424243

42434244
impl fmt::Display for Constness {
42444245
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42454246
f.write_str(match *self {
4247+
Self::Comptime => "comptime",
42464248
Self::Const => "const",
42474249
Self::NotConst => "non-const",
42484250
})

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +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-
self.tables.constness.set(def_id.index, constness);
1527+
self.tables.constness.set(def_id.index, constness)
15281528
}
15291529
if let DefKind::Fn | DefKind::AssocFn = def_kind {
15301530
let asyncness = tcx.asyncness(def_id);

compiler/rustc_metadata/src/rmeta/table.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ defaulted_enum! {
234234
hir::Constness {
235235
( Const )
236236
( NotConst )
237+
( Comptime )
237238
}
238239
}
239240

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_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
535535
if matches!(target, Target::Impl { of_trait: true }) {
536536
match item.unwrap() {
537537
ItemLike::Item(it) => match it.expect_impl().constness {
538-
Constness::Const => {}
538+
Constness::Const | Constness::Comptime => {}
539539
Constness::NotConst => return,
540540
},
541541
ItemLike::ForeignItem => {}

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
@@ -1479,14 +1479,18 @@ pub(crate) fn print_constness_with_space(
14791479
const_stab: Option<ConstStability>,
14801480
) -> &'static str {
14811481
match c {
1482-
hir::Constness::Const => match (overall_stab, const_stab) {
1482+
hir::Constness::Comptime | hir::Constness::Const => match (overall_stab, const_stab) {
14831483
// const stable...
14841484
(_, Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }))
14851485
// ...or when feature(staged_api) is not set...
14861486
| (_, None)
14871487
// ...or when const unstable, but overall unstable too
14881488
| (None, Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => {
1489-
"const "
1489+
match c {
1490+
hir::Constness::Comptime => "",
1491+
hir::Constness::Const => "const ",
1492+
_ => unreachable!(),
1493+
}
14901494
}
14911495
// const unstable (and overall stable)
14921496
(Some(_), Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => "",

0 commit comments

Comments
 (0)