diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2021-11-11 14:55:08 -0800 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2021-11-13 11:16:57 -0800 |
| commit | ece0e6ae6d29aa8c8b1fea06986840a4609f43b8 (patch) | |
| tree | a75781cf6c7584882fb3dd1dad722f26b3dcc023 | |
| parent | d846fe052294be6bd763bfb08479c9b93cda90fd (diff) | |
| download | rust-ece0e6ae6d29aa8c8b1fea06986840a4609f43b8.tar.gz rust-ece0e6ae6d29aa8c8b1fea06986840a4609f43b8.zip | |
Add raw pointer variant of #90752 with incorrect behavior
| -rw-r--r-- | src/test/ui/drop/issue-90752-raw-ptr-shenanigans.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/ui/drop/issue-90752-raw-ptr-shenanigans.rs b/src/test/ui/drop/issue-90752-raw-ptr-shenanigans.rs new file mode 100644 index 00000000000..4e67b35949e --- /dev/null +++ b/src/test/ui/drop/issue-90752-raw-ptr-shenanigans.rs @@ -0,0 +1,41 @@ +// run-pass + +use std::cell::RefCell; + +struct S<'a>(i32, &'a RefCell<Vec<i32>>); + +impl<'a> Drop for S<'a> { + fn drop(&mut self) { + self.1.borrow_mut().push(self.0); + } +} + +fn test(drops: &RefCell<Vec<i32>>) { + let mut foo = None; + let pfoo: *mut _ = &mut foo; + + match foo { + None => (), + _ => return, + } + + // Both S(0) and S(1) should be dropped, but aren't. + unsafe { *pfoo = Some((S(0, drops), S(1, drops))); } + + match foo { + Some((_x, _)) => {} + _ => {} + } +} + +fn main() { + let drops = RefCell::new(Vec::new()); + test(&drops); + + // Ideally, we want this... + //assert_eq!(*drops.borrow(), &[0, 1]); + + // But the delayed access through the raw pointer confuses drop elaboration, + // causing S(1) to be leaked. + assert_eq!(*drops.borrow(), &[0]); +} |
