Skip to content

Commit 5e4ff26

Browse files
Lireeroli-obk
authored andcommitted
separate const prop lint from optimizations
1 parent c99b42c commit 5e4ff26

28 files changed

+1558
-238
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 23 additions & 177 deletions
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/const_prop_lint.rs

Lines changed: 1295 additions & 0 deletions
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub mod cleanup_post_borrowck;
4949
mod const_debuginfo;
5050
mod const_goto;
5151
mod const_prop;
52+
mod const_prop_lint;
5253
mod coverage;
5354
mod deaggregator;
5455
mod deduplicate_blocks;
@@ -430,6 +431,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
430431
// `Deaggregator` is conceptually part of MIR building, some backends rely on it happening
431432
// and it can help optimizations.
432433
&deaggregator::Deaggregator,
434+
&const_prop_lint::ConstProp,
433435
];
434436

435437
pm::run_passes(tcx, body, post_borrowck_cleanup);

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ trait Foo {
44
const BAR: u32;
55
}
66

7-
const IMPL_REF_BAR: u32 = GlobalImplRef::BAR; //~ ERROR E0391
7+
const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
88

99
struct GlobalImplRef;
1010

1111
impl GlobalImplRef {
12-
const BAR: u32 = IMPL_REF_BAR;
12+
const BAR: u32 = IMPL_REF_BAR; //~ ERROR E0391
1313
}
1414

1515
fn main() {}

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
error[E0391]: cycle detected when simplifying constant for the type system `IMPL_REF_BAR`
1+
error[E0391]: cycle detected when elaborating drops for `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`
2+
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5
3+
|
4+
LL | const BAR: u32 = IMPL_REF_BAR;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: ...which requires normalizing `IMPL_REF_BAR`...
8+
note: ...which requires simplifying constant for the type system `IMPL_REF_BAR`...
29
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
310
|
411
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
512
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
713
note: ...which requires simplifying constant for the type system `IMPL_REF_BAR`...
814
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
915
|
@@ -35,8 +41,7 @@ note: ...which requires caching mir of `<impl at $DIR/issue-24949-assoc-const-st
3541
|
3642
LL | const BAR: u32 = IMPL_REF_BAR;
3743
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38-
= note: ...which requires normalizing `IMPL_REF_BAR`...
39-
= note: ...which again requires simplifying constant for the type system `IMPL_REF_BAR`, completing the cycle
44+
= note: ...which again requires elaborating drops for `<impl at $DIR/issue-24949-assoc-const-static-recursion-impl.rs:11:1: 13:2>::BAR`, completing the cycle
4045
= note: cycle used when running analysis passes on this crate
4146

4247
error: aborting due to previous error

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ trait Foo {
55
}
66

77
trait FooDefault {
8-
const BAR: u32 = DEFAULT_REF_BAR;
8+
const BAR: u32 = DEFAULT_REF_BAR; //~ ERROR E0391
99
}
1010

11-
const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR; //~ ERROR E0391
11+
const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
1212

1313
struct GlobalDefaultRef;
1414

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
error[E0391]: cycle detected when simplifying constant for the type system `DEFAULT_REF_BAR`
1+
error[E0391]: cycle detected when elaborating drops for `FooDefault::BAR`
2+
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5
3+
|
4+
LL | const BAR: u32 = DEFAULT_REF_BAR;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: ...which requires normalizing `DEFAULT_REF_BAR`...
8+
note: ...which requires simplifying constant for the type system `DEFAULT_REF_BAR`...
29
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
310
|
411
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
512
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
713
note: ...which requires simplifying constant for the type system `DEFAULT_REF_BAR`...
814
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
915
|
@@ -35,8 +41,7 @@ note: ...which requires caching mir of `FooDefault::BAR` for CTFE...
3541
|
3642
LL | const BAR: u32 = DEFAULT_REF_BAR;
3743
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38-
= note: ...which requires normalizing `DEFAULT_REF_BAR`...
39-
= note: ...which again requires simplifying constant for the type system `DEFAULT_REF_BAR`, completing the cycle
44+
= note: ...which again requires elaborating drops for `FooDefault::BAR`, completing the cycle
4045
= note: cycle used when running analysis passes on this crate
4146

4247
error: aborting due to previous error

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ trait Foo {
44
const BAR: u32;
55
}
66

7-
const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR; //~ ERROR E0391
7+
const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
88

99
struct GlobalTraitRef;
1010

1111
impl Foo for GlobalTraitRef {
12-
const BAR: u32 = TRAIT_REF_BAR;
12+
const BAR: u32 = TRAIT_REF_BAR; //~ ERROR E0391
1313
}
1414

1515
fn main() {}

src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
error[E0391]: cycle detected when simplifying constant for the type system `TRAIT_REF_BAR`
1+
error[E0391]: cycle detected when elaborating drops for `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`
2+
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5
3+
|
4+
LL | const BAR: u32 = TRAIT_REF_BAR;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: ...which requires normalizing `TRAIT_REF_BAR`...
8+
note: ...which requires simplifying constant for the type system `TRAIT_REF_BAR`...
29
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
310
|
411
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
512
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
713
note: ...which requires simplifying constant for the type system `TRAIT_REF_BAR`...
814
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
915
|
@@ -35,8 +41,7 @@ note: ...which requires caching mir of `<impl at $DIR/issue-24949-assoc-const-st
3541
|
3642
LL | const BAR: u32 = TRAIT_REF_BAR;
3743
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38-
= note: ...which requires normalizing `TRAIT_REF_BAR`...
39-
= note: ...which again requires simplifying constant for the type system `TRAIT_REF_BAR`, completing the cycle
44+
= note: ...which again requires elaborating drops for `<impl at $DIR/issue-24949-assoc-const-static-recursion-trait.rs:11:1: 13:2>::BAR`, completing the cycle
4045
= note: cycle used when running analysis passes on this crate
4146

4247
error: aborting due to previous error
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
// build-fail
1+
// build-pass
22
// compile-flags: -Zmir-opt-level=3
3+
// Overflow can't be detected by const prop
4+
// could only be detected after optimizations
35

46
#![deny(warnings)]
57

68
fn main() {
79
let _ = add(u8::MAX, 1);
8-
//~^ NOTE in this expansion of inlined source
9-
//~| NOTE in this expansion of inlined source
1010
}
1111

1212
#[inline(always)]
1313
fn add(x: u8, y: u8) -> u8 {
1414
x + y
15-
//~^ ERROR this arithmetic operation will overflow
16-
//~| NOTE attempt to compute `u8::MAX + 1_u8`, which would overflow
17-
//~| NOTE `#[deny(arithmetic_overflow)]` on by default
1815
}

0 commit comments

Comments
 (0)