-
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
Missing warning for migration of let _ = x
between Rust 2018 and 2021 edition
#90465
Comments
Thanks for the report! I believe this is already mentioned in the edition guide here. Values that aren't read are not captured, and I believe that is the intended behavior. However, I am a little surprised that |
The confusing issue here is that the value was actually "used" (well, it was written in the closure body) and only the easy to miss Maybe there should be generally a lint for the |
This is indeed expected behavior, but a lint for this case is an interesting idea. I guess that the |
Hmm, I too am a bit surprised that you don't get a migration lint already. Are you sure that you don't? |
OK, I can attest that you don't get a warning (playground). Curious. |
let _ = x
between Rust 2018 and 2021 edition
Yes, that was the idea.
Yes, definitely :) I just retried again. But this should probably not just cause a migration lint but generally cause a warning with the 2021 edition. |
I agree that fn foo() {
let x: u32;
let _ = x;
} |
Indeed, I wasn't aware of this :) Should I create a separate issue for having a general, non-migration warning for this? |
@sdroege +1 from me, I think @Mark-Simulacrum has often discussed their desire for such a lint as well |
Sure, see #90524 . Thanks |
Fix in #90597 |
The following example does not get a migration warning in Rust 2018 (or Rust 2021) -- (playground):
The behavior of
let _ = x
changed in the new edition, but there ought to have been a warning.Original issue
See the below code
With 2018 edition (playground link) this prints
With 2021 edition (playground link) this prints
That is, with the 2021 edition the first closure is apparently not capturing
f0
at all (and drops it at the end ofmain
) while with the 2018 edition it did.This might be intentional and expected or not, which is why I'm creating this issue. It might be worth mentioning it as a potential porting trap in the edition guide. Note that
cargo fix --edition
did not catch this one (but a couple of others where the behaviour difference was irrelevant).This subtle behaviour change caused a test in gtk-rs to timeout and fail.
The text was updated successfully, but these errors were encountered: