Skip to content

Commit

Permalink
Assert def-kind is correct for alias types
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 14, 2023
1 parent f1b1ed7 commit e482701
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use rustc_type_ir::WithCachedTypeInfo;
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;
Expand Down Expand Up @@ -2049,6 +2050,12 @@ impl<'tcx> TyCtxt<'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))
}

Expand Down

0 comments on commit e482701

Please sign in to comment.