@@ -103,30 +103,6 @@ impl<'tcx> GenericArgKind<'tcx> {
103
103
104
104
GenericArg { ptr : unsafe { NonZeroUsize :: new_unchecked ( ptr | tag) } , marker : PhantomData }
105
105
}
106
-
107
- #[ inline]
108
- pub fn as_type ( self ) -> Option < Ty < ' tcx > > {
109
- match self {
110
- GenericArgKind :: Type ( ty) => Some ( ty) ,
111
- _ => None ,
112
- }
113
- }
114
-
115
- #[ inline]
116
- pub fn as_region ( self ) -> Option < ty:: Region < ' tcx > > {
117
- match self {
118
- GenericArgKind :: Lifetime ( re) => Some ( re) ,
119
- _ => None ,
120
- }
121
- }
122
-
123
- #[ inline]
124
- pub fn as_const ( self ) -> Option < ty:: Const < ' tcx > > {
125
- match self {
126
- GenericArgKind :: Const ( ct) => Some ( ct) ,
127
- _ => None ,
128
- }
129
- }
130
106
}
131
107
132
108
impl < ' tcx > fmt:: Debug for GenericArg < ' tcx > {
@@ -204,30 +180,45 @@ impl<'tcx> GenericArg<'tcx> {
204
180
}
205
181
}
206
182
207
- /// Unpack the `GenericArg` as a region when it is known certainly to be a region.
208
- pub fn expect_region ( self ) -> ty :: Region < ' tcx > {
183
+ # [ inline ]
184
+ pub fn as_type ( self ) -> Option < Ty < ' tcx > > {
209
185
match self . unpack ( ) {
210
- GenericArgKind :: Lifetime ( lt ) => lt ,
211
- _ => bug ! ( "expected a region, but found another kind" ) ,
186
+ GenericArgKind :: Type ( ty ) => Some ( ty ) ,
187
+ _ => None ,
212
188
}
213
189
}
214
190
191
+ #[ inline]
192
+ pub fn as_region ( self ) -> Option < ty:: Region < ' tcx > > {
193
+ match self . unpack ( ) {
194
+ GenericArgKind :: Lifetime ( re) => Some ( re) ,
195
+ _ => None ,
196
+ }
197
+ }
198
+
199
+ #[ inline]
200
+ pub fn as_const ( self ) -> Option < ty:: Const < ' tcx > > {
201
+ match self . unpack ( ) {
202
+ GenericArgKind :: Const ( ct) => Some ( ct) ,
203
+ _ => None ,
204
+ }
205
+ }
206
+
207
+ /// Unpack the `GenericArg` as a region when it is known certainly to be a region.
208
+ pub fn expect_region ( self ) -> ty:: Region < ' tcx > {
209
+ self . as_region ( ) . unwrap_or_else ( || bug ! ( "expected a region, but found another kind" ) )
210
+ }
211
+
215
212
/// Unpack the `GenericArg` as a type when it is known certainly to be a type.
216
213
/// This is true in cases where `Substs` is used in places where the kinds are known
217
214
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
218
215
pub fn expect_ty ( self ) -> Ty < ' tcx > {
219
- match self . unpack ( ) {
220
- GenericArgKind :: Type ( ty) => ty,
221
- _ => bug ! ( "expected a type, but found another kind" ) ,
222
- }
216
+ self . as_type ( ) . unwrap_or_else ( || bug ! ( "expected a type, but found another kind" ) )
223
217
}
224
218
225
219
/// Unpack the `GenericArg` as a const when it is known certainly to be a const.
226
220
pub fn expect_const ( self ) -> ty:: Const < ' tcx > {
227
- match self . unpack ( ) {
228
- GenericArgKind :: Const ( c) => c,
229
- _ => bug ! ( "expected a const, but found another kind" ) ,
230
- }
221
+ self . as_const ( ) . unwrap_or_else ( || bug ! ( "expected a const, but found another kind" ) )
231
222
}
232
223
233
224
pub fn is_non_region_infer ( self ) -> bool {
@@ -403,17 +394,17 @@ impl<'tcx> InternalSubsts<'tcx> {
403
394
404
395
#[ inline]
405
396
pub fn types ( & ' tcx self ) -> impl DoubleEndedIterator < Item = Ty < ' tcx > > + ' tcx {
406
- self . iter ( ) . filter_map ( |k| k. unpack ( ) . as_type ( ) )
397
+ self . iter ( ) . filter_map ( |k| k. as_type ( ) )
407
398
}
408
399
409
400
#[ inline]
410
401
pub fn regions ( & ' tcx self ) -> impl DoubleEndedIterator < Item = ty:: Region < ' tcx > > + ' tcx {
411
- self . iter ( ) . filter_map ( |k| k. unpack ( ) . as_region ( ) )
402
+ self . iter ( ) . filter_map ( |k| k. as_region ( ) )
412
403
}
413
404
414
405
#[ inline]
415
406
pub fn consts ( & ' tcx self ) -> impl DoubleEndedIterator < Item = ty:: Const < ' tcx > > + ' tcx {
416
- self . iter ( ) . filter_map ( |k| k. unpack ( ) . as_const ( ) )
407
+ self . iter ( ) . filter_map ( |k| k. as_const ( ) )
417
408
}
418
409
419
410
#[ inline]
@@ -429,28 +420,21 @@ impl<'tcx> InternalSubsts<'tcx> {
429
420
#[ inline]
430
421
#[ track_caller]
431
422
pub fn type_at ( & self , i : usize ) -> Ty < ' tcx > {
432
- self [ i]
433
- . unpack ( )
434
- . as_type ( )
435
- . unwrap_or_else ( || bug ! ( "expected type for param #{} in {:?}" , i, self ) )
423
+ self [ i] . as_type ( ) . unwrap_or_else ( || bug ! ( "expected type for param #{} in {:?}" , i, self ) )
436
424
}
437
425
438
426
#[ inline]
439
427
#[ track_caller]
440
428
pub fn region_at ( & self , i : usize ) -> ty:: Region < ' tcx > {
441
429
self [ i]
442
- . unpack ( )
443
430
. as_region ( )
444
431
. unwrap_or_else ( || bug ! ( "expected region for param #{} in {:?}" , i, self ) )
445
432
}
446
433
447
434
#[ inline]
448
435
#[ track_caller]
449
436
pub fn const_at ( & self , i : usize ) -> ty:: Const < ' tcx > {
450
- self [ i]
451
- . unpack ( )
452
- . as_const ( )
453
- . unwrap_or_else ( || bug ! ( "expected const for param #{} in {:?}" , i, self ) )
437
+ self [ i] . as_const ( ) . unwrap_or_else ( || bug ! ( "expected const for param #{} in {:?}" , i, self ) )
454
438
}
455
439
456
440
#[ inline]
0 commit comments