@@ -152,17 +152,19 @@ fn extract_const_value<'tcx>(
152
152
) -> Result < ty:: Value < ' tcx > , & ' tcx LayoutError < ' tcx > > {
153
153
match const_. kind ( ) {
154
154
ty:: ConstKind :: Value ( cv) => Ok ( cv) ,
155
- ty:: ConstKind :: Error ( guar) => {
156
- return Err ( error ( cx, LayoutError :: ReferencesError ( guar) ) ) ;
157
- }
158
155
ty:: ConstKind :: Param ( _) | ty:: ConstKind :: Expr ( _) | ty:: ConstKind :: Unevaluated ( _) => {
159
156
if !const_. has_param ( ) {
160
157
bug ! ( "failed to normalize const, but it is not generic: {const_:?}" ) ;
161
158
}
162
159
return Err ( error ( cx, LayoutError :: TooGeneric ( ty) ) ) ;
163
160
}
164
- ty:: ConstKind :: Infer ( _) | ty:: ConstKind :: Bound ( ..) | ty:: ConstKind :: Placeholder ( _) => {
165
- bug ! ( "unexpected type: {ty:?}" ) ;
161
+ ty:: ConstKind :: Infer ( _)
162
+ | ty:: ConstKind :: Bound ( ..)
163
+ | ty:: ConstKind :: Placeholder ( _)
164
+ | ty:: ConstKind :: Error ( _) => {
165
+ // `ty::ConstKind::Error` is handled at the top of `layout_of_uncached`
166
+ // (via `ty.error_reported()`).
167
+ bug ! ( "layout_of: unexpected const: {const_:?}" ) ;
166
168
}
167
169
}
168
170
}
@@ -267,16 +269,11 @@ fn layout_of_uncached<'tcx>(
267
269
data_ptr. valid_range_mut ( ) . start = 1 ;
268
270
}
269
271
270
- let pointee = tcx. normalize_erasing_regions ( cx. typing_env , pointee) ;
271
272
if pointee. is_sized ( tcx, cx. typing_env ) {
272
273
return Ok ( tcx. mk_layout ( LayoutData :: scalar ( cx, data_ptr) ) ) ;
273
274
}
274
275
275
- let metadata = if let Some ( metadata_def_id) = tcx. lang_items ( ) . metadata_type ( )
276
- // Projection eagerly bails out when the pointee references errors,
277
- // fall back to structurally deducing metadata.
278
- && !pointee. references_error ( )
279
- {
276
+ let metadata = if let Some ( metadata_def_id) = tcx. lang_items ( ) . metadata_type ( ) {
280
277
let pointee_metadata = Ty :: new_projection ( tcx, metadata_def_id, [ pointee] ) ;
281
278
let metadata_ty =
282
279
match tcx. try_normalize_erasing_regions ( cx. typing_env , pointee_metadata) {
@@ -726,6 +723,7 @@ fn layout_of_uncached<'tcx>(
726
723
| ty:: CoroutineWitness ( ..)
727
724
| ty:: Infer ( _)
728
725
| ty:: Error ( _) => {
726
+ // `ty::Error` is handled at the top of this function.
729
727
bug ! ( "layout_of: unexpected type `{ty}`" )
730
728
}
731
729
0 commit comments