lowering casts in constants now creates multiple uses
This can trigger more errors than before. Not sure what is the best fix here.
This commit is contained in:
parent
26fdac6224
commit
d5d5e8c5f5
3 changed files with 21 additions and 6 deletions
|
@ -14,9 +14,10 @@ const X: u32 = 5;
|
||||||
const Y: u32 = 6;
|
const Y: u32 = 6;
|
||||||
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||||
//~^ WARN this constant cannot be used
|
//~^ WARN this constant cannot be used
|
||||||
|
//~| ERROR
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{}", FOO);
|
println!("{}", FOO);
|
||||||
//~^ ERROR erroneous constant used
|
//~^ ERROR
|
||||||
//~| E0080
|
//~| ERROR
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ LL | #![warn(const_err)]
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: referenced constant has errors
|
error[E0080]: referenced constant has errors
|
||||||
--> $DIR/conditional_array_execution.rs:19:20
|
--> $DIR/conditional_array_execution.rs:20:20
|
||||||
|
|
|
|
||||||
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||||
| ----- attempt to subtract with overflow
|
| ----- attempt to subtract with overflow
|
||||||
|
@ -21,12 +21,20 @@ LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||||
LL | println!("{}", FOO);
|
LL | println!("{}", FOO);
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
||||||
error[E0080]: erroneous constant used
|
error[E0080]: could not evaluate constant
|
||||||
--> $DIR/conditional_array_execution.rs:19:20
|
--> $DIR/conditional_array_execution.rs:20:20
|
||||||
|
|
|
|
||||||
LL | println!("{}", FOO);
|
LL | println!("{}", FOO);
|
||||||
| ^^^ referenced constant has errors
|
| ^^^ referenced constant has errors
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error[E0080]: constant evaluation error
|
||||||
|
--> $DIR/conditional_array_execution.rs:15:1
|
||||||
|
|
|
||||||
|
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
|
||||||
|
| ^^^^^^^^^^^^^^^^^^-----^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
| |
|
||||||
|
| attempt to subtract with overflow
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0080`.
|
For more information about this error, try `rustc --explain E0080`.
|
||||||
|
|
|
@ -34,6 +34,12 @@ warning: attempt to divide by zero
|
||||||
LL | println!("{}", 1/(false as u32));
|
LL | println!("{}", 1/(false as u32));
|
||||||
| ^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
warning: this expression will panic at runtime
|
||||||
|
--> $DIR/promoted_errors.rs:24:20
|
||||||
|
|
|
||||||
|
LL | println!("{}", 1/(false as u32));
|
||||||
|
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
|
||||||
|
|
||||||
warning: attempt to divide by zero
|
warning: attempt to divide by zero
|
||||||
--> $DIR/promoted_errors.rs:26:14
|
--> $DIR/promoted_errors.rs:26:14
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue