@@ -1727,6 +1727,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
17271727 PrivateField { inside : Ty < ' tcx > } ,
17281728 NonExhaustive { ty : Ty < ' tcx > } ,
17291729 ReprC { ty : Ty < ' tcx > } ,
1730+ Array ,
17301731 }
17311732 struct NonTrivialFieldInfo < ' tcx > {
17321733 span : Span ,
@@ -1745,7 +1746,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
17451746 tcx. try_normalize_erasing_regions ( typing_env, Unnormalized :: new_wip ( ty) ) . unwrap_or ( ty) ;
17461747 match ty. kind ( ) {
17471748 ty:: Tuple ( list) => list. iter ( ) . try_for_each ( |t| is_trivial ( tcx, typing_env, t) ) ,
1748- ty:: Array ( ty, _) => is_trivial ( tcx, typing_env, * ty) ,
1749+ ty:: Array ( ..) => {
1750+ // Arrays are meant to be ABI-compatible with what happens in other languages,
1751+ // so we should not promise that they are "trivial".
1752+ return ControlFlow :: Break ( NonTrivialReason :: Array ) ;
1753+ }
17491754 ty:: Adt ( def, args) => {
17501755 if !def. did ( ) . is_local ( ) && !find_attr ! ( tcx, def. did( ) , RustcPubTransparent ( _) ) {
17511756 let non_exhaustive = def. is_variant_list_non_exhaustive ( )
@@ -1833,6 +1838,9 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
18331838 NonTrivialReason :: ReprC { ty } => format ! (
18341839 "this field contains `{ty}`, which is a `#[repr(C)]` type, so it is not guaranteed to be zero-sized on all targets"
18351840 ) ,
1841+ NonTrivialReason :: Array => format ! (
1842+ "this field contains an array, which might be relevant for the ABI on some targets"
1843+ ) ,
18361844 } ;
18371845 diag. span_label ( field. span , msg) ;
18381846 }
0 commit comments