mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
beebd3a4c6
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>
25 lines
560 B
Rust
25 lines
560 B
Rust
// A version of `issue-70919-drop-in-loop`, but without
|
|
// the necessary `drop` call.
|
|
//
|
|
// This should fail to compile, since the `Drop` impl
|
|
// for `WrapperWithDrop` could observe the changed
|
|
// `base` value.
|
|
|
|
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 {
|
|
base = false; //~ ERROR: cannot assign to `base`
|
|
wrapper = WrapperWithDrop(&mut base);
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
}
|