Repository navigation
let_underscore_* lints usage in place expression contexts #164746
Copy link
Copy link
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This was discovered by @traviscross at #164414 (comment)
The let_underscore_lock lint, the let_underscore_drop lint, and the upcoming let_underscore_drop_guard lint all detect when a pattern (or assignee expression) written as _ is matched against some relevant types. The lints assume that when such a thing happens, a value of the relevant type is dropped. This assumption is incorrect when the pattern is matched against a place expression. For example:
use std::sync::Mutex;
pub fn foo(x: Mutex<i32>) {
let y = x.lock().unwrap();
let _ = y;
}error: non-binding let on a synchronization lock
--> src/lib.rs:4:9
|
4 | let _ = y;
| ^ this lock is not assigned to a binding and is immediately dropped
|
= note: `#[deny(let_underscore_lock)]` (part of `#[deny(let_underscore)]`) on by default
help: consider binding to an unused variable to avoid immediately dropping the value
|
4 | let _unused = y;
| ++++++
help: consider immediately dropping the value
|
4 - let _ = y;
4 + drop(y);
|
error: could not compile `playground` (lib) due to 1 previous error
The let _ = y; doesn't actually drop the y at all. The lint message is wrong.
Meta
Reproducible on the playground with rust version 1.99.1.
Reacted by Max
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
yashaggarwal85d commentedon Oct 26, 2026
yashaggarwal85d commentedon Oct 26, 2026