File tree 3 files changed +14
-11
lines changed
3 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -645,19 +645,22 @@ impl Type {
645
645
}
646
646
647
647
/// If this type is a class template specialization, return its number of
648
- /// template arguments. Otherwise, return -1.
649
- pub fn num_template_args ( & self ) -> c_int {
650
- unsafe {
651
- clang_Type_getNumTemplateArguments ( self . x )
648
+ /// template arguments. Otherwise, return None.
649
+ pub fn num_template_args ( & self ) -> Option < u32 > {
650
+ let n = unsafe { clang_Type_getNumTemplateArguments ( self . x ) } ;
651
+ if n >= 0 {
652
+ Some ( n as u32 )
653
+ } else {
654
+ debug_assert_eq ! ( n, -1 ) ;
655
+ None
652
656
}
653
657
}
654
658
655
659
/// Get the type of the `i`th template argument for this template
656
660
/// specialization.
657
- pub fn template_arg_type ( & self , i : c_int ) -> Type {
658
- unsafe {
659
- Type { x : clang_Type_getTemplateArgumentAsType ( self . x , i) }
660
- }
661
+ pub fn template_arg_type ( & self , i : u32 ) -> Type {
662
+ let n = i as c_int ;
663
+ Type { x : unsafe { clang_Type_getTemplateArgumentAsType ( self . x , n) } }
661
664
}
662
665
663
666
/// Given that this type is a pointer type, return the type that it points
Original file line number Diff line number Diff line change @@ -492,8 +492,8 @@ impl CompInfo {
492
492
ci. template_args = match ty. num_template_args ( ) {
493
493
// In forward declarations and not specializations, etc, they are in
494
494
// the ast, we'll meet them in CXCursor_TemplateTypeParameter
495
- - 1 => vec ! [ ] ,
496
- len => {
495
+ None => vec ! [ ] ,
496
+ Some ( len) => {
497
497
let mut list = Vec :: with_capacity ( len as usize ) ;
498
498
for i in 0 ..len {
499
499
let arg_type = ty. template_arg_type ( i) ;
Original file line number Diff line number Diff line change @@ -506,7 +506,7 @@ impl Type {
506
506
TypeKind :: Function ( signature)
507
507
// Same here, with template specialisations we can safely assume
508
508
// this is a Comp(..)
509
- } else if ty. num_template_args ( ) > 0 {
509
+ } else if ty. num_template_args ( ) . unwrap_or ( 0 ) > 0 {
510
510
debug ! ( "Template specialization: {:?}" , ty) ;
511
511
let complex =
512
512
CompInfo :: from_ty ( potential_id, ty, location, ctx)
You can’t perform that action at this time.
0 commit comments