@@ -214,38 +214,62 @@ impl TyKind {
214
214
if let TyKind :: RigidTy ( inner) = self { Some ( inner) } else { None }
215
215
}
216
216
217
+ #[ inline]
217
218
pub fn is_unit ( & self ) -> bool {
218
219
matches ! ( self , TyKind :: RigidTy ( RigidTy :: Tuple ( data) ) if data. is_empty( ) )
219
220
}
220
221
222
+ #[ inline]
221
223
pub fn is_bool ( & self ) -> bool {
222
224
matches ! ( self , TyKind :: RigidTy ( RigidTy :: Bool ) )
223
225
}
224
226
227
+ #[ inline]
228
+ pub fn is_char ( & self ) -> bool {
229
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Char ) )
230
+ }
231
+
232
+ #[ inline]
225
233
pub fn is_trait ( & self ) -> bool {
226
234
matches ! ( self , TyKind :: RigidTy ( RigidTy :: Dynamic ( _, _, DynKind :: Dyn ) ) )
227
235
}
228
236
237
+ #[ inline]
229
238
pub fn is_enum ( & self ) -> bool {
230
239
matches ! ( self , TyKind :: RigidTy ( RigidTy :: Adt ( def, _) ) if def. kind( ) == AdtKind :: Enum )
231
240
}
232
241
242
+ #[ inline]
233
243
pub fn is_struct ( & self ) -> bool {
234
244
matches ! ( self , TyKind :: RigidTy ( RigidTy :: Adt ( def, _) ) if def. kind( ) == AdtKind :: Struct )
235
245
}
236
246
247
+ #[ inline]
237
248
pub fn is_union ( & self ) -> bool {
238
249
matches ! ( self , TyKind :: RigidTy ( RigidTy :: Adt ( def, _) ) if def. kind( ) == AdtKind :: Union )
239
250
}
240
251
252
+ #[ inline]
253
+ pub fn is_adt ( & self ) -> bool {
254
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Adt ( ..) ) )
255
+ }
256
+
257
+ #[ inline]
258
+ pub fn is_ref ( & self ) -> bool {
259
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Ref ( ..) ) )
260
+ }
261
+
262
+ #[ inline]
241
263
pub fn is_fn ( & self ) -> bool {
242
264
matches ! ( self , TyKind :: RigidTy ( RigidTy :: FnDef ( ..) ) )
243
265
}
244
266
267
+ #[ inline]
245
268
pub fn is_fn_ptr ( & self ) -> bool {
246
269
matches ! ( self , TyKind :: RigidTy ( RigidTy :: FnPtr ( ..) ) )
247
270
}
248
271
272
+ #[ inline]
249
273
pub fn is_primitive ( & self ) -> bool {
250
274
matches ! (
251
275
self ,
@@ -259,6 +283,84 @@ impl TyKind {
259
283
)
260
284
}
261
285
286
+ #[ inline]
287
+ pub fn is_float ( & self ) -> bool {
288
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Float ( _) ) )
289
+ }
290
+
291
+ #[ inline]
292
+ pub fn is_integral ( & self ) -> bool {
293
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Int ( _) | RigidTy :: Uint ( _) ) )
294
+ }
295
+
296
+ #[ inline]
297
+ pub fn is_numeric ( & self ) -> bool {
298
+ self . is_integral ( ) || self . is_float ( )
299
+ }
300
+
301
+ #[ inline]
302
+ pub fn is_signed ( & self ) -> bool {
303
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Int ( _) ) )
304
+ }
305
+
306
+ #[ inline]
307
+ pub fn is_str ( & self ) -> bool {
308
+ * self == TyKind :: RigidTy ( RigidTy :: Str )
309
+ }
310
+
311
+ #[ inline]
312
+ pub fn is_slice ( & self ) -> bool {
313
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Slice ( _) ) )
314
+ }
315
+
316
+ #[ inline]
317
+ pub fn is_array ( & self ) -> bool {
318
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Array ( ..) ) )
319
+ }
320
+
321
+ #[ inline]
322
+ pub fn is_mutable_ptr ( & self ) -> bool {
323
+ matches ! (
324
+ self ,
325
+ TyKind :: RigidTy ( RigidTy :: RawPtr ( _, Mutability :: Mut ) )
326
+ | TyKind :: RigidTy ( RigidTy :: Ref ( _, _, Mutability :: Mut ) )
327
+ )
328
+ }
329
+
330
+ #[ inline]
331
+ pub fn is_raw_ptr ( & self ) -> bool {
332
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: RawPtr ( ..) ) )
333
+ }
334
+
335
+ /// Tests if this is any kind of primitive pointer type (reference, raw pointer, fn pointer).
336
+ #[ inline]
337
+ pub fn is_any_ptr ( & self ) -> bool {
338
+ self . is_ref ( ) || self . is_raw_ptr ( ) || self . is_fn_ptr ( )
339
+ }
340
+
341
+ #[ inline]
342
+ pub fn is_coroutine ( & self ) -> bool {
343
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Coroutine ( ..) ) )
344
+ }
345
+
346
+ #[ inline]
347
+ pub fn is_closure ( & self ) -> bool {
348
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Closure ( ..) ) )
349
+ }
350
+
351
+ #[ inline]
352
+ pub fn is_box ( & self ) -> bool {
353
+ match self {
354
+ TyKind :: RigidTy ( RigidTy :: Adt ( def, _) ) => def. is_box ( ) ,
355
+ _ => false ,
356
+ }
357
+ }
358
+
359
+ #[ inline]
360
+ pub fn is_simd ( & self ) -> bool {
361
+ matches ! ( self , TyKind :: RigidTy ( RigidTy :: Adt ( def, _) ) if def. is_simd( ) )
362
+ }
363
+
262
364
pub fn trait_principal ( & self ) -> Option < Binder < ExistentialTraitRef > > {
263
365
if let TyKind :: RigidTy ( RigidTy :: Dynamic ( predicates, _, _) ) = self {
264
366
if let Some ( Binder { value : ExistentialPredicate :: Trait ( trait_ref) , bound_vars } ) =
@@ -300,12 +402,12 @@ impl TyKind {
300
402
}
301
403
}
302
404
303
- /// Get the function signature for function like types (Fn, FnPtr, Closure, Coroutine)
304
- /// FIXME(closure)
405
+ /// Get the function signature for function like types (Fn, FnPtr, and Closure)
305
406
pub fn fn_sig ( & self ) -> Option < PolyFnSig > {
306
407
match self {
307
408
TyKind :: RigidTy ( RigidTy :: FnDef ( def, args) ) => Some ( with ( |cx| cx. fn_sig ( * def, args) ) ) ,
308
409
TyKind :: RigidTy ( RigidTy :: FnPtr ( sig) ) => Some ( sig. clone ( ) ) ,
410
+ TyKind :: RigidTy ( RigidTy :: Closure ( _def, args) ) => Some ( with ( |cx| cx. closure_sig ( args) ) ) ,
309
411
_ => None ,
310
412
}
311
413
}
@@ -481,6 +583,10 @@ impl AdtDef {
481
583
with ( |cx| cx. adt_is_box ( * self ) )
482
584
}
483
585
586
+ pub fn is_simd ( & self ) -> bool {
587
+ with ( |cx| cx. adt_is_simd ( * self ) )
588
+ }
589
+
484
590
/// The number of variants in this ADT.
485
591
pub fn num_variants ( & self ) -> usize {
486
592
with ( |cx| cx. adt_variants_len ( * self ) )
@@ -738,13 +844,24 @@ pub enum Abi {
738
844
RiscvInterruptS ,
739
845
}
740
846
847
+ /// A binder represents a possibly generic type and its bound vars.
741
848
#[ derive( Clone , Debug , Eq , PartialEq ) ]
742
849
pub struct Binder < T > {
743
850
pub value : T ,
744
851
pub bound_vars : Vec < BoundVariableKind > ,
745
852
}
746
853
747
854
impl < T > Binder < T > {
855
+ /// Create a new binder with the given bound vars.
856
+ pub fn bind_with_vars ( value : T , bound_vars : Vec < BoundVariableKind > ) -> Self {
857
+ Binder { value, bound_vars }
858
+ }
859
+
860
+ /// Create a new binder with no bounded variable.
861
+ pub fn dummy ( value : T ) -> Self {
862
+ Binder { value, bound_vars : vec ! [ ] }
863
+ }
864
+
748
865
pub fn skip_binder ( self ) -> T {
749
866
self . value
750
867
}
0 commit comments