@@ -7,7 +7,7 @@ use rustc_middle::bug;
77use rustc_middle:: ty:: { self , Article , FloatTy , IntTy , Ty , TyCtxt , TypeVisitableExt , UintTy } ;
88use rustc_session:: lint;
99use rustc_span:: def_id:: LocalDefId ;
10- use rustc_span:: { Span , Symbol , sym} ;
10+ use rustc_span:: { ErrorGuaranteed , Span , Symbol , sym} ;
1111use rustc_target:: asm:: {
1212 InlineAsmReg , InlineAsmRegClass , InlineAsmRegOrRegClass , InlineAsmType , ModifierInfo ,
1313} ;
@@ -27,6 +27,7 @@ enum NonAsmTypeReason<'tcx> {
2727 InvalidElement ( DefId , Ty < ' tcx > ) ,
2828 NotSizedPtr ( Ty < ' tcx > ) ,
2929 EmptySIMDArray ( Ty < ' tcx > ) ,
30+ Tainted ( ErrorGuaranteed ) ,
3031}
3132
3233impl < ' a , ' tcx > InlineAsmCtxt < ' a , ' tcx > {
@@ -93,6 +94,14 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
9394 }
9495 }
9596 ty:: Adt ( adt, args) if adt. repr ( ) . simd ( ) => {
97+ if !adt. is_struct ( ) {
98+ let guar = self . fcx . dcx ( ) . span_delayed_bug (
99+ span,
100+ format ! ( "repr(simd) should only be used on structs, got {}" , adt. descr( ) ) ,
101+ ) ;
102+ return Err ( NonAsmTypeReason :: Tainted ( guar) ) ;
103+ }
104+
96105 let fields = & adt. non_enum_variant ( ) . fields ;
97106 if fields. is_empty ( ) {
98107 return Err ( NonAsmTypeReason :: EmptySIMDArray ( ty) ) ;
@@ -234,6 +243,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
234243 let msg = format ! ( "use of empty SIMD vector `{ty}`" ) ;
235244 self . fcx . dcx ( ) . struct_span_err ( expr. span , msg) . emit ( ) ;
236245 }
246+ NonAsmTypeReason :: Tainted ( _error_guard) => {
247+ // An error has already been reported.
248+ }
237249 }
238250 return None ;
239251 }
0 commit comments