提交 e9009c86 编写于 作者: W Wesley Wiser

[const-prop] Fix ICE when trying to eval polymorphic promoted MIR

上级 cfb6d847
......@@ -594,6 +594,13 @@ pub(super) fn eval_static_to_mplace(
StaticKind::Promoted(promoted, promoted_substs) => {
let substs = self.subst_from_frame_and_normalize_erasing_regions(promoted_substs);
let instance = ty::Instance::new(place_static.def_id, substs);
// Even after getting `substs` from the frame, this instance may still be
// polymorphic because `ConstProp` will try to promote polymorphic MIR.
if instance.needs_subst() {
throw_inval!(TooGeneric);
}
self.const_eval_raw(GlobalId {
instance,
promoted: Some(promoted),
......
......@@ -11,7 +11,6 @@ impl Unsigned for U8 {
impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A,B> {
const MAX: u8 = A::MAX + B::MAX; //~ ERROR any use of this value will cause an error
//~| ERROR any use of this value will cause an error
}
fn foo<T>(_: T) -> &'static u8 {
......
......@@ -9,21 +9,13 @@ LL | const MAX: u8 = A::MAX + B::MAX;
= note: `#[deny(const_err)]` on by default
error[E0080]: evaluation of constant expression failed
--> $DIR/issue-50814.rs:18:5
--> $DIR/issue-50814.rs:17:5
|
LL | &Sum::<U8,U8>::MAX
| ^-----------------
| |
| referenced constant has errors
error: any use of this value will cause an error
--> $DIR/issue-50814.rs:13:21
|
LL | const MAX: u8 = A::MAX + B::MAX;
| ----------------^^^^^^^^^^^^^^^-
| |
| attempt to add with overflow
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0080`.
// run-pass
// This test verifies that the `ConstProp` pass doesn't cause an ICE when evaluating polymorphic
// promoted MIR.
pub trait ArrowPrimitiveType {
type Native;
}
pub fn new<T: ArrowPrimitiveType>() {
assert_eq!(0, std::mem::size_of::<T::Native>());
}
impl ArrowPrimitiveType for () {
type Native = ();
}
fn main() {
new::<()>();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册