Skip to content

Commit 7a667d2

Browse files
author
Lukas Markeffsky
committed
remove unreachable cases
`ty::Placeholder` is used by the trait solver and computing its layout was necessary, because the `PointerLike` trait used to be automatically implemented for all types with pointer-like layout. Nowadays, `PointerLike` requires user-written impls and the trait solver no longer computes any layouts, so this can be removed. Unevaluated constants that aren't generic should have caused a const eval error earlier during normalization.
1 parent 802b7ab commit 7a667d2

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

Diff for: compiler/rustc_ty_utils/src/layout.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,12 @@ fn extract_const_value<'tcx>(
155155
ty::ConstKind::Error(guar) => {
156156
return Err(error(cx, LayoutError::ReferencesError(guar)));
157157
}
158-
ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) => {
158+
ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) => {
159159
if !const_.has_param() {
160-
bug!("no generic type found in the type: {ty:?}");
160+
bug!("failed to normalize const, but it is not generic: {const_:?}");
161161
}
162162
return Err(error(cx, LayoutError::TooGeneric(ty)));
163163
}
164-
ty::ConstKind::Unevaluated(_) => {
165-
if !const_.has_param() {
166-
return Err(error(cx, LayoutError::Unknown(ty)));
167-
} else {
168-
return Err(error(cx, LayoutError::TooGeneric(ty)));
169-
}
170-
}
171164
ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => {
172165
bug!("unexpected type: {ty:?}");
173166
}
@@ -728,17 +721,17 @@ fn layout_of_uncached<'tcx>(
728721
return Err(error(cx, LayoutError::Unknown(ty)));
729722
}
730723

731-
ty::Bound(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => {
732-
bug!("Layout::compute: unexpected type `{}`", ty)
724+
ty::Placeholder(..)
725+
| ty::Bound(..)
726+
| ty::CoroutineWitness(..)
727+
| ty::Infer(_)
728+
| ty::Error(_) => {
729+
bug!("layout_of: unexpected type `{ty}`")
733730
}
734731

735732
ty::Param(_) => {
736733
return Err(error(cx, LayoutError::TooGeneric(ty)));
737734
}
738-
739-
ty::Placeholder(..) => {
740-
return Err(error(cx, LayoutError::Unknown(ty)));
741-
}
742735
})
743736
}
744737

0 commit comments

Comments
 (0)