@@ -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
@@ -570,13 +579,19 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Term<'tcx> {
570579 self ,
571580 folder : & mut F ,
572581 ) -> Result < Self , F :: Error > {
573- Ok ( self . unpack ( ) . try_fold_with ( folder) ?. pack ( ) )
582+ match self . unpack ( ) {
583+ ty:: TermKind :: Ty ( ty) => ty. try_fold_with ( folder) . map ( Into :: into) ,
584+ ty:: TermKind :: Const ( ct) => ct. try_fold_with ( folder) . map ( Into :: into) ,
585+ }
574586 }
575587}
576588
577589impl < ' tcx > TypeVisitable < TyCtxt < ' tcx > > for Term < ' tcx > {
578590 fn visit_with < V : TypeVisitor < TyCtxt < ' tcx > > > ( & self , visitor : & mut V ) -> V :: Result {
579- self . unpack ( ) . visit_with ( visitor)
591+ match self . unpack ( ) {
592+ ty:: TermKind :: Ty ( ty) => ty. visit_with ( visitor) ,
593+ ty:: TermKind :: Const ( ct) => ct. visit_with ( visitor) ,
594+ }
580595 }
581596}
582597
@@ -654,13 +669,7 @@ const TAG_MASK: usize = 0b11;
654669const TYPE_TAG : usize = 0b00 ;
655670const CONST_TAG : usize = 0b01 ;
656671
657- #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash , TyEncodable , TyDecodable ) ]
658- #[ derive( HashStable , TypeFoldable , TypeVisitable ) ]
659- pub enum TermKind < ' tcx > {
660- Ty ( Ty < ' tcx > ) ,
661- Const ( Const < ' tcx > ) ,
662- }
663-
672+ #[ extension( pub trait TermKindPackExt <' tcx>) ]
664673impl < ' tcx > TermKind < ' tcx > {
665674 #[ inline]
666675 fn pack ( self ) -> Term < ' tcx > {
0 commit comments