summaryrefslogtreecommitdiffstats
path: root/tests/ui/drop
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/ui/drop
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/drop')
-rw-r--r--tests/ui/drop/dropck-eyepatch-manuallydrop.rs22
-rw-r--r--tests/ui/drop/issue-110682.rs92
-rw-r--r--tests/ui/drop/issue-979.rs29
-rw-r--r--tests/ui/drop/repeat-drop.rs2
4 files changed, 145 insertions, 0 deletions
diff --git a/tests/ui/drop/dropck-eyepatch-manuallydrop.rs b/tests/ui/drop/dropck-eyepatch-manuallydrop.rs
new file mode 100644
index 000000000..ff100cd94
--- /dev/null
+++ b/tests/ui/drop/dropck-eyepatch-manuallydrop.rs
@@ -0,0 +1,22 @@
+// check-pass
+//! This test checks that dropck knows that ManuallyDrop does not drop its field.
+#![feature(dropck_eyepatch)]
+
+use std::mem::ManuallyDrop;
+
+struct S<T>(ManuallyDrop<T>);
+
+unsafe impl<#[may_dangle] T> Drop for S<T> {
+ fn drop(&mut self) {}
+}
+
+struct NonTrivialDrop<'a>(&'a str);
+impl<'a> Drop for NonTrivialDrop<'a> {
+ fn drop(&mut self) {}
+}
+
+fn main() {
+ let s = String::from("string");
+ let _t = S(ManuallyDrop::new(NonTrivialDrop(&s)));
+ drop(s);
+}
diff --git a/tests/ui/drop/issue-110682.rs b/tests/ui/drop/issue-110682.rs
new file mode 100644
index 000000000..35f9c7e8d
--- /dev/null
+++ b/tests/ui/drop/issue-110682.rs
@@ -0,0 +1,92 @@
+// build-pass
+// compile-flags: -Zmir-opt-level=3
+
+use std::fmt::Debug;
+use std::mem::ManuallyDrop;
+use std::ptr;
+
+pub trait BitRegister {}
+
+macro_rules! register {
+ ($($t:ty),+ $(,)?) => { $(
+ impl BitRegister for $t {
+ }
+ )* };
+}
+
+register!(u8, u16, u32);
+
+pub trait BitStore: Sized + Debug {
+ /// The register type that the implementor describes.
+ type Mem: BitRegister + Into<Self>;
+}
+
+macro_rules! store {
+ ($($t:ty),+ $(,)?) => { $(
+ impl BitStore for $t {
+ type Mem = Self;
+ }
+ )+ };
+}
+
+store!(u8, u16, u32,);
+
+#[repr(C)]
+pub struct BitVec<T>
+where
+ T: BitStore,
+{
+ /// Region pointer describing the live portion of the owned buffer.
+ pointer: ptr::NonNull<T>,
+ /// Allocated capacity, in elements `T`, of the owned buffer.
+ capacity: usize,
+}
+
+impl<T> BitVec<T>
+where
+ T: BitStore,
+{
+ pub fn new() -> Self {
+ let pointer = ptr::NonNull::<T>::new(ptr::null_mut()).unwrap();
+
+ BitVec { pointer, capacity: 10 }
+ }
+
+ pub fn clear(&mut self) {
+ unsafe {
+ self.set_len(0);
+ }
+ }
+
+ #[inline]
+ pub unsafe fn set_len(&mut self, new_len: usize) {}
+
+ fn with_vec<F, R>(&mut self, func: F) -> R
+ where
+ F: FnOnce(&mut ManuallyDrop<Vec<T::Mem>>) -> R,
+ {
+ let cap = self.capacity;
+ let elts = 10;
+ let mut vec = ManuallyDrop::new(unsafe { Vec::from_raw_parts(ptr::null_mut(), elts, cap) });
+ let out = func(&mut vec);
+
+ out
+ }
+}
+
+impl<T> Drop for BitVec<T>
+where
+ T: BitStore,
+{
+ #[inline]
+ fn drop(&mut self) {
+ // The buffer elements do not have destructors.
+ self.clear();
+ // Run the `Vec` destructor to deƤllocate the buffer.
+ self.with_vec(|vec| unsafe { ManuallyDrop::drop(vec) });
+ }
+}
+
+fn main() {
+ let bitvec = BitVec::<u32>::new();
+}
diff --git a/tests/ui/drop/issue-979.rs b/tests/ui/drop/issue-979.rs
new file mode 100644
index 000000000..57a99b325
--- /dev/null
+++ b/tests/ui/drop/issue-979.rs
@@ -0,0 +1,29 @@
+// run-pass
+#![allow(non_camel_case_types)]
+
+use std::cell::Cell;
+
+struct r<'a> {
+ b: &'a Cell<isize>,
+}
+
+impl<'a> Drop for r<'a> {
+ fn drop(&mut self) {
+ self.b.set(self.b.get() + 1);
+ }
+}
+
+fn r(b: &Cell<isize>) -> r {
+ r {
+ b: b
+ }
+}
+
+pub fn main() {
+ let b = &Cell::new(0);
+ {
+ let _p = Some(r(b));
+ }
+
+ assert_eq!(b.get(), 1);
+}
diff --git a/tests/ui/drop/repeat-drop.rs b/tests/ui/drop/repeat-drop.rs
index 8fd46ecaf..0afb4bb11 100644
--- a/tests/ui/drop/repeat-drop.rs
+++ b/tests/ui/drop/repeat-drop.rs
@@ -1,6 +1,8 @@
// run-pass
// needs-unwind
+#![allow(dropping_references, dropping_copy_types)]
+
static mut CHECK: usize = 0;
struct DropChecker(usize);