diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 4248627dccaf2..74a9646a0c0af 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -40,31 +40,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut self, constant: &mir::Constant<'tcx>, ) -> Result, ErrorHandled> { - match constant.literal.val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { - let substs = self.monomorphize(&substs); - self.cx - .tcx() - .const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None) - .map_err(|err| { - if promoted.is_none() { - self.cx - .tcx() - .sess - .span_err(constant.span, "erroneous constant encountered"); - } - err - }) - } + match self.monomorphize(&constant.literal).val { + ty::ConstKind::Unevaluated(def_id, substs, promoted) => self + .cx + .tcx() + .const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None) + .map_err(|err| { + if promoted.is_none() { + self.cx + .tcx() + .sess + .span_err(constant.span, "erroneous constant encountered"); + } + err + }), ty::ConstKind::Value(value) => Ok(value), - _ => { - let const_ = self.monomorphize(&constant.literal); - if let ty::ConstKind::Value(value) = const_.val { - Ok(value) - } else { - span_bug!(constant.span, "encountered bad ConstKind in codegen: {:?}", const_); - } - } + err => span_bug!( + constant.span, + "encountered bad ConstKind after monomorphizing: {:?}", + err + ), } } diff --git a/src/test/ui/const-generics/issues/issue-70125-1.rs b/src/test/ui/const-generics/issues/issue-70125-1.rs new file mode 100644 index 0000000000000..8b933c078ff26 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-70125-1.rs @@ -0,0 +1,19 @@ +// run-pass +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +const L: usize = 4; + +pub trait Print { + fn print(&self) -> usize { + N + } +} + +pub struct Printer; +impl Print for Printer {} + +fn main() { + let p = Printer; + assert_eq!(p.print(), 4); +} diff --git a/src/test/ui/const-generics/issues/issue-70125-1.stderr b/src/test/ui/const-generics/issues/issue-70125-1.stderr new file mode 100644 index 0000000000000..f28f58cf5ce4d --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-70125-1.stderr @@ -0,0 +1,8 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/issue-70125-1.rs:2:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + diff --git a/src/test/ui/const-generics/issues/issue-70125-2.rs b/src/test/ui/const-generics/issues/issue-70125-2.rs new file mode 100644 index 0000000000000..ea7a68c2f93d9 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-70125-2.rs @@ -0,0 +1,16 @@ +// run-pass + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +fn main() { + <()>::foo(); +} + +trait Foo { + fn foo() -> usize { + X + } +} + +impl Foo<{3}> for () {} diff --git a/src/test/ui/const-generics/issues/issue-70125-2.stderr b/src/test/ui/const-generics/issues/issue-70125-2.stderr new file mode 100644 index 0000000000000..664aa7ba45161 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-70125-2.stderr @@ -0,0 +1,8 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/issue-70125-2.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default +