Skip to content
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

Warn if no-op let _ = x statement is used #90524

Open
sdroege opened this issue Nov 3, 2021 · 3 comments
Open

Warn if no-op let _ = x statement is used #90524

sdroege opened this issue Nov 3, 2021 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@sdroege
Copy link
Contributor

sdroege commented Nov 3, 2021

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.

@RalfJung
Copy link
Member

RalfJung commented Nov 3, 2021

let _ has a bunch of 'interesting' behaviors, Cc #79735 rust-lang/unsafe-code-guidelines#261

@the8472
Copy link
Member

the8472 commented Nov 5, 2021

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.

It's currently the recommended way to silence #[must_use] warnings.

@RalfJung
Copy link
Member

RalfJung commented Nov 5, 2021

It's currently the recommended way to silence #[must_use] warnings.

This issue is specifically about let _ = x where x is a variable (I think). That's different from let _ = foo() silencing a must_use on foo.

@camelid camelid added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants