Skip to content

Commit 984db78

Browse files
committed
Hide niches in SIMD types, too
1 parent 4239155 commit 984db78

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
10921092
hide_niches(a);
10931093
hide_niches(b);
10941094
}
1095-
Abi::Vector { element, count: _ } => {
1096-
// Until we support types other than floats and integers in SIMD,
1097-
// `element` must already be a full for its range, so there's nothing to
1098-
// do here.
1099-
assert!(element.is_always_valid(dl));
1100-
}
1095+
Abi::Vector { element, count: _ } => hide_niches(element),
11011096
Abi::Aggregate { sized: _ } => {}
11021097
}
11031098
st.largest_niche = None;

src/test/ui/layout/unsafe-cell-hides-niche.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
// run-pass
77

8+
#![feature(repr_simd)]
9+
810
use std::cell::{UnsafeCell, RefCell, Cell};
911
use std::mem::size_of;
1012
use std::num::NonZeroU32 as N32;
@@ -47,4 +49,10 @@ fn main() {
4749
trait Trait {}
4850
assert_eq!(size_of::< UnsafeCell<&dyn Trait> >(), 16);
4951
assert_eq!(size_of::<Option<UnsafeCell<&dyn Trait>>>(), 24); // (✗ niche opt)
52+
53+
#[repr(simd)]
54+
pub struct Vec4<T>([T; 4]);
55+
56+
assert_eq!(size_of::< UnsafeCell<Vec4<N32>> >(), 16);
57+
assert_eq!(size_of::<Option<UnsafeCell<Vec4<N32>>>>(), 32); // (✗ niche opt)
5058
}

0 commit comments

Comments
 (0)