@@ -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,32 @@ 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 :: 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) ) ) ;
327327 }
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+ } ;
329345
330- let count = count
331- . try_to_target_usize ( tcx)
332- . ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
333346 let element = cx. layout_of ( element) ?;
334347 let size = element
335348 . size
@@ -687,6 +700,9 @@ fn layout_of_uncached<'tcx>(
687700
688701 // Types with no meaningful known layout.
689702 ty:: Alias ( ..) => {
703+ if ty. has_param ( ) {
704+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
705+ }
690706 // NOTE(eddyb) `layout_of` query should've normalized these away,
691707 // if that was possible, so there's no reason to try again here.
692708 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
@@ -696,7 +712,11 @@ fn layout_of_uncached<'tcx>(
696712 bug ! ( "Layout::compute: unexpected type `{}`" , ty)
697713 }
698714
699- ty:: Placeholder ( ..) | ty:: Param ( _) => {
715+ ty:: Param ( _) => {
716+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
717+ }
718+
719+ ty:: Placeholder ( ..) => {
700720 return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
701721 }
702722 } )
0 commit comments