Skip to content

Commit 509de00

Browse files
committed
Add Constness::Comptime
1 parent 5bc3450 commit 509de00

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4290,11 +4290,13 @@ pub enum Constness {
42904290
#[default]
42914291
Const,
42924292
NotConst,
4293+
Comptime,
42934294
}
42944295

42954296
impl fmt::Display for Constness {
42964297
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42974298
f.write_str(match *self {
4299+
Self::Comptime => "comptime",
42984300
Self::Const => "const",
42994301
Self::NotConst => "non-const",
43004302
})
@@ -4336,7 +4338,7 @@ impl FnHeader {
43364338
}
43374339

43384340
pub fn is_const(&self) -> bool {
4339-
matches!(self.constness, Constness::Const)
4341+
!matches!(self.constness, Constness::NotConst)
43404342
}
43414343

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

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,6 +2566,7 @@ impl<'a> State<'a> {
25662566
match s {
25672567
hir::Constness::NotConst => {}
25682568
hir::Constness::Const => self.word_nbsp("const"),
2569+
hir::Constness::Comptime => { /* printed as an attribute */ }
25692570
}
25702571
}
25712572

compiler/rustc_metadata/src/rmeta/table.rs

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

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
@@ -538,7 +538,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
538538
if matches!(target, Target::Impl { of_trait: true }) {
539539
match item.unwrap() {
540540
ItemLike::Item(it) => match it.expect_impl().constness {
541-
Constness::Const => {}
541+
Constness::Const | Constness::Comptime => {}
542542
Constness::NotConst => return,
543543
},
544544
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)