]> git.lizzy.rs Git - rust.git/commitdiff
adjust for Weak::as_raw -> as_ptr rename
authorRalf Jung <post@ralfj.de>
Mon, 20 Apr 2020 08:04:17 +0000 (10:04 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 20 Apr 2020 08:04:17 +0000 (10:04 +0200)
tests/compile-fail/rc_as_ptr.rs [new file with mode: 0644]
tests/compile-fail/rc_as_raw.rs [deleted file]

diff --git a/tests/compile-fail/rc_as_ptr.rs b/tests/compile-fail/rc_as_ptr.rs
new file mode 100644 (file)
index 0000000..0b98c7d
--- /dev/null
@@ -0,0 +1,21 @@
+// This should fail even without validation
+// compile-flags: -Zmiri-disable-validation
+#![feature(weak_into_raw)]
+
+use std::rc::{Rc, Weak};
+use std::ptr;
+
+/// Taken from the `Weak::as_ptr` doctest.
+fn main() {
+    let strong = Rc::new(Box::new(42));
+    let weak = Rc::downgrade(&strong);
+    // Both point to the same object
+    assert!(ptr::eq(&*strong, Weak::as_ptr(&weak)));
+    // The strong here keeps it alive, so we can still access the object.
+    assert_eq!(42, **unsafe { &*Weak::as_ptr(&weak) });
+    
+    drop(strong);
+    // But not any more. We can do Weak::as_raw(&weak), but accessing the pointer would lead to
+    // undefined behaviour.
+    assert_eq!(42, **unsafe { &*Weak::as_ptr(&weak) }); //~ ERROR dereferenced after this allocation got freed
+}
diff --git a/tests/compile-fail/rc_as_raw.rs b/tests/compile-fail/rc_as_raw.rs
deleted file mode 100644 (file)
index cb50ca5..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-// This should fail even without validation
-// compile-flags: -Zmiri-disable-validation
-#![feature(weak_into_raw)]
-
-use std::rc::{Rc, Weak};
-use std::ptr;
-
-/// Taken from the `Weak::as_raw` doctest.
-fn main() {
-    let strong = Rc::new(Box::new(42));
-    let weak = Rc::downgrade(&strong);
-    // Both point to the same object
-    assert!(ptr::eq(&*strong, Weak::as_raw(&weak)));
-    // The strong here keeps it alive, so we can still access the object.
-    assert_eq!(42, **unsafe { &*Weak::as_raw(&weak) });
-    
-    drop(strong);
-    // But not any more. We can do Weak::as_raw(&weak), but accessing the pointer would lead to
-    // undefined behaviour.
-    assert_eq!(42, **unsafe { &*Weak::as_raw(&weak) }); //~ ERROR dereferenced after this allocation got freed
-}