Open
Description
This is related to #90465.
The problem is code as follows
let x = ...;
let c = move || {
let _ = x;
};
or also
fn foo() {
let x: u32;
let _ = x;
}
The let _ = x
statement in both cases has no effect at all:
- In the first case with the 2021 edition it does not move the
x
into the closure. With the 2018 edition it is moved into the closure however. - In the second case the variable
x
is not even initialized.
As the statement generally has no effect, it would be good to warn if it used like in the above cases. The author of the code probably intended something that the code is not actually doing.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
let _ = x
between Rust 2018 and 2021 edition #90465RalfJung commentedon Nov 3, 2021
let _
has a bunch of 'interesting' behaviors, Cc #79735 rust-lang/unsafe-code-guidelines#261the8472 commentedon Nov 5, 2021
It's currently the recommended way to silence
#[must_use]
warnings.RalfJung commentedon Nov 5, 2021
This issue is specifically about
let _ = x
wherex
is a variable (I think). That's different fromlet _ = foo()
silencing amust_use
onfoo
.