]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-27401-dropflag-reinit.rs
Merge commit 'a8385522ade6f67853edac730b5bf164ddb298fd' into simd-remove-autosplats
[rust.git] / src / test / ui / issues / issue-27401-dropflag-reinit.rs
1 // run-pass
2
3 // Check that when a `let`-binding occurs in a loop, its associated
4 // drop-flag is reinitialized (to indicate "needs-drop" at the end of
5 // the owning variable's scope).
6
7 struct A<'a>(&'a mut i32);
8
9 impl<'a> Drop for A<'a> {
10     fn drop(&mut self) {
11         *self.0 += 1;
12     }
13 }
14
15 fn main() {
16     let mut cnt = 0;
17     for i in 0..2 {
18         let a = A(&mut cnt);
19         if i == 1 { // Note that
20             break;  //  both this break
21         }           //   and also
22         drop(a);    //    this move of `a`
23         // are necessary to expose the bug
24     }
25     assert_eq!(cnt, 2);
26 }