Skip to content

Commit

Permalink
Add test case for unsizing with niche
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser authored and Mark-Simulacrum committed Jun 24, 2023
1 parent f667eeb commit f8052fc
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/ui/layout/issue-112048-unsizing-niche.rs
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)
);
}

0 comments on commit f8052fc

Please sign in to comment.