Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_mir_transform/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/lint/unused/underscore-capture-issue-149889.rs
Original file line number Diff line number Diff line change
@@ -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();
}
Loading