@@ -28,7 +28,7 @@ use crate::ty::fast_reject::SimplifiedType;
28
28
use crate :: ty:: util:: Discr ;
29
29
pub use adt:: * ;
30
30
pub use assoc:: * ;
31
- pub use generic_args:: { GenericArgKind , * } ;
31
+ pub use generic_args:: { GenericArgKind , TermKind , * } ;
32
32
pub use generics:: * ;
33
33
pub use intrinsic:: IntrinsicDef ;
34
34
use rustc_ast as ast;
@@ -48,7 +48,8 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}
48
48
use rustc_hir:: def_id:: { CrateNum , DefId , DefIdMap , LocalDefId , LocalDefIdMap } ;
49
49
use rustc_index:: IndexVec ;
50
50
use rustc_macros:: {
51
- Decodable , Encodable , HashStable , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable ,
51
+ extension, Decodable , Encodable , HashStable , TyDecodable , TyEncodable , TypeFoldable ,
52
+ TypeVisitable ,
52
53
} ;
53
54
use rustc_query_system:: ich:: StableHashingContext ;
54
55
use rustc_serialize:: { Decodable , Encodable } ;
@@ -521,6 +522,14 @@ pub struct Term<'tcx> {
521
522
marker : PhantomData < ( Ty < ' tcx > , Const < ' tcx > ) > ,
522
523
}
523
524
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
+
524
533
#[ cfg( parallel_compiler) ]
525
534
unsafe impl < ' tcx > rustc_data_structures:: sync:: DynSend for Term < ' tcx > where
526
535
& ' tcx ( Ty < ' tcx > , Const < ' tcx > ) : rustc_data_structures:: sync:: DynSend
@@ -566,13 +575,19 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for Term<'tcx> {
566
575
self ,
567
576
folder : & mut F ,
568
577
) -> 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
+ }
570
582
}
571
583
}
572
584
573
585
impl < ' tcx > TypeVisitable < TyCtxt < ' tcx > > for Term < ' tcx > {
574
586
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
+ }
576
591
}
577
592
}
578
593
@@ -650,13 +665,7 @@ const TAG_MASK: usize = 0b11;
650
665
const TYPE_TAG : usize = 0b00 ;
651
666
const CONST_TAG : usize = 0b01 ;
652
667
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>) ]
660
669
impl < ' tcx > TermKind < ' tcx > {
661
670
#[ inline]
662
671
fn pack ( self ) -> Term < ' tcx > {
0 commit comments