]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/tests/rc.rs
Rollup merge of #103969 - ferrocene:pa-download-rustc-ui-tests, r=jyn514
[rust.git] / library / alloc / tests / rc.rs
index efb39a609665b33ad2e6b9b43a75533a98f1feb5..1d5f3c52006487bb9517b4fafec882965868c117 100644 (file)
@@ -206,3 +206,18 @@ fn hmm<'a>(val: &'a mut Weak<&'a str>) -> Weak<&'a str> {
     // `val` dropped here while still borrowed
     // borrow might be used here, when `val` is dropped and runs the `Drop` code for type `std::rc::Weak`
 }
+
+#[test]
+fn rc_from_vec_opt() {
+    let mut v = Vec::with_capacity(64);
+    v.push(0usize);
+    let addr = v.as_ptr().cast::<u8>();
+    let rc: Rc<[_]> = v.into();
+    unsafe {
+        assert_eq!(
+            rc.as_ptr().cast::<u8>().offset_from(addr),
+            (std::mem::size_of::<usize>() * 2) as isize,
+            "Vector allocation not reused"
+        );
+    }
+}