-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for unsizing with niche
- Loading branch information
1 parent
3003d05
commit b982f3a
Showing
1 changed file
with
30 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// run-pass | ||
|
||
// Check that unsizing does not change which field is considered for niche layout. | ||
|
||
#![feature(offset_of)] | ||
#![allow(dead_code)] | ||
|
||
#[derive(Clone)] | ||
struct WideptrField<T: ?Sized> { | ||
first: usize, | ||
second: usize, | ||
niche: NicheAtEnd, | ||
tail: T, | ||
} | ||
|
||
#[derive(Clone)] | ||
#[repr(C)] | ||
struct NicheAtEnd { | ||
arr: [u8; 7], | ||
b: bool, | ||
} | ||
|
||
type Tail = [bool; 8]; | ||
|
||
fn main() { | ||
assert_eq!( | ||
core::mem::offset_of!(WideptrField<Tail>, niche), | ||
core::mem::offset_of!(WideptrField<dyn Send>, niche) | ||
); | ||
} |