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

let_underscore_drop should not trigger on function parameters #119696

Closed
matthiaskrgr opened this issue Jan 7, 2024 · 0 comments · Fixed by #119704
Closed

let_underscore_drop should not trigger on function parameters #119696

matthiaskrgr opened this issue Jan 7, 2024 · 0 comments · Fixed by #119704
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

#![warn(let_underscore_drop)]
fn main() {
    let _ = foo();
}

async fn from_config(_: Config) {}

async fn foo() {
    from_config(Config {
        nickname: None,
        ..Default::default()
    })
    .await;
}

#[derive(Default)]
struct Config {
    nickname: Option<Box<u8>>,
}

Current output

warning: non-binding let on a type that implements `Drop`
 --> src/main.rs:3:5
  |
3 |     let _ = foo();
  |     ^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(let_underscore_drop)]
  |         ^^^^^^^^^^^^^^^^^^^
help: consider binding to an unused variable to avoid immediately dropping the value
  |
3 |     let _unused = foo();
  |         ~~~~~~~
help: consider immediately dropping the value
  |
3 |     drop(foo());
  |     ~~~~~     +

warning: non-binding let on a type that implements `Drop`
 --> src/main.rs:6:22
  |
6 | async fn from_config(_: Config) {}
  |                      ^
  |
help: consider binding to an unused variable to avoid immediately dropping the value
  |
6 | async fn from_config(_unused: Config) {}
  |                      ~~~~~~~
help: consider immediately dropping the value
  |
6 | async fn from_config(drop(_): Config) {}
  |                      +++++ +

Desired output

No response

Rationale and extra context

The async fn from_config(drop(_): Config) {} suggestion does not make sense, this will fail when applied with rustfix.

Other cases

No response

Rust Version

rustc 1.77.0-nightly (87e143089 2024-01-07)
binary: rustc
commit-hash: 87e1430893d55001034bd76c5dbe832d80bc50c3
commit-date: 2024-01-07
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Anything else?

No response

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 7, 2024
@chenyukang chenyukang self-assigned this Jan 7, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 7, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 8, 2024
…re, r=Nilstrieb

Fix two variable binding issues in lint let_underscore

Fixes rust-lang#119696
Fixes rust-lang#119697
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 8, 2024
…re, r=Nilstrieb

Fix two variable binding issues in lint let_underscore

Fixes rust-lang#119696
Fixes rust-lang#119697
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 8, 2024
…re, r=Nilstrieb

Fix two variable binding issues in lint let_underscore

Fixes rust-lang#119696
Fixes rust-lang#119697
@bors bors closed this as completed in 5efa69d Jan 9, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 9, 2024
Rollup merge of rust-lang#119704 - chenyukang:yukang-fix-let_underscore, r=Nilstrieb

Fix two variable binding issues in lint let_underscore

Fixes rust-lang#119696
Fixes rust-lang#119697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants