Skip to content

Commit

Permalink
remove unreachable cases
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Lukas Markeffsky committed Feb 18, 2025
1 parent 802b7ab commit 7a667d2
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,12 @@ fn extract_const_value<'tcx>(
ty::ConstKind::Error(guar) => {
return Err(error(cx, LayoutError::ReferencesError(guar)));
}
ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) => {
ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) => {
if !const_.has_param() {
bug!("no generic type found in the type: {ty:?}");
bug!("failed to normalize const, but it is not generic: {const_:?}");
}
return Err(error(cx, LayoutError::TooGeneric(ty)));
}
ty::ConstKind::Unevaluated(_) => {
if !const_.has_param() {
return Err(error(cx, LayoutError::Unknown(ty)));
} else {
return Err(error(cx, LayoutError::TooGeneric(ty)));
}
}
ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) => {
bug!("unexpected type: {ty:?}");
}
Expand Down Expand Up @@ -728,17 +721,17 @@ fn layout_of_uncached<'tcx>(
return Err(error(cx, LayoutError::Unknown(ty)));
}

ty::Bound(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => {
bug!("Layout::compute: unexpected type `{}`", ty)
ty::Placeholder(..)
| ty::Bound(..)
| ty::CoroutineWitness(..)
| ty::Infer(_)
| ty::Error(_) => {
bug!("layout_of: unexpected type `{ty}`")
}

ty::Param(_) => {
return Err(error(cx, LayoutError::TooGeneric(ty)));
}

ty::Placeholder(..) => {
return Err(error(cx, LayoutError::Unknown(ty)));
}
})
}

Expand Down

0 comments on commit 7a667d2

Please sign in to comment.