Skip to content

Commit a9f6784

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 dfb1f5e commit a9f6784

13 files changed

+5681
-10
lines changed

compiler/rustc_mir_transform/src/const_prop_lint.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ impl<'tcx> MirLint<'tcx> for ConstPropLint {
4242
return;
4343
}
4444

45-
// will be evaluated by miri and produce its errors there
46-
if body.source.promoted.is_some() {
47-
return;
48-
}
49-
5045
let def_id = body.source.def_id().expect_local();
5146
let def_kind = tcx.def_kind(def_id);
5247
let is_fn_like = def_kind.is_fn_like();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ 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]`
24-
--> $DIR/defaults-cyclic-fail.rs:16:16
23+
note: cycle used when simplifying constant for the type system `Tr::A`
24+
--> $DIR/defaults-cyclic-fail.rs:5:5
2525
|
26-
LL | assert_eq!(<() as Tr>::A, 0);
27-
| ^^^^^^^^^^^^^
26+
LL | const A: u8 = Self::B;
27+
| ^^^^^^^^^^^
2828
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
2929

3030
error: aborting due to 1 previous error

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

Lines changed: 8 additions & 0 deletions
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-eval/issue-44578.stderr

Lines changed: 8 additions & 0 deletions
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.stderr

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,28 @@ note: erroneous constant encountered
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:20: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>`
1430
--> $DIR/issue-50814.rs:25: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)