-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler suggests unnecessary try into #63697
Comments
I am using Rust 1.37.0. |
cc @estebank |
Similarly, this code should suggest replacing #[derive(Debug)]
struct Member(u16);
pub fn main() {
let m = Member(i32::from(0_u8));
println!("{:?}", m);
}
|
For the case where we have |
@estebank that sounds good to me 👍 |
@rustbot claim |
@estebank Which of these options makes more sense? Check if the new (suggested) conversion is infallible
1. Seems like the user already opted in for panicking if the conversion fails, so conversion was fallible and will stay so: struct A(i16);
fn main() {
let _ = A(i32::from(0_i64));
} 2. The conversion is infallible but will become fallible if the suggestion is applied: struct A(i16);
fn main() {
let _ = A(i128::from(0_i64));
} |
@rustbot release-assignment |
@u32i64 sorry, didn't see your claim before I pushed my PR :-| |
Do not suggest `.try_into()` on `i32::from(x)` Fix rust-lang#63697.
Do not suggest `.try_into()` on `i32::from(x)` Fix rust-lang#63697.
I updated a dependency and the type of a struct field changed from an
i32
to au16
.I am assigning a
u16
value to this struct field. Before, I was callingi32::from
to convert theu16
to ani32
. With the upgrade this is unnecessary since the field and the value are bothu16
.The rust compiler suggests this fix:
But it should really suggest removing the
i32::from
and using theu16
directly.The text was updated successfully, but these errors were encountered: