Skip to content

Commit 0fc86d8

Browse files
Rollup merge of #151260 - reddevilmidzy:type_const, r=BoxyUwU
Handle unevaluated ConstKind in in_operand fix: #151248 r? BoxyUwU ~~I can't reproduce #151246 in my local(x86_64-pc-windows-msvc) even before this change. 🤔 create a draft and test it in different environments.~~
2 parents 4fb420a + a158e2e commit 0fc86d8

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,18 @@ where
343343

344344
// Check the qualifs of the value of `const` items.
345345
let uneval = match constant.const_ {
346-
Const::Ty(_, ct)
347-
if matches!(
348-
ct.kind(),
349-
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_)
350-
) =>
351-
{
352-
None
353-
}
354-
Const::Ty(_, c) => {
355-
bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c)
356-
}
346+
Const::Ty(_, ct) => match ct.kind() {
347+
ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
348+
// Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`).
349+
ty::ConstKind::Unevaluated(_) => None,
350+
// FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
351+
// strict, and if instead we should be doing some kind of value-based analysis.
352+
ty::ConstKind::Value(_) => None,
353+
_ => bug!(
354+
"expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}",
355+
ct
356+
),
357+
},
357358
Const::Unevaluated(uv, _) => Some(uv),
358359
Const::Val(..) => None,
359360
};
@@ -364,10 +365,8 @@ where
364365
// check performed after the promotion. Verify that with an assertion.
365366
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
366367

367-
// Don't peak inside trait associated constants, also `#[type_const] const` items
368-
// don't have bodies so there's nothing to look at
369-
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !cx.tcx.is_type_const(def)
370-
{
368+
// Don't peak inside trait associated constants.
369+
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
371370
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
372371

373372
if !Q::in_qualifs(&qualifs) {

tests/ui/const-generics/mgca/type_const-pub.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77

88
#[type_const]
99
pub const TYPE_CONST : usize = 1;
10-
fn main() {}
10+
fn main() {
11+
print!("{}", TYPE_CONST)
12+
}

0 commit comments

Comments
 (0)