@@ -401,7 +401,7 @@ impl<'tcx> Ty<'tcx> {
401401 /// The more specific methods will often optimize their creation.
402402 #[ allow( rustc:: usage_of_ty_tykind) ]
403403 #[ inline]
404- pub fn new ( tcx : TyCtxt < ' tcx > , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
404+ fn new ( tcx : TyCtxt < ' tcx > , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
405405 tcx. mk_ty_from_kind ( st)
406406 }
407407
@@ -613,6 +613,41 @@ impl<'tcx> Ty<'tcx> {
613613 #[ inline]
614614 pub fn new_adt ( tcx : TyCtxt < ' tcx > , def : AdtDef < ' tcx > , args : GenericArgsRef < ' tcx > ) -> Ty < ' tcx > {
615615 tcx. debug_assert_args_compatible ( def. did ( ) , args) ;
616+ if cfg ! ( debug_assertions) {
617+ match tcx. def_kind ( def. did ( ) ) {
618+ DefKind :: Struct | DefKind :: Union | DefKind :: Enum => { }
619+ DefKind :: Mod
620+ | DefKind :: Variant
621+ | DefKind :: Trait
622+ | DefKind :: TyAlias
623+ | DefKind :: ForeignTy
624+ | DefKind :: TraitAlias
625+ | DefKind :: AssocTy
626+ | DefKind :: TyParam
627+ | DefKind :: Fn
628+ | DefKind :: Const
629+ | DefKind :: ConstParam
630+ | DefKind :: Static { .. }
631+ | DefKind :: Ctor ( ..)
632+ | DefKind :: AssocFn
633+ | DefKind :: AssocConst
634+ | DefKind :: Macro ( ..)
635+ | DefKind :: ExternCrate
636+ | DefKind :: Use
637+ | DefKind :: ForeignMod
638+ | DefKind :: AnonConst
639+ | DefKind :: InlineConst
640+ | DefKind :: OpaqueTy
641+ | DefKind :: Field
642+ | DefKind :: LifetimeParam
643+ | DefKind :: GlobalAsm
644+ | DefKind :: Impl { .. }
645+ | DefKind :: Closure
646+ | DefKind :: SyntheticCoroutineBody => {
647+ bug ! ( "not an adt: {def:?} ({:?})" , tcx. def_kind( def. did( ) ) )
648+ }
649+ }
650+ }
616651 Ty :: new ( tcx, Adt ( def, args) )
617652 }
618653
@@ -772,7 +807,7 @@ impl<'tcx> Ty<'tcx> {
772807 }
773808 }
774809 } ) ;
775- Ty :: new ( tcx, Adt ( adt_def, args) )
810+ Ty :: new_adt ( tcx, adt_def, args)
776811 }
777812
778813 #[ inline]
0 commit comments