Skip to content

let_underscore_drop should not trigger on function parameters #119696

Closed
@matthiaskrgr

Description

@matthiaskrgr

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions