]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/tests/arc.rs
Rollup merge of #104516 - notriddle:notriddle/flex-basis-sidebar-width, r=GuillaumeGomez
[rust.git] / library / alloc / tests / arc.rs
index ce40b5c9b0a0d3a5948635c131dc1b353adbbcfb..eb379e4d6a10f9edfba773e77377f3cd4169a289 100644 (file)
@@ -210,3 +210,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::sync::Weak`
 }
+
+#[test]
+fn arc_from_vec_opt() {
+    let mut v = Vec::with_capacity(64);
+    v.push(0usize);
+    let addr = v.as_ptr().cast::<u8>();
+    let arc: Arc<[_]> = v.into();
+    unsafe {
+        assert_eq!(
+            arc.as_ptr().cast::<u8>().offset_from(addr),
+            (std::mem::size_of::<usize>() * 2) as isize,
+            "Vector allocation not reused"
+        );
+    }
+}