Skip to content

Commit

Permalink
fixup! Note numeric literals that can never fit in an expected type
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Jun 17, 2020
1 parent f0d3689 commit d7277df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// suggest a fallible conversion, check if the value can never fit in the
// expected type.
let msg = format!("`{}` cannot fit into type `{}`", src, expected_ty);
err.span_note(expr.span, &msg);
err.note(&msg);
return;
} else if in_const_context {
// Do not recommend `into` or `try_into` in const contexts.
Expand Down
150 changes: 25 additions & 125 deletions src/test/ui/numeric/numeric-cast-no-fix.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,39 @@ error[E0308]: mismatched types
LL | x_usize > -1_isize;
| ^^^^^^^^ expected `usize`, found `isize`
|
note: `-1_isize` cannot fit into type `usize`
--> $DIR/numeric-cast-no-fix.rs:10:15
|
LL | x_usize > -1_isize;
| ^^^^^^^^
= note: `-1_isize` cannot fit into type `usize`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:12:14
|
LL | x_u128 > -1_isize;
| ^^^^^^^^ expected `u128`, found `isize`
|
note: `-1_isize` cannot fit into type `u128`
--> $DIR/numeric-cast-no-fix.rs:12:14
|
LL | x_u128 > -1_isize;
| ^^^^^^^^
= note: `-1_isize` cannot fit into type `u128`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:14:13
|
LL | x_u64 > -1_isize;
| ^^^^^^^^ expected `u64`, found `isize`
|
note: `-1_isize` cannot fit into type `u64`
--> $DIR/numeric-cast-no-fix.rs:14:13
|
LL | x_u64 > -1_isize;
| ^^^^^^^^
= note: `-1_isize` cannot fit into type `u64`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:16:13
|
LL | x_u32 > -1_isize;
| ^^^^^^^^ expected `u32`, found `isize`
|
note: `-1_isize` cannot fit into type `u32`
--> $DIR/numeric-cast-no-fix.rs:16:13
|
LL | x_u32 > -1_isize;
| ^^^^^^^^
= note: `-1_isize` cannot fit into type `u32`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:18:13
|
LL | x_u16 > -1_isize;
| ^^^^^^^^ expected `u16`, found `isize`
|
note: `-1_isize` cannot fit into type `u16`
--> $DIR/numeric-cast-no-fix.rs:18:13
|
LL | x_u16 > -1_isize;
| ^^^^^^^^
= note: `-1_isize` cannot fit into type `u16`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:20:12
Expand All @@ -75,23 +55,15 @@ error[E0308]: mismatched types
LL | x_usize > -1_i128;
| ^^^^^^^ expected `usize`, found `i128`
|
note: `-1_i128` cannot fit into type `usize`
--> $DIR/numeric-cast-no-fix.rs:23:15
|
LL | x_usize > -1_i128;
| ^^^^^^^
= note: `-1_i128` cannot fit into type `usize`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:25:14
|
LL | x_u128 > -1_i128;
| ^^^^^^^ expected `u128`, found `i128`
|
note: `-1_i128` cannot fit into type `u128`
--> $DIR/numeric-cast-no-fix.rs:25:14
|
LL | x_u128 > -1_i128;
| ^^^^^^^
= note: `-1_i128` cannot fit into type `u128`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:27:13
Expand Down Expand Up @@ -143,35 +115,23 @@ error[E0308]: mismatched types
LL | x_usize > -1_i64;
| ^^^^^^ expected `usize`, found `i64`
|
note: `-1_i64` cannot fit into type `usize`
--> $DIR/numeric-cast-no-fix.rs:36:15
|
LL | x_usize > -1_i64;
| ^^^^^^
= note: `-1_i64` cannot fit into type `usize`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:38:14
|
LL | x_u128 > -1_i64;
| ^^^^^^ expected `u128`, found `i64`
|
note: `-1_i64` cannot fit into type `u128`
--> $DIR/numeric-cast-no-fix.rs:38:14
|
LL | x_u128 > -1_i64;
| ^^^^^^
= note: `-1_i64` cannot fit into type `u128`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:40:13
|
LL | x_u64 > -1_i64;
| ^^^^^^ expected `u64`, found `i64`
|
note: `-1_i64` cannot fit into type `u64`
--> $DIR/numeric-cast-no-fix.rs:40:13
|
LL | x_u64 > -1_i64;
| ^^^^^^
= note: `-1_i64` cannot fit into type `u64`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:42:13
Expand Down Expand Up @@ -212,47 +172,31 @@ error[E0308]: mismatched types
LL | x_usize > -1_i32;
| ^^^^^^ expected `usize`, found `i32`
|
note: `-1_i32` cannot fit into type `usize`
--> $DIR/numeric-cast-no-fix.rs:49:15
|
LL | x_usize > -1_i32;
| ^^^^^^
= note: `-1_i32` cannot fit into type `usize`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:51:14
|
LL | x_u128 > -1_i32;
| ^^^^^^ expected `u128`, found `i32`
|
note: `-1_i32` cannot fit into type `u128`
--> $DIR/numeric-cast-no-fix.rs:51:14
|
LL | x_u128 > -1_i32;
| ^^^^^^
= note: `-1_i32` cannot fit into type `u128`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:53:13
|
LL | x_u64 > -1_i32;
| ^^^^^^ expected `u64`, found `i32`
|
note: `-1_i32` cannot fit into type `u64`
--> $DIR/numeric-cast-no-fix.rs:53:13
|
LL | x_u64 > -1_i32;
| ^^^^^^
= note: `-1_i32` cannot fit into type `u64`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:55:13
|
LL | x_u32 > -1_i32;
| ^^^^^^ expected `u32`, found `i32`
|
note: `-1_i32` cannot fit into type `u32`
--> $DIR/numeric-cast-no-fix.rs:55:13
|
LL | x_u32 > -1_i32;
| ^^^^^^
= note: `-1_i32` cannot fit into type `u32`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:57:13
Expand Down Expand Up @@ -282,59 +226,39 @@ error[E0308]: mismatched types
LL | x_usize > -1_i16;
| ^^^^^^ expected `usize`, found `i16`
|
note: `-1_i16` cannot fit into type `usize`
--> $DIR/numeric-cast-no-fix.rs:62:15
|
LL | x_usize > -1_i16;
| ^^^^^^
= note: `-1_i16` cannot fit into type `usize`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:64:14
|
LL | x_u128 > -1_i16;
| ^^^^^^ expected `u128`, found `i16`
|
note: `-1_i16` cannot fit into type `u128`
--> $DIR/numeric-cast-no-fix.rs:64:14
|
LL | x_u128 > -1_i16;
| ^^^^^^
= note: `-1_i16` cannot fit into type `u128`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:66:13
|
LL | x_u64 > -1_i16;
| ^^^^^^ expected `u64`, found `i16`
|
note: `-1_i16` cannot fit into type `u64`
--> $DIR/numeric-cast-no-fix.rs:66:13
|
LL | x_u64 > -1_i16;
| ^^^^^^
= note: `-1_i16` cannot fit into type `u64`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:68:13
|
LL | x_u32 > -1_i16;
| ^^^^^^ expected `u32`, found `i16`
|
note: `-1_i16` cannot fit into type `u32`
--> $DIR/numeric-cast-no-fix.rs:68:13
|
LL | x_u32 > -1_i16;
| ^^^^^^
= note: `-1_i16` cannot fit into type `u32`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:70:13
|
LL | x_u16 > -1_i16;
| ^^^^^^ expected `u16`, found `i16`
|
note: `-1_i16` cannot fit into type `u16`
--> $DIR/numeric-cast-no-fix.rs:70:13
|
LL | x_u16 > -1_i16;
| ^^^^^^
= note: `-1_i16` cannot fit into type `u16`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:72:12
Expand All @@ -353,71 +277,47 @@ error[E0308]: mismatched types
LL | x_usize > -1_i8;
| ^^^^^ expected `usize`, found `i8`
|
note: `-1_i8` cannot fit into type `usize`
--> $DIR/numeric-cast-no-fix.rs:75:15
|
LL | x_usize > -1_i8;
| ^^^^^
= note: `-1_i8` cannot fit into type `usize`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:77:14
|
LL | x_u128 > -1_i8;
| ^^^^^ expected `u128`, found `i8`
|
note: `-1_i8` cannot fit into type `u128`
--> $DIR/numeric-cast-no-fix.rs:77:14
|
LL | x_u128 > -1_i8;
| ^^^^^
= note: `-1_i8` cannot fit into type `u128`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:79:13
|
LL | x_u64 > -1_i8;
| ^^^^^ expected `u64`, found `i8`
|
note: `-1_i8` cannot fit into type `u64`
--> $DIR/numeric-cast-no-fix.rs:79:13
|
LL | x_u64 > -1_i8;
| ^^^^^
= note: `-1_i8` cannot fit into type `u64`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:81:13
|
LL | x_u32 > -1_i8;
| ^^^^^ expected `u32`, found `i8`
|
note: `-1_i8` cannot fit into type `u32`
--> $DIR/numeric-cast-no-fix.rs:81:13
|
LL | x_u32 > -1_i8;
| ^^^^^
= note: `-1_i8` cannot fit into type `u32`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:83:13
|
LL | x_u16 > -1_i8;
| ^^^^^ expected `u16`, found `i8`
|
note: `-1_i8` cannot fit into type `u16`
--> $DIR/numeric-cast-no-fix.rs:83:13
|
LL | x_u16 > -1_i8;
| ^^^^^
= note: `-1_i8` cannot fit into type `u16`

error[E0308]: mismatched types
--> $DIR/numeric-cast-no-fix.rs:85:12
|
LL | x_u8 > -1_i8;
| ^^^^^ expected `u8`, found `i8`
|
note: `-1_i8` cannot fit into type `u8`
--> $DIR/numeric-cast-no-fix.rs:85:12
|
LL | x_u8 > -1_i8;
| ^^^^^
= note: `-1_i8` cannot fit into type `u8`

error: aborting due to 36 previous errors

Expand Down

0 comments on commit d7277df

Please sign in to comment.