@@ -104,14 +104,12 @@ fn map_error<'tcx>(
104
104
// This is sometimes not a compile error if there are trivially false where clauses.
105
105
// See `tests/ui/layout/trivial-bounds-sized.rs` for an example.
106
106
assert ! ( field. layout. is_unsized( ) , "invalid layout error {err:#?}" ) ;
107
- if !field . ty . is_sized ( cx . tcx ( ) , cx . typing_env ) {
108
- let guar = cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! (
107
+ if cx . typing_env . param_env . caller_bounds ( ) . is_empty ( ) {
108
+ cx. tcx ( ) . dcx ( ) . delayed_bug ( format ! (
109
109
"encountered unexpected unsized field in layout of {ty:?}: {field:#?}"
110
110
) ) ;
111
- LayoutError :: ReferencesError ( guar)
112
- } else {
113
- LayoutError :: Unknown ( ty)
114
111
}
112
+ LayoutError :: Unknown ( ty)
115
113
}
116
114
LayoutCalculatorError :: EmptyUnion => {
117
115
// This is always a compile error.
@@ -319,17 +317,32 @@ fn layout_of_uncached<'tcx>(
319
317
}
320
318
321
319
// Arrays and slices.
322
- ty:: Array ( element, mut count) => {
323
- if count. has_aliases ( ) {
324
- count = tcx. normalize_erasing_regions ( cx. typing_env , count) ;
325
- if count. has_aliases ( ) {
326
- return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
320
+ ty:: Array ( element, count) => {
321
+ let count = match count. kind ( ) {
322
+ ty:: ConstKind :: Value ( _, valtree) => valtree
323
+ . try_to_target_usize ( tcx)
324
+ . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?,
325
+ ty:: ConstKind :: Error ( guar) => {
326
+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar) ) ) ;
327
327
}
328
- }
328
+ ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Expr ( _) => {
329
+ if !count. has_param ( ) {
330
+ bug ! ( "no generic type found in count of array type: {ty:?}" ) ;
331
+ }
332
+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
333
+ }
334
+ ty:: ConstKind :: Unevaluated ( _) => {
335
+ if !count. has_param ( ) {
336
+ return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
337
+ } else {
338
+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
339
+ }
340
+ }
341
+ ty:: ConstKind :: Infer ( _)
342
+ | ty:: ConstKind :: Bound ( ..)
343
+ | ty:: ConstKind :: Placeholder ( _) => bug ! ( "unexpected count in array type: {ty:?}" ) ,
344
+ } ;
329
345
330
- let count = count
331
- . try_to_target_usize ( tcx)
332
- . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
333
346
let element = cx. layout_of ( element) ?;
334
347
let size = element
335
348
. size
@@ -687,6 +700,9 @@ fn layout_of_uncached<'tcx>(
687
700
688
701
// Types with no meaningful known layout.
689
702
ty:: Alias ( ..) => {
703
+ if ty. has_param ( ) {
704
+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
705
+ }
690
706
// NOTE(eddyb) `layout_of` query should've normalized these away,
691
707
// if that was possible, so there's no reason to try again here.
692
708
return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
@@ -696,7 +712,11 @@ fn layout_of_uncached<'tcx>(
696
712
bug ! ( "Layout::compute: unexpected type `{}`" , ty)
697
713
}
698
714
699
- ty:: Placeholder ( ..) | ty:: Param ( _) => {
715
+ ty:: Param ( _) => {
716
+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
717
+ }
718
+
719
+ ty:: Placeholder ( ..) => {
700
720
return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
701
721
}
702
722
} )
0 commit comments