Rollup merge of #152103 - eggyal:caught-divergence-not-unused, r=cjgillot
Consider captures to be used by closures that unwind Assignments to a captured variable within a diverging closure should not be considered unused if the divergence is caught. This patch considers such assignments/captures to be used by diverging closures irrespective of whether the divergence is caught, but better a false negative unused lint than a false positive one (the latter having caused a stable-to-stable regression). Fixes rust-lang/rust#152079 r? compiler
This commit is contained in:
commit
c9a7f8afa9
2 changed files with 22 additions and 0 deletions
21
tests/ui/lint/unused/diverging-path.rs
Normal file
21
tests/ui/lint/unused/diverging-path.rs
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue