From ce5ed5b6ccf2095bc2cb51534e59306ba7648a43 Mon Sep 17 00:00:00 2001 From: James Dietz Date: Tue, 27 Jun 2023 17:03:21 -0400 Subject: [PATCH 1/2] add check for ConstKind::Value(_) --- .../src/transform/check_consts/qualifs.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index a2d23425f3bc2..3496a06a4e072 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -348,11 +348,16 @@ where // way for type and mir constants. let uneval = match constant.literal { ConstantKind::Ty(ct) - if matches!(ct.kind(), ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) => + if matches!( + ct.kind(), + ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_) + ) => { None } - ConstantKind::Ty(c) => bug!("expected ConstKind::Param here, found {:?}", c), + ConstantKind::Ty(c) => { + bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c) + } ConstantKind::Unevaluated(uv, _) => Some(uv), ConstantKind::Val(..) => None, }; From 71362c733f3e3b0d83e78554b1cf4009aa319e84 Mon Sep 17 00:00:00 2001 From: James Dietz Date: Wed, 28 Jun 2023 07:50:34 -0400 Subject: [PATCH 2/2] remove FIXME and add test --- .../src/transform/check_consts/qualifs.rs | 2 -- tests/ui/match/issue-113012.rs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/ui/match/issue-113012.rs diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index 3496a06a4e072..36c76e532313d 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -344,8 +344,6 @@ where }; // Check the qualifs of the value of `const` items. - // FIXME(valtrees): check whether const qualifs should behave the same - // way for type and mir constants. let uneval = match constant.literal { ConstantKind::Ty(ct) if matches!( diff --git a/tests/ui/match/issue-113012.rs b/tests/ui/match/issue-113012.rs new file mode 100644 index 0000000000000..da7a8b65b97ba --- /dev/null +++ b/tests/ui/match/issue-113012.rs @@ -0,0 +1,12 @@ +// run-pass + +#![allow(dead_code)] +struct Foo(()); + +const FOO: Foo = Foo(match 0 { + 0.. => (), + _ => (), +}); + +fn main() { +}