-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #63635 - oli-obk:default-slice-dangles, r=eddyb
Do not generate allocations for zero sized allocations Alternative to #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
- Loading branch information
Showing
2 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} |