]> git.lizzy.rs Git - rust.git/blobdiff - src/test/ui/numeric/numeric-cast-2.stderr
Suggest try_into when possible
[rust.git] / src / test / ui / numeric / numeric-cast-2.stderr
index 79088f0e2ca2f224c3453a48f764b932e712ee34..be4411e630becfdbfec6b2ce31d0dbcb8dfd62e4 100644 (file)
@@ -3,18 +3,30 @@ error[E0308]: mismatched types
    |
 LL |     let x: u16 = foo();
    |                  ^^^^^ expected u16, found i32
+help: you can convert an `i32` to `u16` or panic if it the converted value wouldn't fit
+   |
+LL |     let x: u16 = foo().try_into().unwrap();
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/numeric-cast-2.rs:7:18
    |
 LL |     let y: i64 = x + x;
    |                  ^^^^^ expected i64, found u16
+help: you can convert an `u16` to `i64` or panic if it the converted value wouldn't fit
+   |
+LL |     let y: i64 = (x + x).try_into().unwrap();
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0308]: mismatched types
   --> $DIR/numeric-cast-2.rs:9:18
    |
 LL |     let z: i32 = x + x;
    |                  ^^^^^ expected i32, found u16
+help: you can convert an `u16` to `i32` or panic if it the converted value wouldn't fit
+   |
+LL |     let z: i32 = (x + x).try_into().unwrap();
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 3 previous errors