1
Fork 0

Pull out logic from #111131, plus some new logic in EvalCtxt::normalize_opaque_type

Co-authored-by: lcnr <rust@lcnr.de>
This commit is contained in:
Michael Goulet 2023-05-09 18:56:43 +00:00
parent 7664dfe433
commit 4d80b8090c
13 changed files with 122 additions and 43 deletions

View file

@ -996,17 +996,11 @@ impl<'tcx> Term<'tcx> {
}
}
/// This function returns the inner `AliasTy` if this term is a projection.
///
/// FIXME: rename `AliasTy` to `AliasTerm` and make sure we correctly
/// deal with constants.
pub fn to_projection_term(&self, tcx: TyCtxt<'tcx>) -> Option<AliasTy<'tcx>> {
/// This function returns the inner `AliasTy` for a `ty::Alias` or `ConstKind::Unevaluated`.
pub fn to_alias_ty(&self, tcx: TyCtxt<'tcx>) -> Option<AliasTy<'tcx>> {
match self.unpack() {
TermKind::Ty(ty) => match ty.kind() {
ty::Alias(kind, alias_ty) => match kind {
AliasKind::Projection | AliasKind::Inherent => Some(*alias_ty),
AliasKind::Opaque => None,
},
TermKind::Ty(ty) => match *ty.kind() {
ty::Alias(_kind, alias_ty) => Some(alias_ty),
_ => None,
},
TermKind::Const(ct) => match ct.kind() {