-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest
into
instead of try_into
if possible with int types
If it is possible to convert an integer type into another using `into`, don't suggest `try_into`. This commit changes the suggested method to convert from one integer type to another for the following cases: - u{n} -> i{m} where n < m - u8 -> isize - i{n} -> isize where n <= 16 - u{n} -> usize where n <= 16
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fn main() { | ||
let a = 1u8; | ||
let _: i64 = a; | ||
//~^ ERROR mismatched types | ||
|
||
let b = 1i8; | ||
let _: isize = b; | ||
//~^ ERROR mismatched types | ||
|
||
let c = 1u8; | ||
let _: isize = c; | ||
//~^ ERROR mismatched types | ||
|
||
let d = 1u8; | ||
let _: usize = d; | ||
//~^ ERROR mismatched types | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/integer-into.rs:3:18 | ||
| | ||
LL | let _: i64 = a; | ||
| --- ^ | ||
| | | | ||
| | expected `i64`, found `u8` | ||
| | help: you can convert an `u8` to `i64`: `a.into()` | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/integer-into.rs:7:20 | ||
| | ||
LL | let _: isize = b; | ||
| ----- ^ | ||
| | | | ||
| | expected `isize`, found `i8` | ||
| | help: you can convert an `i8` to `isize`: `b.into()` | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/integer-into.rs:11:20 | ||
| | ||
LL | let _: isize = c; | ||
| ----- ^ | ||
| | | | ||
| | expected `isize`, found `u8` | ||
| | help: you can convert an `u8` to `isize`: `c.into()` | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/integer-into.rs:15:20 | ||
| | ||
LL | let _: usize = d; | ||
| ----- ^ | ||
| | | | ||
| | expected `usize`, found `u8` | ||
| | help: you can convert an `u8` to `usize`: `d.into()` | ||
| expected due to this | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |