Skip to content

Commit 9e27a7e

Browse files
committed
Enable ConstPropLint for promoteds
This fixes the issue wherein the lint didn't fire for promoteds in the case of SHL/SHR operators in non-optimized builds and all arithmetic operators in optimized builds
1 parent ee9c7c9 commit 9e27a7e

29 files changed

+6967
-738
lines changed

compiler/rustc_mir_transform/src/const_prop_lint.rs

-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ impl<'tcx> MirLint<'tcx> for ConstPropLint {
3232
return;
3333
}
3434

35-
// will be evaluated by miri and produce its errors there
36-
if body.source.promoted.is_some() {
37-
return;
38-
}
39-
4035
let def_id = body.source.def_id().expect_local();
4136
let def_kind = tcx.def_kind(def_id);
4237
let is_fn_like = def_kind.is_fn_like();

src/tools/miri/tests/pass/overflow_checks_off.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
//@compile-flags: -C overflow-checks=off
22

33
// Check that we correctly implement the intended behavior of these operators
4-
// when they are not being overflow-checked.
4+
// when they are not being overflow-checked at runtime.
55

66
// FIXME: if we call the functions in `std::ops`, we still get the panics.
77
// Miri does not implement the codegen-time hack that backs `#[rustc_inherit_overflow_checks]`.
88
// use std::ops::*;
99

10+
11+
// Disable _compile-time_ overflow linting
12+
// so that we can test runtime overflow checks
13+
#![allow(arithmetic_overflow)]
14+
1015
fn main() {
1116
assert_eq!(-{ -0x80i8 }, -0x80);
1217

tests/ui/associated-consts/defaults-cyclic-fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ note: ...which requires const-evaluating + checking `Tr::B`...
2020
LL | const B: u8 = Self::A;
2121
| ^^^^^^^
2222
= note: ...which again requires simplifying constant for the type system `Tr::A`, completing the cycle
23-
note: cycle used when const-evaluating + checking `main::promoted[1]`
23+
note: cycle used when optimizing promoted MIR for `main`
2424
--> $DIR/defaults-cyclic-fail.rs:16:16
2525
|
2626
LL | assert_eq!(<() as Tr>::A, 0);

tests/ui/associated-consts/defaults-not-assumed-fail.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ note: erroneous constant encountered
1010
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
1111
| ^^^^^^^^^^^^^
1212

13+
note: erroneous constant encountered
14+
--> $DIR/defaults-not-assumed-fail.rs:33:16
15+
|
16+
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
17+
| ^^^^^^^^^^^^^
18+
|
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
1321
note: erroneous constant encountered
1422
--> $DIR/defaults-not-assumed-fail.rs:33:5
1523
|

tests/ui/consts/const-err2.noopt.stderr

-48
This file was deleted.

tests/ui/consts/const-err2.opt.stderr

-48
This file was deleted.

tests/ui/consts/const-err2.opt_with_overflow_checks.stderr

-48
This file was deleted.

tests/ui/consts/const-err2.rs

-39
This file was deleted.

tests/ui/consts/const-eval/issue-44578.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ note: erroneous constant encountered
1010
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13+
note: erroneous constant encountered
14+
--> $DIR/issue-44578.rs:25:20
15+
|
16+
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
1321
note: erroneous constant encountered
1422
--> $DIR/issue-44578.rs:25:20
1523
|

tests/ui/consts/const-eval/issue-50814.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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 evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
17+
//~| ERROR evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
1718
}
1819

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

tests/ui/consts/const-eval/issue-50814.stderr

+19-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,33 @@ LL | const MAX: u8 = A::MAX + B::MAX;
55
| ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow
66

77
note: erroneous constant encountered
8-
--> $DIR/issue-50814.rs:20:6
8+
--> $DIR/issue-50814.rs:21:6
99
|
1010
LL | &Sum::<U8, U8>::MAX
1111
| ^^^^^^^^^^^^^^^^^^
1212

13+
error[E0080]: evaluation of `<Sum<U8, U8> as Unsigned>::MAX` failed
14+
--> $DIR/issue-50814.rs:15:21
15+
|
16+
LL | const MAX: u8 = A::MAX + B::MAX;
17+
| ^^^^^^^^^^^^^^^ attempt to compute `u8::MAX + u8::MAX`, which would overflow
18+
|
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
21+
note: erroneous constant encountered
22+
--> $DIR/issue-50814.rs:21:6
23+
|
24+
LL | &Sum::<U8, U8>::MAX
25+
| ^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
28+
1329
note: the above error was encountered while instantiating `fn foo::<i32>`
14-
--> $DIR/issue-50814.rs:25:5
30+
--> $DIR/issue-50814.rs:26:5
1531
|
1632
LL | foo(0);
1733
| ^^^^^^
1834

19-
error: aborting due to 1 previous error
35+
error: aborting due to 2 previous errors
2036

2137
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)