@@ -17,6 +17,9 @@ use rustc_target::abi::*;
1717use std:: fmt:: Debug ;
1818use std:: iter;
1919
20+ use crate :: errors:: {
21+ MultipleArrayFieldsSimdType , NonPrimitiveSimdType , OversizedSimdType , ZeroLengthSimdType ,
22+ } ;
2023use crate :: layout_sanity_check:: sanity_check_layout;
2124
2225pub fn provide ( providers : & mut ty:: query:: Providers ) {
@@ -294,6 +297,8 @@ fn layout_of_uncached<'tcx>(
294297 return Err ( LayoutError :: Unknown ( ty) ) ;
295298 }
296299
300+ let fields = & def. non_enum_variant ( ) . fields ;
301+
297302 // Supported SIMD vectors are homogeneous ADTs with at least one field:
298303 //
299304 // * #[repr(simd)] struct S(T, T, T, T);
@@ -304,18 +309,22 @@ fn layout_of_uncached<'tcx>(
304309
305310 // SIMD vectors with zero fields are not supported.
306311 // (should be caught by typeck)
307- if def . non_enum_variant ( ) . fields . is_empty ( ) {
308- tcx. sess . fatal ( & format ! ( "monomorphising SIMD type `{}` of zero length" , ty ) ) ;
312+ if fields. is_empty ( ) {
313+ tcx. sess . emit_fatal ( ZeroLengthSimdType { ty } )
309314 }
310315
311316 // Type of the first ADT field:
312- let f0_ty = def . non_enum_variant ( ) . fields [ FieldIdx :: from_u32 ( 0 ) ] . ty ( tcx, substs) ;
317+ let f0_ty = fields[ FieldIdx :: from_u32 ( 0 ) ] . ty ( tcx, substs) ;
313318
314319 // Heterogeneous SIMD vectors are not supported:
315320 // (should be caught by typeck)
316- for fi in & def . non_enum_variant ( ) . fields {
321+ for fi in fields {
317322 if fi. ty ( tcx, substs) != f0_ty {
318- tcx. sess . fatal ( & format ! ( "monomorphising heterogeneous SIMD type `{}`" , ty) ) ;
323+ tcx. sess . delay_span_bug (
324+ DUMMY_SP ,
325+ "#[repr(simd)] was applied to an ADT with hetrogeneous field type" ,
326+ ) ;
327+ return Err ( LayoutError :: Unknown ( ty) ) ;
319328 }
320329 }
321330
@@ -330,12 +339,9 @@ fn layout_of_uncached<'tcx>(
330339 // First ADT field is an array:
331340
332341 // SIMD vectors with multiple array fields are not supported:
333- // (should be caught by typeck)
342+ // Can't be caught by typeck with a generic simd type.
334343 if def. non_enum_variant ( ) . fields . len ( ) != 1 {
335- tcx. sess . fatal ( & format ! (
336- "monomorphising SIMD type `{}` with more than one array field" ,
337- ty
338- ) ) ;
344+ tcx. sess . emit_fatal ( MultipleArrayFieldsSimdType { ty } ) ;
339345 }
340346
341347 // Extract the number of elements from the layout of the array field:
@@ -355,24 +361,17 @@ fn layout_of_uncached<'tcx>(
355361 //
356362 // Can't be caught in typeck if the array length is generic.
357363 if e_len == 0 {
358- tcx. sess . fatal ( & format ! ( "monomorphising SIMD type `{}` of zero length" , ty ) ) ;
364+ tcx. sess . emit_fatal ( ZeroLengthSimdType { ty } ) ;
359365 } else if e_len > MAX_SIMD_LANES {
360- tcx. sess . fatal ( & format ! (
361- "monomorphising SIMD type `{}` of length greater than {}" ,
362- ty, MAX_SIMD_LANES ,
363- ) ) ;
366+ tcx. sess . emit_fatal ( OversizedSimdType { ty, max_lanes : MAX_SIMD_LANES } ) ;
364367 }
365368
366369 // Compute the ABI of the element type:
367370 let e_ly = cx. layout_of ( e_ty) ?;
368371 let Abi :: Scalar ( e_abi) = e_ly. abi else {
369372 // This error isn't caught in typeck, e.g., if
370373 // the element type of the vector is generic.
371- tcx. sess . fatal ( & format ! (
372- "monomorphising SIMD type `{}` with a non-primitive-scalar \
373- (integer/float/pointer) element type `{}`",
374- ty, e_ty
375- ) )
374+ tcx. sess . emit_fatal ( NonPrimitiveSimdType { ty, e_ty } ) ;
376375 } ;
377376
378377 // Compute the size and alignment of the vector:
0 commit comments