1
Fork 0

Rollup merge of #109151 - compiler-errors:debug-assert-alias, r=WaffleLapkin

Assert def-kind is correct for alias types

Make sure we're not constructing alias types for the wrong def-kind, at least for debug cases 😅
This commit is contained in:
Matthias Krüger 2023-03-16 08:57:06 +01:00 committed by GitHub
commit 9d5d447421
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 20 deletions

View file

@ -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;
@ -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)
| (ty::Opaque | ty::Projection, DefKind::ImplTraitPlaceholder)
);
self.mk_ty_from_kind(Alias(kind, alias_ty))
}