about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAyaz Hafiz <ayaz.hafiz.1@gmail.com>2020-06-16 20:05:55 -0700
committerAyaz Hafiz <ayaz.hafiz.1@gmail.com>2020-06-16 20:05:55 -0700
commitd7277df3acc47d3bcf9e580e8991e0ebb7e66664 (patch)
treeabb304318ae7a32698fb79b63f51d36d107ce8cf
parentf0d36891b6681c0833747d6188f0b194aee7fac8 (diff)
downloadrust-d7277df3acc47d3bcf9e580e8991e0ebb7e66664.tar.gz
rust-d7277df3acc47d3bcf9e580e8991e0ebb7e66664.zip
fixup! Note numeric literals that can never fit in an expected type
-rw-r--r--src/librustc_typeck/check/demand.rs2
-rw-r--r--src/test/ui/numeric/numeric-cast-no-fix.stderr150
2 files changed, 26 insertions, 126 deletions
diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs
index 79fc9772423..bcfc0cf347c 100644
--- a/src/librustc_typeck/check/demand.rs
+++ b/src/librustc_typeck/check/demand.rs
@@ -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.
diff --git a/src/test/ui/numeric/numeric-cast-no-fix.stderr b/src/test/ui/numeric/numeric-cast-no-fix.stderr
index 6501e11fc64..4852e7047b4 100644
--- a/src/test/ui/numeric/numeric-cast-no-fix.stderr
+++ b/src/test/ui/numeric/numeric-cast-no-fix.stderr
@@ -4,11 +4,7 @@ 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
@@ -16,11 +12,7 @@ error[E0308]: mismatched types
 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
@@ -28,11 +20,7 @@ error[E0308]: mismatched types
 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
@@ -40,11 +28,7 @@ error[E0308]: mismatched types
 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
@@ -52,11 +36,7 @@ error[E0308]: mismatched types
 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
@@ -75,11 +55,7 @@ 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
@@ -87,11 +63,7 @@ error[E0308]: mismatched types
 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
@@ -143,11 +115,7 @@ 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
@@ -155,11 +123,7 @@ error[E0308]: mismatched types
 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
@@ -167,11 +131,7 @@ error[E0308]: mismatched types
 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
@@ -212,11 +172,7 @@ 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
@@ -224,11 +180,7 @@ error[E0308]: mismatched types
 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
@@ -236,11 +188,7 @@ error[E0308]: mismatched types
 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
@@ -248,11 +196,7 @@ error[E0308]: mismatched types
 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
@@ -282,11 +226,7 @@ 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
@@ -294,11 +234,7 @@ error[E0308]: mismatched types
 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
@@ -306,11 +242,7 @@ error[E0308]: mismatched types
 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
@@ -318,11 +250,7 @@ error[E0308]: mismatched types
 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
@@ -330,11 +258,7 @@ error[E0308]: mismatched types
 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
@@ -353,11 +277,7 @@ 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
@@ -365,11 +285,7 @@ error[E0308]: mismatched types
 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
@@ -377,11 +293,7 @@ error[E0308]: mismatched types
 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
@@ -389,11 +301,7 @@ error[E0308]: mismatched types
 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
@@ -401,11 +309,7 @@ error[E0308]: mismatched types
 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
@@ -413,11 +317,7 @@ error[E0308]: mismatched types
 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