Skip to content

Commit e482701

Browse files
Assert def-kind is correct for alias types
1 parent f1b1ed7 commit e482701

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use rustc_type_ir::WithCachedTypeInfo;
7171
use rustc_type_ir::{CollectAndApply, DynKind, Interner, TypeFlags};
7272

7373
use std::any::Any;
74+
use std::assert_matches::debug_assert_matches;
7475
use std::borrow::Borrow;
7576
use std::cmp::Ordering;
7677
use std::fmt;
@@ -2049,6 +2050,12 @@ impl<'tcx> TyCtxt<'tcx> {
20492050

20502051
#[inline]
20512052
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
2053+
debug_assert_matches!(
2054+
(kind, self.def_kind(alias_ty.def_id)),
2055+
(ty::Opaque, DefKind::OpaqueTy)
2056+
| (ty::Projection, DefKind::AssocTy | DefKind::AssocConst)
2057+
| (ty::Opaque | ty::Projection, DefKind::ImplTraitPlaceholder)
2058+
);
20522059
self.mk_ty_from_kind(Alias(kind, alias_ty))
20532060
}
20542061

0 commit comments

Comments
 (0)