Skip to content

Commit ddc74d3

Browse files
committed
always evaluate constant operands in const-prop
1 parent caee496 commit ddc74d3

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

-5
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
468468

469469
/// Returns the value, if any, of evaluating `c`.
470470
fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option<OpTy<'tcx>> {
471-
// FIXME we need to revisit this for #67176
472-
if c.needs_subst() {
473-
return None;
474-
}
475-
476471
self.ecx.mir_const_to_op(&c.literal, None).ok()
477472
}
478473

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

+3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ struct Sum<A,B>(A,B);
1414
impl<A: Unsigned, B: Unsigned> Unsigned for Sum<A,B> {
1515
const MAX: u8 = A::MAX + B::MAX;
1616
//~^ ERROR any use of this value will cause an error [const_err]
17+
//~| ERROR any use of this value will cause an error
1718
//~| WARN this was previously accepted by the compiler but is being phased out
19+
//~| WARNING this was previously accepted by the compiler
1820
}
1921

2022
fn foo<T>(_: T) -> &'static u8 {
2123
&Sum::<U8,U8>::MAX
2224
//~^ ERROR E0080
25+
//~| ERROR evaluation of `foo::<i32>` failed
2326
}
2427

2528
fn main() {

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

+20-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,36 @@ LL | const MAX: u8 = A::MAX + B::MAX;
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
1010

11+
error[E0080]: evaluation of `foo::<T>` failed
12+
--> $DIR/issue-50814.rs:23:6
13+
|
14+
LL | &Sum::<U8,U8>::MAX
15+
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
16+
17+
error: any use of this value will cause an error
18+
--> $DIR/issue-50814.rs:15:21
19+
|
20+
LL | const MAX: u8 = A::MAX + B::MAX;
21+
| ----------------^^^^^^^^^^^^^^^-
22+
| |
23+
| attempt to compute `u8::MAX + u8::MAX`, which would overflow
24+
|
25+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
26+
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
27+
1128
error[E0080]: evaluation of `foo::<i32>` failed
12-
--> $DIR/issue-50814.rs:21:6
29+
--> $DIR/issue-50814.rs:23:6
1330
|
1431
LL | &Sum::<U8,U8>::MAX
1532
| ^^^^^^^^^^^^^^^^^ referenced constant has errors
1633

1734
note: the above error was encountered while instantiating `fn foo::<i32>`
18-
--> $DIR/issue-50814.rs:26:5
35+
--> $DIR/issue-50814.rs:29:5
1936
|
2037
LL | foo(0);
2138
| ^^^^^^
2239

23-
error: aborting due to 2 previous errors
40+
error: aborting due to 4 previous errors
2441

2542
For more information about this error, try `rustc --explain E0080`.
2643
Future incompatibility report: Future breakage diagnostic:

0 commit comments

Comments
 (0)