Skip to content

Commit d5d5e8c

Browse files
committed
lowering casts in constants now creates multiple uses
This can trigger more errors than before. Not sure what is the best fix here.
1 parent 26fdac6 commit d5d5e8c

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/test/ui/consts/const-eval/conditional_array_execution.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ const X: u32 = 5;
1414
const Y: u32 = 6;
1515
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
1616
//~^ WARN this constant cannot be used
17+
//~| ERROR
1718

1819
fn main() {
1920
println!("{}", FOO);
20-
//~^ ERROR erroneous constant used
21-
//~| E0080
21+
//~^ ERROR
22+
//~| ERROR
2223
}

src/test/ui/consts/const-eval/conditional_array_execution.stderr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@ LL | #![warn(const_err)]
1313
| ^^^^^^^^^
1414

1515
error[E0080]: referenced constant has errors
16-
--> $DIR/conditional_array_execution.rs:19:20
16+
--> $DIR/conditional_array_execution.rs:20:20
1717
|
1818
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
1919
| ----- attempt to subtract with overflow
2020
...
2121
LL | println!("{}", FOO);
2222
| ^^^
2323

24-
error[E0080]: erroneous constant used
25-
--> $DIR/conditional_array_execution.rs:19:20
24+
error[E0080]: could not evaluate constant
25+
--> $DIR/conditional_array_execution.rs:20:20
2626
|
2727
LL | println!("{}", FOO);
2828
| ^^^ referenced constant has errors
2929

30-
error: aborting due to 2 previous errors
30+
error[E0080]: constant evaluation error
31+
--> $DIR/conditional_array_execution.rs:15:1
32+
|
33+
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
34+
| ^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^
35+
| |
36+
| attempt to subtract with overflow
37+
38+
error: aborting due to 3 previous errors
3139

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

src/test/ui/consts/const-eval/promoted_errors.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ warning: attempt to divide by zero
3434
LL | println!("{}", 1/(false as u32));
3535
| ^^^^^^^^^^^^^^^^
3636

37+
warning: this expression will panic at runtime
38+
--> $DIR/promoted_errors.rs:24:20
39+
|
40+
LL | println!("{}", 1/(false as u32));
41+
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
42+
3743
warning: attempt to divide by zero
3844
--> $DIR/promoted_errors.rs:26:14
3945
|

0 commit comments

Comments
 (0)