@@ -141,25 +141,25 @@ fn univariant_uninterned<'tcx>(
141
141
}
142
142
143
143
fn extract_const_value < ' tcx > (
144
- const_ : ty:: Const < ' tcx > ,
145
- ty : Ty < ' tcx > ,
146
144
cx : & LayoutCx < ' tcx > ,
145
+ ty : Ty < ' tcx > ,
146
+ ct : ty:: Const < ' tcx > ,
147
147
) -> Result < ty:: Value < ' tcx > , & ' tcx LayoutError < ' tcx > > {
148
- match const_ . kind ( ) {
148
+ match ct . kind ( ) {
149
149
ty:: ConstKind :: Value ( cv) => Ok ( cv) ,
150
150
ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Expr ( _) | ty:: ConstKind :: Unevaluated ( _) => {
151
- if !const_ . has_param ( ) {
152
- bug ! ( "failed to normalize const, but it is not generic: {const_ :?}" ) ;
151
+ if !ct . has_param ( ) {
152
+ bug ! ( "failed to normalize const, but it is not generic: {ct :?}" ) ;
153
153
}
154
- return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
154
+ Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) )
155
155
}
156
156
ty:: ConstKind :: Infer ( _)
157
157
| ty:: ConstKind :: Bound ( ..)
158
158
| ty:: ConstKind :: Placeholder ( _)
159
159
| ty:: ConstKind :: Error ( _) => {
160
160
// `ty::ConstKind::Error` is handled at the top of `layout_of_uncached`
161
161
// (via `ty.error_reported()`).
162
- bug ! ( "layout_of: unexpected const: {const_ :?}" ) ;
162
+ bug ! ( "layout_of: unexpected const: {ct :?}" ) ;
163
163
}
164
164
}
165
165
}
@@ -199,12 +199,12 @@ fn layout_of_uncached<'tcx>(
199
199
& mut layout. backend_repr
200
200
{
201
201
if let Some ( start) = start {
202
- scalar. valid_range_mut ( ) . start = extract_const_value ( start , ty, cx ) ?
202
+ scalar. valid_range_mut ( ) . start = extract_const_value ( cx , ty, start ) ?
203
203
. try_to_bits ( tcx, cx. typing_env )
204
204
. ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
205
205
}
206
206
if let Some ( end) = end {
207
- let mut end = extract_const_value ( end , ty, cx ) ?
207
+ let mut end = extract_const_value ( cx , ty, end ) ?
208
208
. try_to_bits ( tcx, cx. typing_env )
209
209
. ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
210
210
if !include_end {
@@ -338,7 +338,7 @@ fn layout_of_uncached<'tcx>(
338
338
339
339
// Arrays and slices.
340
340
ty:: Array ( element, count) => {
341
- let count = extract_const_value ( count , ty, cx ) ?
341
+ let count = extract_const_value ( cx , ty, count ) ?
342
342
. try_to_target_usize ( tcx)
343
343
. ok_or_else ( || error ( cx, LayoutError :: Unknown ( ty) ) ) ?;
344
344
@@ -690,13 +690,21 @@ fn layout_of_uncached<'tcx>(
690
690
}
691
691
692
692
// Types with no meaningful known layout.
693
+ ty:: Param ( _) => {
694
+ return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
695
+ }
696
+
693
697
ty:: Alias ( ..) => {
694
- if ty. has_param ( ) {
695
- return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
696
- }
697
698
// NOTE(eddyb) `layout_of` query should've normalized these away,
698
699
// if that was possible, so there's no reason to try again here.
699
- return Err ( error ( cx, LayoutError :: Unknown ( ty) ) ) ;
700
+ let err = if ty. has_param ( ) {
701
+ LayoutError :: TooGeneric ( ty)
702
+ } else {
703
+ // This is only reachable with unsatisfiable predicates. For example, if we have
704
+ // `u8: Iterator`, then we can't compute the layout of `<u8 as Iterator>::Item`.
705
+ LayoutError :: Unknown ( ty)
706
+ } ;
707
+ return Err ( error ( cx, err) ) ;
700
708
}
701
709
702
710
ty:: Placeholder ( ..)
@@ -707,10 +715,6 @@ fn layout_of_uncached<'tcx>(
707
715
// `ty::Error` is handled at the top of this function.
708
716
bug ! ( "layout_of: unexpected type `{ty}`" )
709
717
}
710
-
711
- ty:: Param ( _) => {
712
- return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
713
- }
714
718
} )
715
719
}
716
720
0 commit comments