Assert def-kind is correct for alias types

This commit is contained in:
Michael Goulet 2023-03-14 22:56:20 +00:00
parent f1b1ed7e18
commit e482701998

View File

@ -71,6 +71,7 @@
use rustc_type_ir::{CollectAndApply, DynKind, Interner, TypeFlags};
use std::any::Any;
use std::assert_matches::debug_assert_matches;
use std::borrow::Borrow;
use std::cmp::Ordering;
use std::fmt;
@ -2049,6 +2050,12 @@ pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> {
#[inline]
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
debug_assert_matches!(
(kind, self.def_kind(alias_ty.def_id)),
(ty::Opaque, DefKind::OpaqueTy)
| (ty::Projection, DefKind::AssocTy | DefKind::AssocConst)
| (ty::Opaque | ty::Projection, DefKind::ImplTraitPlaceholder)
);
self.mk_ty_from_kind(Alias(kind, alias_ty))
}