-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Note numeric literals that can never fit in an expected type #73334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
afbbd38
2b936bb
f0d3689
d7277df
7a89a33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#[allow(unused_must_use)] | ||
fn main() { | ||
let x_usize: usize = 1; | ||
let x_u128: u128 = 2; | ||
let x_u64: u64 = 3; | ||
let x_u32: u32 = 4; | ||
let x_u16: u16 = 5; | ||
let x_u8: u8 = 6; | ||
|
||
x_usize > -1_isize; | ||
//~^ ERROR mismatched types | ||
x_u128 > -1_isize; | ||
//~^ ERROR mismatched types | ||
x_u64 > -1_isize; | ||
//~^ ERROR mismatched types | ||
x_u32 > -1_isize; | ||
//~^ ERROR mismatched types | ||
x_u16 > -1_isize; | ||
//~^ ERROR mismatched types | ||
x_u8 > -1_isize; | ||
//~^ ERROR mismatched types | ||
Comment on lines
+10
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this exhaustive by including the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, let's add a check for |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/numeric-cast-no-fix.rs:10:15 | ||
| | ||
LL | x_usize > -1_isize; | ||
| ^^^^^^^^ expected `usize`, found `isize` | ||
| | ||
note: `-1_isize` can never fit into `usize` | ||
--> $DIR/numeric-cast-no-fix.rs:10:15 | ||
| | ||
LL | x_usize > -1_isize; | ||
| ^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/numeric-cast-no-fix.rs:12:14 | ||
| | ||
LL | x_u128 > -1_isize; | ||
| ^^^^^^^^ expected `u128`, found `isize` | ||
| | ||
note: `-1_isize` can never fit into `u128` | ||
--> $DIR/numeric-cast-no-fix.rs:12:14 | ||
| | ||
LL | x_u128 > -1_isize; | ||
| ^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/numeric-cast-no-fix.rs:14:13 | ||
| | ||
LL | x_u64 > -1_isize; | ||
| ^^^^^^^^ expected `u64`, found `isize` | ||
| | ||
note: `-1_isize` can never fit into `u64` | ||
--> $DIR/numeric-cast-no-fix.rs:14:13 | ||
| | ||
LL | x_u64 > -1_isize; | ||
| ^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/numeric-cast-no-fix.rs:16:13 | ||
| | ||
LL | x_u32 > -1_isize; | ||
| ^^^^^^^^ expected `u32`, found `isize` | ||
| | ||
note: `-1_isize` can never fit into `u32` | ||
--> $DIR/numeric-cast-no-fix.rs:16:13 | ||
| | ||
LL | x_u32 > -1_isize; | ||
| ^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/numeric-cast-no-fix.rs:18:13 | ||
| | ||
LL | x_u16 > -1_isize; | ||
| ^^^^^^^^ expected `u16`, found `isize` | ||
| | ||
note: `-1_isize` can never fit into `u16` | ||
--> $DIR/numeric-cast-no-fix.rs:18:13 | ||
| | ||
LL | x_u16 > -1_isize; | ||
| ^^^^^^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/numeric-cast-no-fix.rs:20:12 | ||
| | ||
LL | x_u8 > -1_isize; | ||
| ^^^^^^^^ expected `u8`, found `isize` | ||
| | ||
help: you can convert `x_u8` from `u8` to `isize`, matching the type of `-1_isize` | ||
| | ||
LL | isize::from(x_u8) > -1_isize; | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Uh oh!
There was an error while loading. Please reload this page.