2 // Test when destructors run in a for loop. The intention is
3 // that the value for each iteration is dropped *after* the loop
4 // body has executed. This is true even when the value is assigned
5 // to a `_` pattern (and hence ignored).
9 struct Flag<'a>(&'a Cell<bool>);
11 impl<'a> Drop for Flag<'a> {
18 let alive2 = Cell::new(true);
19 for _i in std::iter::once(Flag(&alive2)) {
20 // The Flag value should be alive in the for loop body
21 assert_eq!(alive2.get(), true);
23 // The Flag value should be dead outside of the loop
24 assert_eq!(alive2.get(), false);
26 let alive = Cell::new(true);
27 for _ in std::iter::once(Flag(&alive)) {
28 // The Flag value should be alive in the for loop body even if it wasn't
29 // bound by the for loop
30 assert_eq!(alive.get(), true);
32 // The Flag value should be dead outside of the loop
33 assert_eq!(alive.get(), false);