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
1 change: 1 addition & 0 deletions compiler/rustc_mir_transform/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ impl<'tcx> Visitor<'tcx> for TransferFunction<'_, 'tcx> {
TerminatorKind::Return
| TerminatorKind::Yield { .. }
| TerminatorKind::Goto { target: START_BLOCK } // Inserted for the `FnMut` case.
| TerminatorKind::Call { target: None, .. } // unwinding could be caught
if self.capture_kind != CaptureKind::None =>
{
// All indirect captures have an effect on the environment, so we mark them as live.
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/lint/unused/diverging-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Assignments to a captured variable within a diverging closure should not be considered unused if
//! the divergence is caught.
//!
//! Regression test for https://github.com/rust-lang/rust/issues/152079
//@ compile-flags: -Wunused
//@ check-pass

fn main() {
let mut x = 1;
catch(|| {
x = 2;
panic!();
});
dbg!(x);
}

fn catch<F: FnOnce()>(f: F) {
if let Ok(true) = std::fs::exists("may_or_may_not_call_f") {
_ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(f));
}
}
Loading