mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
[const-prop] Fix ICE when trying to eval polymorphic promoted MIR
This commit is contained in:
parent
cfb6d84720
commit
e9009c86d2
@ -594,6 +594,13 @@ where
|
||||
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 @@ struct Sum<A,B>(A,B);
|
||||
|
||||
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`.
|
||||
|
20
src/test/ui/consts/const-eval/issue-64908.rs
Normal file
20
src/test/ui/consts/const-eval/issue-64908.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// 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::<()>();
|
||||
}
|
Loading…
Reference in New Issue
Block a user