Skip to content

Commit f14d374

Browse files
authored
Rollup merge of #65066 - wesleywiser:fix_const_prop_ice_on_polymorphic_promoted_mir, r=oli-obk
[const-prop] Fix ICE when trying to eval polymorphic promoted MIR Fixes #64908 r? @oli-obk cc @nikomatsakis @pnkfelix
2 parents df471c1 + e9009c8 commit f14d374

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

src/librustc_mir/interpret/place.rs

+7
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,13 @@ where
594594
StaticKind::Promoted(promoted, promoted_substs) => {
595595
let substs = self.subst_from_frame_and_normalize_erasing_regions(promoted_substs);
596596
let instance = ty::Instance::new(place_static.def_id, substs);
597+
598+
// Even after getting `substs` from the frame, this instance may still be
599+
// polymorphic because `ConstProp` will try to promote polymorphic MIR.
600+
if instance.needs_subst() {
601+
throw_inval!(TooGeneric);
602+
}
603+
597604
self.const_eval_raw(GlobalId {
598605
instance,
599606
promoted: Some(promoted),

src/test/ui/consts/const-eval/issue-50814.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ struct Sum<A,B>(A,B);
1111

1212
impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A,B> {
1313
const MAX: u8 = A::MAX + B::MAX; //~ ERROR any use of this value will cause an error
14-
//~| ERROR any use of this value will cause an error
1514
}
1615

1716
fn foo<T>(_: T) -> &'static u8 {

src/test/ui/consts/const-eval/issue-50814.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,13 @@ LL | const MAX: u8 = A::MAX + B::MAX;
99
= note: `#[deny(const_err)]` on by default
1010

1111
error[E0080]: evaluation of constant expression failed
12-
--> $DIR/issue-50814.rs:18:5
12+
--> $DIR/issue-50814.rs:17:5
1313
|
1414
LL | &Sum::<U8,U8>::MAX
1515
| ^-----------------
1616
| |
1717
| referenced constant has errors
1818

19-
error: any use of this value will cause an error
20-
--> $DIR/issue-50814.rs:13:21
21-
|
22-
LL | const MAX: u8 = A::MAX + B::MAX;
23-
| ----------------^^^^^^^^^^^^^^^-
24-
| |
25-
| attempt to add with overflow
26-
27-
error: aborting due to 3 previous errors
19+
error: aborting due to 2 previous errors
2820

2921
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
3+
// This test verifies that the `ConstProp` pass doesn't cause an ICE when evaluating polymorphic
4+
// promoted MIR.
5+
6+
pub trait ArrowPrimitiveType {
7+
type Native;
8+
}
9+
10+
pub fn new<T: ArrowPrimitiveType>() {
11+
assert_eq!(0, std::mem::size_of::<T::Native>());
12+
}
13+
14+
impl ArrowPrimitiveType for () {
15+
type Native = ();
16+
}
17+
18+
fn main() {
19+
new::<()>();
20+
}

0 commit comments

Comments
 (0)