@@ -104,14 +104,12 @@ fn map_error<'tcx>(
104104 // This is sometimes not a compile error if there are trivially false where clauses.
105105 // See `tests/ui/layout/trivial-bounds-sized.rs` for an example.
106106 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 ! (
109109 "encountered unexpected unsized field in layout of {ty:?}: {field:#?}"
110110 ) ) ;
111- LayoutError :: ReferencesError ( guar)
112- } else {
113- LayoutError :: Unknown ( ty)
114111 }
112+ LayoutError :: Unknown ( ty)
115113 }
116114 LayoutCalculatorError :: EmptyUnion => {
117115 // This is always a compile error.
@@ -319,17 +317,30 @@ fn layout_of_uncached<'tcx>(
319317 }
320318
321319 // 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 :: Infer ( _) | ty:: ConstKind :: Bound ( ..) | ty:: ConstKind :: Placeholder ( _) => bug ! ( "unexpected count in array type: {ty:?}" ) ,
323+ ty:: ConstKind :: Value ( _, valtree) => valtree
324+ . try_to_target_usize ( tcx)
325+ . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?,
326+ ty:: ConstKind :: Error ( guar) => {
327+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar) ) ) ;
327328 }
328- }
329+ ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Expr ( _) => {
330+ if !count. has_param ( ) {
331+ bug ! ( "no generic type found in count of array type: {ty:?}" ) ;
332+ }
333+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
334+ }
335+ ty:: ConstKind :: Unevaluated ( _) => {
336+ if !count. has_param ( ) {
337+ return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
338+ } else {
339+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
340+ }
341+ }
342+ } ;
329343
330- let count = count
331- . try_to_target_usize ( tcx)
332- . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
333344 let element = cx. layout_of ( element) ?;
334345 let size = element
335346 . size
@@ -687,6 +698,9 @@ fn layout_of_uncached<'tcx>(
687698
688699 // Types with no meaningful known layout.
689700 ty:: Alias ( ..) => {
701+ if ty. has_param ( ) {
702+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
703+ }
690704 // NOTE(eddyb) `layout_of` query should've normalized these away,
691705 // if that was possible, so there's no reason to try again here.
692706 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
@@ -696,7 +710,11 @@ fn layout_of_uncached<'tcx>(
696710 bug ! ( "Layout::compute: unexpected type `{}`" , ty)
697711 }
698712
699- ty:: Placeholder ( ..) | ty:: Param ( _) => {
713+ ty:: Param ( _) => {
714+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
715+ }
716+
717+ ty:: Placeholder ( ..) => {
700718 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
701719 }
702720 } )
0 commit comments