@@ -28,7 +28,7 @@ use crate::ty::fast_reject::SimplifiedType;
2828use crate :: ty:: util:: Discr ;
2929pub use adt:: * ;
3030pub use assoc:: * ;
31- pub use generic_args:: { GenericArgKind , * } ;
31+ pub use generic_args:: { GenericArgKind , TermKind , * } ;
3232pub use generics:: * ;
3333pub use intrinsic:: IntrinsicDef ;
3434use rustc_ast as ast;
@@ -48,7 +48,8 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}
4848use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LocalDefId , LocalDefIdMap } ;
4949use rustc_index:: IndexVec ;
5050use rustc_macros:: {
51- Decodable , Encodable , HashStable , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable ,
51+ extension, Decodable , Encodable , HashStable , TyDecodable , TyEncodable , TypeFoldable ,
52+ TypeVisitable ,
5253} ;
5354use rustc_query_system:: ich:: StableHashingContext ;
5455use rustc_serialize:: { Decodable , Encodable } ;
@@ -521,6 +522,14 @@ pub struct Term<'tcx> {
521522 marker : PhantomData < ( Ty < ' tcx > , Const < ' tcx > ) > ,
522523}
523524
525+ impl < ' tcx > rustc_type_ir:: inherent:: IntoKind for Term < ' tcx > {
526+ type Kind = TermKind < ' tcx > ;
527+
528+ fn kind ( self ) -> Self :: Kind {
529+ self . unpack ( )
530+ }
531+ }
532+
524533#[ cfg( parallel_compiler) ]
525534unsafe impl < ' tcx > rustc_data_structures:: sync:: DynSend for Term < ' tcx > where
526535 & ' tcx ( Ty < ' tcx > , Const < ' tcx > ) : rustc_data_structures:: sync:: DynSend
@@ -566,13 +575,19 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Term<'tcx> {
566575 self ,
567576 folder : & mut F ,
568577 ) -> Result < Self , F :: Error > {
569- Ok ( self . unpack ( ) . try_fold_with ( folder) ?. pack ( ) )
578+ match self . unpack ( ) {
579+ ty:: TermKind :: Ty ( ty) => ty. try_fold_with ( folder) . map ( Into :: into) ,
580+ ty:: TermKind :: Const ( ct) => ct. try_fold_with ( folder) . map ( Into :: into) ,
581+ }
570582 }
571583}
572584
573585impl < ' tcx > TypeVisitable < TyCtxt < ' tcx > > for Term < ' tcx > {
574586 fn visit_with < V : TypeVisitor < TyCtxt < ' tcx > > > ( & self , visitor : & mut V ) -> V :: Result {
575- self . unpack ( ) . visit_with ( visitor)
587+ match self . unpack ( ) {
588+ ty:: TermKind :: Ty ( ty) => ty. visit_with ( visitor) ,
589+ ty:: TermKind :: Const ( ct) => ct. visit_with ( visitor) ,
590+ }
576591 }
577592}
578593
@@ -650,13 +665,7 @@ const TAG_MASK: usize = 0b11;
650665const TYPE_TAG : usize = 0b00 ;
651666const CONST_TAG : usize = 0b01 ;
652667
653- #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
654- #[ derive( HashStable , TypeFoldable , TypeVisitable ) ]
655- pub enum TermKind < ' tcx > {
656- Ty ( Ty < ' tcx > ) ,
657- Const ( Const < ' tcx > ) ,
658- }
659-
668+ #[ extension( pub trait TermKindPackExt <' tcx>) ]
660669impl < ' tcx > TermKind < ' tcx > {
661670 #[ inline]
662671 fn pack ( self ) -> Term < ' tcx > {
0 commit comments