Rollup merge of #70249 - lcnr:issue70125, r=eddyb
handle ConstKind::Unresolved after monomorphizing fixes #70125 r? @bjorn3
This commit is contained in:
commit
092c821ef2
|
@ -40,31 +40,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
&mut self,
|
||||
constant: &mir::Constant<'tcx>,
|
||||
) -> Result<ConstValue<'tcx>, 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
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<const N: usize> {
|
||||
fn print(&self) -> usize {
|
||||
N
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Printer;
|
||||
impl Print<L> for Printer {}
|
||||
|
||||
fn main() {
|
||||
let p = Printer;
|
||||
assert_eq!(p.print(), 4);
|
||||
}
|
|
@ -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
|
||||
|
|
@ -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<const X: usize> {
|
||||
fn foo() -> usize {
|
||||
X
|
||||
}
|
||||
}
|
||||
|
||||
impl Foo<{3}> for () {}
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue