Rollup merge of #150955 - yukang-fix-149889-unused-assign, r=fee1-dead

Underscore-prefixed bindings are explicitly allowed to be unused

Fixes rust-lang/rust#149889
This commit is contained in:
Jacob Pratt 2026-01-18 03:16:45 -05:00 committed by GitHub
commit 0331284ffc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View file

@ -1086,6 +1086,11 @@ impl<'a, 'tcx> AssignmentResult<'a, 'tcx> {
let Some((name, decl_span)) = self.checked_places.names[index] else { continue };
// By convention, underscore-prefixed bindings are explicitly allowed to be unused.
if name.as_str().starts_with('_') {
continue;
}
let is_maybe_drop_guard = maybe_drop_guard(
tcx,
self.typing_env,

View file

@ -0,0 +1,29 @@
//@ check-pass
#![deny(unused_assignments)]
fn lock() -> impl Drop {
struct Handle;
impl Drop for Handle {
fn drop(&mut self) {}
}
Handle
}
fn bar(_f: impl FnMut(bool)) {}
pub fn foo() {
let mut _handle = None;
bar(move |l| {
if l {
_handle = Some(lock());
} else {
_handle = None;
}
})
}
fn main() {
foo();
}