rust/tests/ui/borrowck/issue-70919-drop-in-loop.rs
Giacomo Pasini beebd3a4c6
Add regression tests for issue 70919
Desugaring DropAndReplace at MIR build (#107844) fixed issue
70919. Add regressions tests, borrowed from #102078, to ensure we
check for this in the future.

Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
2023-03-05 16:56:57 +01:00

26 lines
502 B
Rust

// Regression test for issue #70919
// Tests that we don't emit a spurious "borrow might be used" error
// when we have an explicit `drop` in a loop
// check-pass
struct WrapperWithDrop<'a>(&'a mut bool);
impl<'a> Drop for WrapperWithDrop<'a> {
fn drop(&mut self) {
}
}
fn drop_in_loop() {
let mut base = true;
let mut wrapper = WrapperWithDrop(&mut base);
loop {
drop(wrapper);
base = false;
wrapper = WrapperWithDrop(&mut base);
}
}
fn main() {
}