Skip to content

Commit d846fe0

Browse files
Add regression test for rust-lang#90752
1 parent bea1bde commit d846fe0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/ui/drop/issue-90752.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// run-pass
2+
3+
use std::cell::RefCell;
4+
5+
struct S<'a>(i32, &'a RefCell<Vec<i32>>);
6+
7+
impl<'a> Drop for S<'a> {
8+
fn drop(&mut self) {
9+
self.1.borrow_mut().push(self.0);
10+
}
11+
}
12+
13+
fn test(drops: &RefCell<Vec<i32>>) {
14+
let mut foo = None;
15+
match foo {
16+
None => (),
17+
_ => return,
18+
}
19+
20+
*(&mut foo) = Some((S(0, drops), S(1, drops))); // Both S(0) and S(1) should be dropped
21+
22+
match foo {
23+
Some((_x, _)) => {}
24+
_ => {}
25+
}
26+
}
27+
28+
fn main() {
29+
let drops = RefCell::new(Vec::new());
30+
test(&drops);
31+
assert_eq!(*drops.borrow(), &[0, 1]);
32+
}

0 commit comments

Comments
 (0)