@@ -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.
@@ -323,13 +321,25 @@ fn layout_of_uncached<'tcx>(
323321 if count. has_aliases ( ) {
324322 count = tcx. normalize_erasing_regions ( cx. typing_env , count) ;
325323 if count. has_aliases ( ) {
326- return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
324+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
327325 }
328326 }
329327
330- let count = count
331- . try_to_target_usize ( tcx)
332- . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
328+ let count = match count. kind ( ) {
329+ ty:: ConstKind :: Value ( ..) => count
330+ . try_to_target_usize ( tcx)
331+ . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?,
332+ ty:: ConstKind :: Error ( guar) => {
333+ return Err ( error ( cx, LayoutError :: ReferencesError ( guar) ) ) ;
334+ }
335+ _ => {
336+ if !count. has_param ( ) {
337+ bug ! ( "no generic type found in count of array type: {ty:?}" ) ;
338+ }
339+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
340+ }
341+ } ;
342+
333343 let element = cx. layout_of ( element) ?;
334344 let size = element
335345 . size
@@ -687,6 +697,9 @@ fn layout_of_uncached<'tcx>(
687697
688698 // Types with no meaningful known layout.
689699 ty:: Alias ( ..) => {
700+ if ty. has_param ( ) {
701+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
702+ }
690703 // NOTE(eddyb) `layout_of` query should've normalized these away,
691704 // if that was possible, so there's no reason to try again here.
692705 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
@@ -696,7 +709,11 @@ fn layout_of_uncached<'tcx>(
696709 bug ! ( "Layout::compute: unexpected type `{}`" , ty)
697710 }
698711
699- ty:: Placeholder ( ..) | ty:: Param ( _) => {
712+ ty:: Param ( _) => {
713+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
714+ }
715+
716+ ty:: Placeholder ( ..) => {
700717 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
701718 }
702719 } )
0 commit comments