about summary refs log tree commit diff
path: root/src/test/ui/consts
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-18 13:22:38 +0000
committerbors <bors@rust-lang.org>2019-08-18 13:22:38 +0000
commitea52be482ab4945fda63cb65b6a198309a041e3c (patch)
tree7c1bd1c098b3d0bced875d58a3953717fa15e177 /src/test/ui/consts
parent71e2882973e63b9ddc837a61ac8631e6451d31a9 (diff)
parent1ea88a8689a461638fef31e01e62fffc63ac5b79 (diff)
downloadrust-ea52be482ab4945fda63cb65b6a198309a041e3c.tar.gz
rust-ea52be482ab4945fda63cb65b6a198309a041e3c.zip
Auto merge of #63635 - oli-obk:default-slice-dangles, r=eddyb
Do not generate allocations for zero sized allocations

Alternative to https://github.com/rust-lang/rust/issues/62487

r? @eddyb

There are other places where we could do this, too, but that would cause `static FOO: () = ();` to not have a unique address
Diffstat (limited to 'src/test/ui/consts')
-rw-r--r--src/test/ui/consts/zst_no_llvm_alloc.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/ui/consts/zst_no_llvm_alloc.rs b/src/test/ui/consts/zst_no_llvm_alloc.rs
new file mode 100644
index 00000000000..5d779355400
--- /dev/null
+++ b/src/test/ui/consts/zst_no_llvm_alloc.rs
@@ -0,0 +1,19 @@
+// run-pass
+
+#[repr(align(4))]
+struct Foo;
+
+static FOO: Foo = Foo;
+
+fn main() {
+    let x: &'static () = &();
+    assert_eq!(x as *const () as usize, 1);
+    let x: &'static Foo = &Foo;
+    assert_eq!(x as *const Foo as usize, 4);
+
+    // statics must have a unique address
+    assert_ne!(&FOO as *const Foo as usize, 4);
+
+    assert_eq!(<Vec<i32>>::new().as_ptr(), <&[i32]>::default().as_ptr());
+    assert_eq!(<Box<[i32]>>::default().as_ptr(), (&[]).as_ptr());
+}