Change:
() Errors: I would’ve expected something like: Edit: What actually should happen is the same as currently already with , i.e. it would look like modify labels: A-diagnostics, T-compiler, D-papercut, C-enhancement, E-easy <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --This issue has been assigned to via . <!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
Okay, lots of cases that already work got me confused into thinking this was fixed in nightly for a moment. What currently already works is the hint about converting where < where < What currently suggest even though works where < where ≤16 where ≤16
I reported a similar issue not long ago. Maybe it would be more robust and also more general to rewrite this suggestion code to actually look for the impl in question instead of having just a hard-coded list?
claim
I've created a PR augmenting the existing code to change the suggestions for the cases listed. However, I would like to explore the approach suggested(perhaps as part of a separate PR?). Any advice on how I could get the code to look for the impl so it can make the appropriate suggestion? Is the crate the right place to be looking at for this?
Yeah. I believe you'll need to create an and and then call , but there might be other/better ways to do this. You might want to ask for advice on Zulip.

Discussion:
suggest_to_change_suffix_or_into(err, is_fallible); true } <del> (&ty::Int(_), &ty::Uint(_)) | (&ty::Uint(_), &ty::Int(_)) => { </del> <ins> (&ty::Int(exp), &ty::Uint(found)) => { let is_fallible = match (exp.bit_width(), found.bit_width()) { (Some(exp), Some(found)) if found < exp => false, (None, Some(8)) => false, _ => true, }; suggest_to_change_suffix_or_into(err, is_fallible); true } (&ty::Uint(_), &ty::Int(_)) => { </ins> suggest_to_change_suffix_or_into(err, true); true }

--> $DIR/numeric-cast-2.rs:7:18 | LL |     let y: i64 = x + x; <del> |            ---   ^^^^^ expected `i64`, found `u16` |            | </del> <ins> |            ---   ^^^^^ |            |     | |            |     expected `i64`, found `u16` |            |     help: you can convert an `u16` to `i64`: `(x + x).into()` </ins> |            expected due to this <del> | help: you can convert an `u16` to `i64` and panic if the converted value wouldn't fit | LL |     let y: i64 = (x + x).try_into().unwrap(); |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> error[E0308]: mismatched types --> $DIR/numeric-cast-2.rs:9:18 | LL |     let z: i32 = x + x; <del> |            ---   ^^^^^ expected `i32`, found `u16` |            | </del> <ins> |            ---   ^^^^^ |            |     | |            |     expected `i32`, found `u16` |            |     help: you can convert an `u16` to `i32`: `(x + x).into()` </ins> |            expected due to this <del> | help: you can convert an `u16` to `i32` and panic if the converted value wouldn't fit | LL |     let z: i32 = (x + x).try_into().unwrap(); |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ </del> error: aborting due to 3 previous errors

//~^ ERROR mismatched types foo::<isize>(x_u16.try_into().unwrap()); //~^ ERROR mismatched types <del> foo::<isize>(x_u8.try_into().unwrap()); </del> <ins> foo::<isize>(x_u8.into()); </ins> //~^ ERROR mismatched types foo::<isize>(x_isize); foo::<isize>(x_i64.try_into().unwrap());

//~^ ERROR mismatched types foo::<i64>(x_u64.try_into().unwrap()); //~^ ERROR mismatched types <del> foo::<i64>(x_u32.try_into().unwrap()); </del> <ins> foo::<i64>(x_u32.into()); </ins> //~^ ERROR mismatched types <del> foo::<i64>(x_u16.try_into().unwrap()); </del> <ins> foo::<i64>(x_u16.into()); </ins> //~^ ERROR mismatched types <del> foo::<i64>(x_u8.try_into().unwrap()); </del> <ins> foo::<i64>(x_u8.into()); </ins> //~^ ERROR mismatched types foo::<i64>(x_isize.try_into().unwrap()); //~^ ERROR mismatched types

//~^ ERROR mismatched types foo::<i32>(x_u32.try_into().unwrap()); //~^ ERROR mismatched types <del> foo::<i32>(x_u16.try_into().unwrap()); </del> <ins> foo::<i32>(x_u16.into()); </ins> //~^ ERROR mismatched types <del> foo::<i32>(x_u8.try_into().unwrap()); </del> <ins> foo::<i32>(x_u8.into()); </ins> //~^ ERROR mismatched types foo::<i32>(x_isize.try_into().unwrap()); //~^ ERROR mismatched types

//~^ ERROR mismatched types foo::<i16>(x_u16.try_into().unwrap()); //~^ ERROR mismatched types <del> foo::<i16>(x_u8.try_into().unwrap()); </del> <ins> foo::<i16>(x_u8.into()); </ins> //~^ ERROR mismatched types foo::<i16>(x_isize.try_into().unwrap()); //~^ ERROR mismatched types

--> $DIR/numeric-cast.rs:52:18 | LL |     foo::<isize>(x_u8); <del> |                  ^^^^ expected `isize`, found `u8` | help: you can convert an `u8` to `isize` and panic if the converted value wouldn't fit | LL |     foo::<isize>(x_u8.try_into().unwrap()); |                  ^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                  ^^^^ |                  | |                  expected `isize`, found `u8` |                  help: you can convert an `u8` to `isize`: `x_u8.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:55:18

--> $DIR/numeric-cast.rs:92:16 | LL |     foo::<i64>(x_u32); <del> |                ^^^^^ expected `i64`, found `u32` | help: you can convert an `u32` to `i64` and panic if the converted value wouldn't fit | LL |     foo::<i64>(x_u32.try_into().unwrap()); |                ^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                ^^^^^ |                | |                expected `i64`, found `u32` |                help: you can convert an `u32` to `i64`: `x_u32.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:94:16 | LL |     foo::<i64>(x_u16); <del> |                ^^^^^ expected `i64`, found `u16` | help: you can convert an `u16` to `i64` and panic if the converted value wouldn't fit | LL |     foo::<i64>(x_u16.try_into().unwrap()); |                ^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                ^^^^^ |                | |                expected `i64`, found `u16` |                help: you can convert an `u16` to `i64`: `x_u16.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:96:16 | LL |     foo::<i64>(x_u8); <del> |                ^^^^ expected `i64`, found `u8` | help: you can convert an `u8` to `i64` and panic if the converted value wouldn't fit | LL |     foo::<i64>(x_u8.try_into().unwrap()); |                ^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                ^^^^ |                | |                expected `i64`, found `u8` |                help: you can convert an `u8` to `i64`: `x_u8.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:98:16

--> $DIR/numeric-cast.rs:138:16 | LL |     foo::<i32>(x_u16); <del> |                ^^^^^ expected `i32`, found `u16` | help: you can convert an `u16` to `i32` and panic if the converted value wouldn't fit | LL |     foo::<i32>(x_u16.try_into().unwrap()); |                ^^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                ^^^^^ |                | |                expected `i32`, found `u16` |                help: you can convert an `u16` to `i32`: `x_u16.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:140:16 | LL |     foo::<i32>(x_u8); <del> |                ^^^^ expected `i32`, found `u8` | help: you can convert an `u8` to `i32` and panic if the converted value wouldn't fit | LL |     foo::<i32>(x_u8.try_into().unwrap()); |                ^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                ^^^^ |                | |                expected `i32`, found `u8` |                help: you can convert an `u8` to `i32`: `x_u8.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:142:16

--> $DIR/numeric-cast.rs:184:16 | LL |     foo::<i16>(x_u8); <del> |                ^^^^ expected `i16`, found `u8` | help: you can convert an `u8` to `i16` and panic if the converted value wouldn't fit | LL |     foo::<i16>(x_u8.try_into().unwrap()); |                ^^^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |                ^^^^ |                | |                expected `i16`, found `u8` |                help: you can convert an `u8` to `i16`: `x_u8.into()` </ins> error[E0308]: mismatched types --> $DIR/numeric-cast.rs:186:16