]> git.lizzy.rs Git - rust.git/commitdiff
merge packed_static and packed_struct
authorRalf Jung <post@ralfj.de>
Thu, 16 Apr 2020 07:27:40 +0000 (09:27 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 16 Apr 2020 07:33:22 +0000 (09:33 +0200)
tests/run-pass/packed_static.rs [deleted file]
tests/run-pass/packed_struct.rs

diff --git a/tests/run-pass/packed_static.rs b/tests/run-pass/packed_static.rs
deleted file mode 100644 (file)
index 1fa3a36..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#[repr(packed)]
-struct Foo {
-    i: i32
-}
-
-fn main() {
-    assert_eq!({FOO.i}, 42);
-}
-
-static FOO: Foo = Foo { i: 42 };
index 52b75d1a520ae19cd97ecb3c8e2f7e947f3eaab2..cb0bc9859345ab4f7ea16abbf01cc3864037d5a6 100644 (file)
@@ -1,28 +1,48 @@
 #![feature(unsize, coerce_unsized)]
 
-#[repr(packed)]
-struct S {
-    a: i32,
-    b: i64,
-}
 
-#[repr(packed)]
-#[allow(dead_code)]
-struct Test1<'a> {
-    x: u8,
-    other: &'a u32,
-}
+fn test_basic() {
+    #[repr(packed)]
+    struct S {
+        a: i32,
+        b: i64,
+    }
 
-#[repr(packed)]
-#[allow(dead_code)]
-struct Test2<'a> {
-    x: u8,
-    other: &'a Test1<'a>,
-}
+    #[repr(packed)]
+    #[allow(dead_code)]
+    struct Test1<'a> {
+        x: u8,
+        other: &'a u32,
+    }
+
+    #[repr(packed)]
+    #[allow(dead_code)]
+    struct Test2<'a> {
+        x: u8,
+        other: &'a Test1<'a>,
+    }
 
-fn test(t: Test2) {
-    let x = *t.other.other;
-    assert_eq!(x, 42);
+    fn test(t: Test2) {
+        let x = *t.other.other;
+        assert_eq!(x, 42);
+    }
+
+    let mut x = S {
+        a: 42,
+        b: 99,
+    };
+    let a = x.a;
+    let b = x.b;
+    assert_eq!(a, 42);
+    assert_eq!(b, 99);
+    // can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference
+    assert_eq!({x.a}, 42);
+    assert_eq!({x.b}, 99);
+
+    x.b = 77;
+    assert_eq!({x.b}, 77);
+
+    test(Test2 { x: 0, other: &Test1 { x: 0, other: &42 }});
 }
 
 fn test_unsizing() {
@@ -83,25 +103,21 @@ fn test_inner_packed() {
     let _o2 = o.clone();
 }
 
-fn main() {
-    let mut x = S {
-        a: 42,
-        b: 99,
-    };
-    let a = x.a;
-    let b = x.b;
-    assert_eq!(a, 42);
-    assert_eq!(b, 99);
-    // can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference
-    assert_eq!({x.a}, 42);
-    assert_eq!({x.b}, 99);
+fn test_static() {
+    #[repr(packed)]
+    struct Foo {
+        i: i32
+    }
 
-    x.b = 77;
-    assert_eq!({x.b}, 77);
+    static FOO: Foo = Foo { i: 42 };
 
-    test(Test2 { x: 0, other: &Test1 { x: 0, other: &42 }});
+    assert_eq!({FOO.i}, 42);
+}
 
+fn main() {
+    test_basic();
     test_unsizing();
     test_drop();
     test_inner_packed();
+    test_static();
 }