Skip to content

Commit 1d1ac3d

Browse files
author
Lukas Markeffsky
committed
remove redundant code
- we normalize before calling `layout_of_uncached`, so we don't need to normalize again later - we check for type/const errors at the top of `layout_of_uncached`, so we don't need to check again later
1 parent 7a667d2 commit 1d1ac3d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/rustc_ty_utils/src/layout.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,19 @@ fn extract_const_value<'tcx>(
152152
) -> Result<ty::Value<'tcx>, &'tcx LayoutError<'tcx>> {
153153
match const_.kind() {
154154
ty::ConstKind::Value(cv) => Ok(cv),
155-
ty::ConstKind::Error(guar) => {
156-
return Err(error(cx, LayoutError::ReferencesError(guar)));
157-
}
158155
ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) => {
159156
if !const_.has_param() {
160157
bug!("failed to normalize const, but it is not generic: {const_:?}");
161158
}
162159
return Err(error(cx, LayoutError::TooGeneric(ty)));
163160
}
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_:?}");
166168
}
167169
}
168170
}
@@ -267,16 +269,11 @@ fn layout_of_uncached<'tcx>(
267269
data_ptr.valid_range_mut().start = 1;
268270
}
269271

270-
let pointee = tcx.normalize_erasing_regions(cx.typing_env, pointee);
271272
if pointee.is_sized(tcx, cx.typing_env) {
272273
return Ok(tcx.mk_layout(LayoutData::scalar(cx, data_ptr)));
273274
}
274275

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() {
280277
let pointee_metadata = Ty::new_projection(tcx, metadata_def_id, [pointee]);
281278
let metadata_ty =
282279
match tcx.try_normalize_erasing_regions(cx.typing_env, pointee_metadata) {
@@ -726,6 +723,7 @@ fn layout_of_uncached<'tcx>(
726723
| ty::CoroutineWitness(..)
727724
| ty::Infer(_)
728725
| ty::Error(_) => {
726+
// `ty::Error` is handled at the top of this function.
729727
bug!("layout_of: unexpected type `{ty}`")
730728
}
731729

0 commit comments

Comments
 (0)