@@ -217,6 +217,15 @@ impl fmt::Display for ValidityRequirement {
217217 }
218218}
219219
220+ #[ derive( Copy , Clone , Debug , HashStable , TyEncodable , TyDecodable ) ]
221+ pub enum SimdLayoutError {
222+ /// The vector has 0 lanes.
223+ ZeroLength ,
224+ /// The vector has more lanes than supported or permitted by
225+ /// #[rustc_simd_monomorphize_lane_limit].
226+ TooManyLanes ( u64 ) ,
227+ }
228+
220229#[ derive( Copy , Clone , Debug , HashStable , TyEncodable , TyDecodable ) ]
221230pub enum LayoutError < ' tcx > {
222231 /// A type doesn't have a sensible layout.
@@ -229,9 +238,8 @@ pub enum LayoutError<'tcx> {
229238 Unknown ( Ty < ' tcx > ) ,
230239 /// The size of a type exceeds [`TargetDataLayout::obj_size_bound`].
231240 SizeOverflow ( Ty < ' tcx > ) ,
232- /// The size of a SIMD type exceeds either the max SIMD size, or the limit
233- /// configured by #[rustc_simd_monomorphize_lane_limit].
234- OversizedSimd ( Ty < ' tcx > , u64 ) ,
241+ /// A SIMD vector has invalid layout, such as zero-length or too many lanes.
242+ InvalidSimd { ty : Ty < ' tcx > , kind : SimdLayoutError } ,
235243 /// The layout can vary due to a generic parameter.
236244 ///
237245 /// Unlike `Unknown`, this variant is a "soft" error and indicates that the layout
@@ -259,7 +267,10 @@ impl<'tcx> LayoutError<'tcx> {
259267 match self {
260268 Unknown ( _) => middle_layout_unknown,
261269 SizeOverflow ( _) => middle_layout_size_overflow,
262- OversizedSimd ( _, _) => middle_layout_oversized_simd,
270+ InvalidSimd { kind : SimdLayoutError :: TooManyLanes ( _) , .. } => {
271+ middle_layout_simd_too_many
272+ }
273+ InvalidSimd { kind : SimdLayoutError :: ZeroLength , .. } => middle_layout_simd_zero_length,
263274 TooGeneric ( _) => middle_layout_too_generic,
264275 NormalizationFailure ( _, _) => middle_layout_normalization_failure,
265276 Cycle ( _) => middle_layout_cycle,
@@ -274,7 +285,10 @@ impl<'tcx> LayoutError<'tcx> {
274285 match self {
275286 Unknown ( ty) => E :: Unknown { ty } ,
276287 SizeOverflow ( ty) => E :: Overflow { ty } ,
277- OversizedSimd ( ty, max_lanes) => E :: OversizedSimd { ty, max_lanes } ,
288+ InvalidSimd { ty, kind : SimdLayoutError :: TooManyLanes ( max_lanes) } => {
289+ E :: SimdTooManyLanes { ty, max_lanes }
290+ }
291+ InvalidSimd { ty, kind : SimdLayoutError :: ZeroLength } => E :: SimdZeroLength { ty } ,
278292 TooGeneric ( ty) => E :: TooGeneric { ty } ,
279293 NormalizationFailure ( ty, e) => {
280294 E :: NormalizationFailure { ty, failure_ty : e. get_type_for_failure ( ) }
@@ -297,9 +311,12 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
297311 LayoutError :: SizeOverflow ( ty) => {
298312 write ! ( f, "values of the type `{ty}` are too big for the target architecture" )
299313 }
300- LayoutError :: OversizedSimd ( ty, max_lanes) => {
314+ LayoutError :: InvalidSimd { ty, kind : SimdLayoutError :: TooManyLanes ( max_lanes) } => {
301315 write ! ( f, "the SIMD type `{ty}` has more elements than the limit {max_lanes}" )
302316 }
317+ LayoutError :: InvalidSimd { ty, kind : SimdLayoutError :: ZeroLength } => {
318+ write ! ( f, "the SIMD type `{ty}` has zero elements" )
319+ }
303320 LayoutError :: NormalizationFailure ( t, e) => write ! (
304321 f,
305322 "unable to determine layout for `{}` because `{}` cannot be normalized" ,
@@ -381,7 +398,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
381398 e @ LayoutError :: Cycle ( _)
382399 | e @ LayoutError :: Unknown ( _)
383400 | e @ LayoutError :: SizeOverflow ( _)
384- | e @ LayoutError :: OversizedSimd ( _ , _ )
401+ | e @ LayoutError :: InvalidSimd { .. }
385402 | e @ LayoutError :: NormalizationFailure ( ..)
386403 | e @ LayoutError :: ReferencesError ( _) ,
387404 ) => return Err ( e) ,
0 commit comments