diff options
| author | The rustc-josh-sync Cronjob Bot <github-actions@github.com> | 2025-08-07 04:18:21 +0000 |
|---|---|---|
| committer | The rustc-josh-sync Cronjob Bot <github-actions@github.com> | 2025-08-07 04:18:21 +0000 |
| commit | e296468a473de9c4173f673e45f05da6dd911d7c (patch) | |
| tree | 40a1b0e61f6e6557bd7e91224505244287c0306f /tests/ui/drop | |
| parent | 4f96b2aa5e333fc1cad8b5987bfc2d18821d6d4d (diff) | |
| parent | 6bcdcc73bd11568fd85f5a38b58e1eda054ad1cd (diff) | |
| download | rust-e296468a473de9c4173f673e45f05da6dd911d7c.tar.gz rust-e296468a473de9c4173f673e45f05da6dd911d7c.zip | |
Merge ref '6bcdcc73bd11' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: 6bcdcc73bd11568fd85f5a38b58e1eda054ad1cd Filtered ref: 6cc4ce79e1f8dc0ec5a2e18049b9c1a51dee3221 This merge was created using https://github.com/rust-lang/josh-sync.
Diffstat (limited to 'tests/ui/drop')
| -rw-r--r-- | tests/ui/drop/destructor-run-for-expression-4734.rs | 39 | ||||
| -rw-r--r-- | tests/ui/drop/destructor-run-for-let-ignore-6892.rs | 61 | ||||
| -rw-r--r-- | tests/ui/drop/drop-count-assertion-16151.rs | 33 |
3 files changed, 133 insertions, 0 deletions
diff --git a/tests/ui/drop/destructor-run-for-expression-4734.rs b/tests/ui/drop/destructor-run-for-expression-4734.rs new file mode 100644 index 00000000000..57971ee5ef7 --- /dev/null +++ b/tests/ui/drop/destructor-run-for-expression-4734.rs @@ -0,0 +1,39 @@ +// https://github.com/rust-lang/rust/issues/4734 +//@ run-pass +#![allow(dead_code)] +// Ensures that destructors are run for expressions of the form "e;" where +// `e` is a type which requires a destructor. + +// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint +#![allow(static_mut_refs)] +#![allow(path_statements)] + +struct A { n: isize } +struct B; + +static mut NUM_DROPS: usize = 0; + +impl Drop for A { + fn drop(&mut self) { + unsafe { NUM_DROPS += 1; } + } +} + +impl Drop for B { + fn drop(&mut self) { + unsafe { NUM_DROPS += 1; } + } +} + +fn main() { + assert_eq!(unsafe { NUM_DROPS }, 0); + { let _a = A { n: 1 }; } + assert_eq!(unsafe { NUM_DROPS }, 1); + { A { n: 3 }; } + assert_eq!(unsafe { NUM_DROPS }, 2); + + { let _b = B; } + assert_eq!(unsafe { NUM_DROPS }, 3); + { B; } + assert_eq!(unsafe { NUM_DROPS }, 4); +} diff --git a/tests/ui/drop/destructor-run-for-let-ignore-6892.rs b/tests/ui/drop/destructor-run-for-let-ignore-6892.rs new file mode 100644 index 00000000000..0fcf133c2b1 --- /dev/null +++ b/tests/ui/drop/destructor-run-for-let-ignore-6892.rs @@ -0,0 +1,61 @@ +// https://github.com/rust-lang/rust/issues/6892 +//@ run-pass +#![allow(dead_code)] +// Ensures that destructors are run for expressions of the form "let _ = e;" +// where `e` is a type which requires a destructor. + +// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint +#![allow(static_mut_refs)] + +struct Foo; +struct Bar { x: isize } +struct Baz(isize); +enum FooBar { _Foo(Foo), _Bar(usize) } + +static mut NUM_DROPS: usize = 0; + +impl Drop for Foo { + fn drop(&mut self) { + unsafe { NUM_DROPS += 1; } + } +} +impl Drop for Bar { + fn drop(&mut self) { + unsafe { NUM_DROPS += 1; } + } +} +impl Drop for Baz { + fn drop(&mut self) { + unsafe { NUM_DROPS += 1; } + } +} +impl Drop for FooBar { + fn drop(&mut self) { + unsafe { NUM_DROPS += 1; } + } +} + +fn main() { + assert_eq!(unsafe { NUM_DROPS }, 0); + { let _x = Foo; } + assert_eq!(unsafe { NUM_DROPS }, 1); + { let _x = Bar { x: 21 }; } + assert_eq!(unsafe { NUM_DROPS }, 2); + { let _x = Baz(21); } + assert_eq!(unsafe { NUM_DROPS }, 3); + { let _x = FooBar::_Foo(Foo); } + assert_eq!(unsafe { NUM_DROPS }, 5); + { let _x = FooBar::_Bar(42); } + assert_eq!(unsafe { NUM_DROPS }, 6); + + { let _ = Foo; } + assert_eq!(unsafe { NUM_DROPS }, 7); + { let _ = Bar { x: 21 }; } + assert_eq!(unsafe { NUM_DROPS }, 8); + { let _ = Baz(21); } + assert_eq!(unsafe { NUM_DROPS }, 9); + { let _ = FooBar::_Foo(Foo); } + assert_eq!(unsafe { NUM_DROPS }, 11); + { let _ = FooBar::_Bar(42); } + assert_eq!(unsafe { NUM_DROPS }, 12); +} diff --git a/tests/ui/drop/drop-count-assertion-16151.rs b/tests/ui/drop/drop-count-assertion-16151.rs new file mode 100644 index 00000000000..ede6bc23e73 --- /dev/null +++ b/tests/ui/drop/drop-count-assertion-16151.rs @@ -0,0 +1,33 @@ +// https://github.com/rust-lang/rust/issues/16151 +//@ run-pass + +// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint +#![allow(static_mut_refs)] + +use std::mem; + +static mut DROP_COUNT: usize = 0; + +struct Fragment; + +impl Drop for Fragment { + fn drop(&mut self) { + unsafe { + DROP_COUNT += 1; + } + } +} + +fn main() { + { + let mut fragments = vec![Fragment, Fragment, Fragment]; + let _new_fragments: Vec<Fragment> = mem::replace(&mut fragments, vec![]) + .into_iter() + .skip_while(|_fragment| { + true + }).collect(); + } + unsafe { + assert_eq!(DROP_COUNT, 3); + } +} |
