rust-lang / rust-lang/rust-clippy
`let_underscore_lock` false positive
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Lint name: let_underscore_lock
I tried this code:
let _ = task_sender.lock().map(|mut s| s.take().map(|s| s.send(())));
The type of this is a Result as shown by this rustc warning if I remove the binding:
warning: unused `Result` that must be used
--> bee-api/bee-rest-api/src/endpoints/routes/api/plugins/debug/white_flag.rs:137:17
|
137 | task_sender.lock().map(|mut s| s.take().map(|s| s.send(())));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_must_use)]` on by default
= note: this `Result` may be an `Err` variant, which should be handled
warning: 1 warning emitted
With the binding I get the following clippy warning
error: non-binding let on a synchronization lock
--> bee-api/bee-rest-api/src/endpoints/routes/api/plugins/debug/white_flag.rs:154:13
|
154 | let _ = sender.lock().map(|mut s| s.take().map(|s| s.send(())));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_lock
Meta
clippy 0.1.52 (9bc8c42b 2021-05-09)
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the let_underscore_lock lint and reproduce the warning using the Rust snippet in the issue. Trace how this expression is classified, then verify that the reported case no longer produces a false positive while the unused Result warning remains applicable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100