diff options
| author | Oneirical <manchot@videotron.ca> | 2025-07-13 16:39:45 -0400 |
|---|---|---|
| committer | Oneirical <manchot@videotron.ca> | 2025-08-10 11:54:15 -0400 |
| commit | aa543963c68061d9ca46037071d66a028626ff3f (patch) | |
| tree | 2d6e7de7e1b2fe2176d81f48a456a05ef1b06dff /tests/ui/drop | |
| parent | f8e355c230c6eb7b78ffce6a92fd81f78c890524 (diff) | |
| download | rust-aa543963c68061d9ca46037071d66a028626ff3f.tar.gz rust-aa543963c68061d9ca46037071d66a028626ff3f.zip | |
Rehome tests/ui/issues/ tests [4/?]
Diffstat (limited to 'tests/ui/drop')
| -rw-r--r-- | tests/ui/drop/multiple-drop-safe-code-25549.rs | 34 | ||||
| -rw-r--r-- | tests/ui/drop/static-variable-with-drop-trait-9243.rs | 17 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/ui/drop/multiple-drop-safe-code-25549.rs b/tests/ui/drop/multiple-drop-safe-code-25549.rs new file mode 100644 index 00000000000..dcf7a3fc79c --- /dev/null +++ b/tests/ui/drop/multiple-drop-safe-code-25549.rs @@ -0,0 +1,34 @@ +// https://github.com/rust-lang/rust/issues/25549 +//@ run-pass +#![allow(unused_variables)] +struct Foo<'r>(&'r mut i32); + +impl<'r> Drop for Foo<'r> { + fn drop(&mut self) { + *self.0 += 1; + } +} + +trait Trait {} +impl<'r> Trait for Foo<'r> {} + +struct Holder<T: ?Sized>(T); + +fn main() { + let mut drops = 0; + + { + let y = &Holder([Foo(&mut drops)]) as &Holder<[Foo]>; + // this used to cause an extra drop of the Foo instance + let x = &y.0; + } + assert_eq!(1, drops); + + drops = 0; + { + let y = &Holder(Foo(&mut drops)) as &Holder<dyn Trait>; + // this used to cause an extra drop of the Foo instance + let x = &y.0; + } + assert_eq!(1, drops); +} diff --git a/tests/ui/drop/static-variable-with-drop-trait-9243.rs b/tests/ui/drop/static-variable-with-drop-trait-9243.rs new file mode 100644 index 00000000000..0ae32c983e9 --- /dev/null +++ b/tests/ui/drop/static-variable-with-drop-trait-9243.rs @@ -0,0 +1,17 @@ +// https://github.com/rust-lang/rust/issues/9243 +//@ build-pass +#![allow(dead_code)] +// Regression test for issue 9243 +#![allow(non_upper_case_globals)] + +pub struct Test { + mem: isize, +} + +pub static g_test: Test = Test {mem: 0}; + +impl Drop for Test { + fn drop(&mut self) {} +} + +fn main() {} |
