]> git.lizzy.rs Git - rust.git/blobdiff - library/core/tests/ptr.rs
Auto merge of #100946 - jyn514:query-system-3, r=cjgillot
[rust.git] / library / core / tests / ptr.rs
index cc159741d79ec2755c1bdd43d24d7f6154a124fd..12861794c2d2c248d50ebcbb41c9c6d3a749dbf3 100644 (file)
@@ -96,17 +96,14 @@ fn test_is_null() {
     let nmi: *mut dyn ToString = null_mut::<isize>();
     assert!(nmi.is_null());
 
-    #[cfg(not(bootstrap))]
-    {
-        extern "C" {
-            type Extern;
-        }
-        let ec: *const Extern = null::<Extern>();
-        assert!(ec.is_null());
-
-        let em: *mut Extern = null_mut::<Extern>();
-        assert!(em.is_null());
+    extern "C" {
+        type Extern;
     }
+    let ec: *const Extern = null::<Extern>();
+    assert!(ec.is_null());
+
+    let em: *mut Extern = null_mut::<Extern>();
+    assert!(em.is_null());
 }
 
 #[test]
@@ -793,6 +790,31 @@ pub fn set_tag(&mut self, data: usize) {
     }
 }
 
+#[test]
+fn swap_copy_untyped() {
+    // We call `{swap,copy}{,_nonoverlapping}` at `bool` type on data that is not a valid bool.
+    // These should all do untyped copies, so this should work fine.
+    let mut x = 5u8;
+    let mut y = 6u8;
+
+    let ptr1 = &mut x as *mut u8 as *mut bool;
+    let ptr2 = &mut y as *mut u8 as *mut bool;
+
+    unsafe {
+        ptr::swap(ptr1, ptr2);
+        ptr::swap_nonoverlapping(ptr1, ptr2, 1);
+    }
+    assert_eq!(x, 5);
+    assert_eq!(y, 6);
+
+    unsafe {
+        ptr::copy(ptr1, ptr2, 1);
+        ptr::copy_nonoverlapping(ptr1, ptr2, 1);
+    }
+    assert_eq!(x, 5);
+    assert_eq!(y, 5);
+}
+
 #[test]
 fn test_const_copy() {
     const {