@@ -9,8 +9,8 @@ use rustc_query_system::ich::StableHashingContext;
9
9
10
10
use crate :: ty:: {
11
11
self , AliasKind , AliasTy , Const , ConstKind , Decodable , Encodable , FallibleTypeFolder ,
12
- GenericArg , Interned , Ty , TyCtxt , TyDecoder , TyEncoder , TypeFoldable , TypeVisitable ,
13
- TypeVisitor , WithCachedTypeInfo , CONST_TAG , TAG_MASK , TYPE_TAG ,
12
+ GenericArg , Interned , ParamConst , ParamTy , Ty , TyCtxt , TyDecoder , TyEncoder , TypeFoldable ,
13
+ TypeVisitable , TypeVisitor , WithCachedTypeInfo , CONST_TAG , TAG_MASK , TYPE_TAG ,
14
14
} ;
15
15
16
16
#[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -26,6 +26,12 @@ pub enum TermKind<'tcx> {
26
26
Const ( Const < ' tcx > ) ,
27
27
}
28
28
29
+ #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
30
+ pub enum ParamTerm {
31
+ Ty ( ParamTy ) ,
32
+ Const ( ParamConst ) ,
33
+ }
34
+
29
35
impl < ' tcx > Term < ' tcx > {
30
36
#[ inline]
31
37
pub fn unpack ( self ) -> TermKind < ' tcx > {
@@ -89,26 +95,6 @@ impl<'tcx> Term<'tcx> {
89
95
}
90
96
}
91
97
92
- impl < ' tcx > TermKind < ' tcx > {
93
- #[ inline]
94
- pub ( super ) fn pack ( self ) -> Term < ' tcx > {
95
- let ( tag, ptr) = match self {
96
- TermKind :: Ty ( ty) => {
97
- // Ensure we can use the tag bits.
98
- assert_eq ! ( mem:: align_of_val( & * ty. 0.0 ) & TAG_MASK , 0 ) ;
99
- ( TYPE_TAG , ty. 0 . 0 as * const WithCachedTypeInfo < ty:: TyKind < ' tcx > > as usize )
100
- }
101
- TermKind :: Const ( ct) => {
102
- // Ensure we can use the tag bits.
103
- assert_eq ! ( mem:: align_of_val( & * ct. 0.0 ) & TAG_MASK , 0 ) ;
104
- ( CONST_TAG , ct. 0 . 0 as * const ty:: ConstData < ' tcx > as usize )
105
- }
106
- } ;
107
-
108
- Term { ptr : unsafe { NonZeroUsize :: new_unchecked ( ptr | tag) } , marker : PhantomData }
109
- }
110
- }
111
-
112
98
impl fmt:: Debug for Term < ' _ > {
113
99
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
114
100
let data = if let Some ( ty) = self . ty ( ) {
@@ -167,3 +153,32 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Term<'tcx> {
167
153
res. pack ( )
168
154
}
169
155
}
156
+
157
+ impl < ' tcx > TermKind < ' tcx > {
158
+ #[ inline]
159
+ pub ( super ) fn pack ( self ) -> Term < ' tcx > {
160
+ let ( tag, ptr) = match self {
161
+ TermKind :: Ty ( ty) => {
162
+ // Ensure we can use the tag bits.
163
+ assert_eq ! ( mem:: align_of_val( & * ty. 0.0 ) & TAG_MASK , 0 ) ;
164
+ ( TYPE_TAG , ty. 0 . 0 as * const WithCachedTypeInfo < ty:: TyKind < ' tcx > > as usize )
165
+ }
166
+ TermKind :: Const ( ct) => {
167
+ // Ensure we can use the tag bits.
168
+ assert_eq ! ( mem:: align_of_val( & * ct. 0.0 ) & TAG_MASK , 0 ) ;
169
+ ( CONST_TAG , ct. 0 . 0 as * const ty:: ConstData < ' tcx > as usize )
170
+ }
171
+ } ;
172
+
173
+ Term { ptr : unsafe { NonZeroUsize :: new_unchecked ( ptr | tag) } , marker : PhantomData }
174
+ }
175
+ }
176
+
177
+ impl ParamTerm {
178
+ pub fn index ( self ) -> usize {
179
+ match self {
180
+ ParamTerm :: Ty ( ty) => ty. index as usize ,
181
+ ParamTerm :: Const ( ct) => ct. index as usize ,
182
+ }
183
+ }
184
+ }
0 commit comments