Const-propagate casts
This commit is contained in:
parent
1f4e21028d
commit
9329957d32
4 changed files with 61 additions and 15 deletions
|
|
@ -166,7 +166,12 @@ fn main()
|
|||
|
||||
assert!(foo as usize != bar as usize);
|
||||
|
||||
assert_eq!(foo as i16, foo as usize as i16);
|
||||
// Taking a few bits of a function's address is totally pointless and we detect that
|
||||
// Disabling the lint to ensure that the assertion can still be run
|
||||
#[allow(const_err)]
|
||||
{
|
||||
assert_eq!(foo as i16, foo as usize as i16);
|
||||
}
|
||||
|
||||
// fptr-ptr-cast
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,8 @@ fn main() {
|
|||
//~| WARN const_err
|
||||
println!("{}", 1/(false as u32));
|
||||
//~^ WARN const_err
|
||||
//~| WARN const_err
|
||||
let _x = 1/(false as u32);
|
||||
//~^ WARN const_err
|
||||
//~| WARN const_err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,27 @@ warning: this expression will panic at runtime
|
|||
LL | let _x = 1/(1-1);
|
||||
| ^^^^^^^ attempt to divide by zero
|
||||
|
||||
warning: attempt to divide by zero
|
||||
--> $DIR/promoted_errors.rs:25:20
|
||||
|
|
||||
LL | println!("{}", 1/(false as u32));
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: this expression will panic at runtime
|
||||
--> $DIR/promoted_errors.rs:25:20
|
||||
|
|
||||
LL | println!("{}", 1/(false as u32));
|
||||
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
|
||||
|
||||
warning: attempt to divide by zero
|
||||
--> $DIR/promoted_errors.rs:28:14
|
||||
|
|
||||
LL | let _x = 1/(false as u32);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: this expression will panic at runtime
|
||||
--> $DIR/promoted_errors.rs:28:14
|
||||
|
|
||||
LL | let _x = 1/(false as u32);
|
||||
| ^^^^^^^^^^^^^^^^ attempt to divide by zero
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue