@@ -401,7 +401,7 @@ impl<'tcx> Ty<'tcx> {
401
401
/// The more specific methods will often optimize their creation.
402
402
#[ allow( rustc:: usage_of_ty_tykind) ]
403
403
#[ inline]
404
- pub fn new ( tcx : TyCtxt < ' tcx > , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
404
+ fn new ( tcx : TyCtxt < ' tcx > , st : TyKind < ' tcx > ) -> Ty < ' tcx > {
405
405
tcx. mk_ty_from_kind ( st)
406
406
}
407
407
@@ -613,6 +613,41 @@ impl<'tcx> Ty<'tcx> {
613
613
#[ inline]
614
614
pub fn new_adt ( tcx : TyCtxt < ' tcx > , def : AdtDef < ' tcx > , args : GenericArgsRef < ' tcx > ) -> Ty < ' tcx > {
615
615
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
+ }
616
651
Ty :: new ( tcx, Adt ( def, args) )
617
652
}
618
653
@@ -772,7 +807,7 @@ impl<'tcx> Ty<'tcx> {
772
807
}
773
808
}
774
809
} ) ;
775
- Ty :: new ( tcx, Adt ( adt_def, args) )
810
+ Ty :: new_adt ( tcx, adt_def, args)
776
811
}
777
812
778
813
#[ inline]
0 commit comments