-
Notifications
You must be signed in to change notification settings - Fork 13.3k
.try_into().unwrap()
is suggested even when .into()
would work
#70851
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
Comments
You need to change the following rust/src/librustc_typeck/check/demand.rs Lines 755 to 770 in 6dee5f1
so that when one of the |
Hi, this seems like a good first issue. Can I take this up as my first contribution? |
@ryr3 sure! Go ahead. Visit the rustc guide if this is your first time compiling rustc. |
@estebank Isn't it the opposite? If we try to convert a |
Yeah. It's the other way around. |
Sorry about those notifications, all. I was experimenting a bit. |
There might not be tests exercising this code path, but you can add some cases to The code change looks good. You will want to also run |
There still are some. For example: rust/src/test/ui/numeric/numeric-cast.stderr Lines 23 to 32 in 53712f8
needs to be changed |
@LeSeulArtichaut that one seems almost incidental. Given that the test matrix in this case is small enough, it's a good idea to exhaust it in a central place, both for the positive cases (we suggest |
With the changes I've made now, it's such that the compiler will suggest usize be .into() when the function requires a u8. Is that fine, because usize will greater than u8 on most targets? Also, when I'm writing tests for the *size cases, should I use the |
If I understand the code correctly, in your changes, the pattern As for the testing, I think the value doesn't really matter because those checks are about types, not values themselves. Rust doesn't make implicit conversions. You can just use random values like |
Thanks! I just realized that it would be the other way around here, because in rust/src/librustc_typeck/check/demand.rs Line 756 in 6dee5f1
rust/src/librustc_typeck/check/demand.rs Line 765 in 6dee5f1
Should I rearrange that too (within the match statements only where appropriate) or leave it as it is? |
It'll be great if you can bring some consistency in the order. |
Suggest .into() over try_into() when it would work It would be better to suggest x.into() instead, which is shorter, cannot fail, and doesn't require importing a trait. Tests have been added and made up to date. Fixes rust-lang#70851
It would be better to suggest
x.into()
instead, which is shorter, cannot fail, and doesn't require importing a trait.This issue has been assigned to @ryr3 via this comment.
The text was updated successfully, but these errors were encountered: