@@ -46,10 +46,7 @@ pub struct GenericArgList {
46
46
impl GenericArgList {
47
47
pub fn coloncolon_token ( & self ) -> Option < SyntaxToken > { support:: token ( & self . syntax , T ! [ :: ] ) }
48
48
pub fn l_angle_token ( & self ) -> Option < SyntaxToken > { support:: token ( & self . syntax , T ! [ <] ) }
49
- pub fn type_args ( & self ) -> AstChildren < TypeArg > { support:: children ( & self . syntax ) }
50
- pub fn lifetime_args ( & self ) -> AstChildren < LifetimeArg > { support:: children ( & self . syntax ) }
51
- pub fn assoc_type_args ( & self ) -> AstChildren < AssocTypeArg > { support:: children ( & self . syntax ) }
52
- pub fn const_args ( & self ) -> AstChildren < ConstArg > { support:: children ( & self . syntax ) }
49
+ pub fn generic_args ( & self ) -> AstChildren < GenericArg > { support:: children ( & self . syntax ) }
53
50
pub fn r_angle_token ( & self ) -> Option < SyntaxToken > { support:: token ( & self . syntax , T ! [ >] ) }
54
51
}
55
52
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
@@ -86,15 +83,6 @@ impl TypeArg {
86
83
pub fn ty ( & self ) -> Option < Type > { support:: child ( & self . syntax ) }
87
84
}
88
85
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
89
- pub struct LifetimeArg {
90
- pub ( crate ) syntax : SyntaxNode ,
91
- }
92
- impl LifetimeArg {
93
- pub fn lifetime_token ( & self ) -> Option < SyntaxToken > {
94
- support:: token ( & self . syntax , T ! [ lifetime] )
95
- }
96
- }
97
- #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
98
86
pub struct AssocTypeArg {
99
87
pub ( crate ) syntax : SyntaxNode ,
100
88
}
@@ -105,6 +93,15 @@ impl AssocTypeArg {
105
93
pub fn ty ( & self ) -> Option < Type > { support:: child ( & self . syntax ) }
106
94
}
107
95
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
96
+ pub struct LifetimeArg {
97
+ pub ( crate ) syntax : SyntaxNode ,
98
+ }
99
+ impl LifetimeArg {
100
+ pub fn lifetime_token ( & self ) -> Option < SyntaxToken > {
101
+ support:: token ( & self . syntax , T ! [ lifetime] )
102
+ }
103
+ }
104
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
108
105
pub struct ConstArg {
109
106
pub ( crate ) syntax : SyntaxNode ,
110
107
}
@@ -1272,6 +1269,13 @@ impl MacroStmts {
1272
1269
pub fn expr ( & self ) -> Option < Expr > { support:: child ( & self . syntax ) }
1273
1270
}
1274
1271
#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1272
+ pub enum GenericArg {
1273
+ TypeArg ( TypeArg ) ,
1274
+ AssocTypeArg ( AssocTypeArg ) ,
1275
+ LifetimeArg ( LifetimeArg ) ,
1276
+ ConstArg ( ConstArg ) ,
1277
+ }
1278
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
1275
1279
pub enum Type {
1276
1280
ArrayType ( ArrayType ) ,
1277
1281
DynTraitType ( DynTraitType ) ,
@@ -1489,8 +1493,8 @@ impl AstNode for TypeArg {
1489
1493
}
1490
1494
fn syntax ( & self ) -> & SyntaxNode { & self . syntax }
1491
1495
}
1492
- impl AstNode for LifetimeArg {
1493
- fn can_cast ( kind : SyntaxKind ) -> bool { kind == LIFETIME_ARG }
1496
+ impl AstNode for AssocTypeArg {
1497
+ fn can_cast ( kind : SyntaxKind ) -> bool { kind == ASSOC_TYPE_ARG }
1494
1498
fn cast ( syntax : SyntaxNode ) -> Option < Self > {
1495
1499
if Self :: can_cast ( syntax. kind ( ) ) {
1496
1500
Some ( Self { syntax } )
@@ -1500,8 +1504,8 @@ impl AstNode for LifetimeArg {
1500
1504
}
1501
1505
fn syntax ( & self ) -> & SyntaxNode { & self . syntax }
1502
1506
}
1503
- impl AstNode for AssocTypeArg {
1504
- fn can_cast ( kind : SyntaxKind ) -> bool { kind == ASSOC_TYPE_ARG }
1507
+ impl AstNode for LifetimeArg {
1508
+ fn can_cast ( kind : SyntaxKind ) -> bool { kind == LIFETIME_ARG }
1505
1509
fn cast ( syntax : SyntaxNode ) -> Option < Self > {
1506
1510
if Self :: can_cast ( syntax. kind ( ) ) {
1507
1511
Some ( Self { syntax } )
@@ -2765,6 +2769,44 @@ impl AstNode for MacroStmts {
2765
2769
}
2766
2770
fn syntax ( & self ) -> & SyntaxNode { & self . syntax }
2767
2771
}
2772
+ impl From < TypeArg > for GenericArg {
2773
+ fn from ( node : TypeArg ) -> GenericArg { GenericArg :: TypeArg ( node) }
2774
+ }
2775
+ impl From < AssocTypeArg > for GenericArg {
2776
+ fn from ( node : AssocTypeArg ) -> GenericArg { GenericArg :: AssocTypeArg ( node) }
2777
+ }
2778
+ impl From < LifetimeArg > for GenericArg {
2779
+ fn from ( node : LifetimeArg ) -> GenericArg { GenericArg :: LifetimeArg ( node) }
2780
+ }
2781
+ impl From < ConstArg > for GenericArg {
2782
+ fn from ( node : ConstArg ) -> GenericArg { GenericArg :: ConstArg ( node) }
2783
+ }
2784
+ impl AstNode for GenericArg {
2785
+ fn can_cast ( kind : SyntaxKind ) -> bool {
2786
+ match kind {
2787
+ TYPE_ARG | ASSOC_TYPE_ARG | LIFETIME_ARG | CONST_ARG => true ,
2788
+ _ => false ,
2789
+ }
2790
+ }
2791
+ fn cast ( syntax : SyntaxNode ) -> Option < Self > {
2792
+ let res = match syntax. kind ( ) {
2793
+ TYPE_ARG => GenericArg :: TypeArg ( TypeArg { syntax } ) ,
2794
+ ASSOC_TYPE_ARG => GenericArg :: AssocTypeArg ( AssocTypeArg { syntax } ) ,
2795
+ LIFETIME_ARG => GenericArg :: LifetimeArg ( LifetimeArg { syntax } ) ,
2796
+ CONST_ARG => GenericArg :: ConstArg ( ConstArg { syntax } ) ,
2797
+ _ => return None ,
2798
+ } ;
2799
+ Some ( res)
2800
+ }
2801
+ fn syntax ( & self ) -> & SyntaxNode {
2802
+ match self {
2803
+ GenericArg :: TypeArg ( it) => & it. syntax ,
2804
+ GenericArg :: AssocTypeArg ( it) => & it. syntax ,
2805
+ GenericArg :: LifetimeArg ( it) => & it. syntax ,
2806
+ GenericArg :: ConstArg ( it) => & it. syntax ,
2807
+ }
2808
+ }
2809
+ }
2768
2810
impl From < ArrayType > for Type {
2769
2811
fn from ( node : ArrayType ) -> Type { Type :: ArrayType ( node) }
2770
2812
}
@@ -3380,6 +3422,11 @@ impl From<Item> for Stmt {
3380
3422
impl From < LetStmt > for Stmt {
3381
3423
fn from ( node : LetStmt ) -> Stmt { Stmt :: LetStmt ( node) }
3382
3424
}
3425
+ impl std:: fmt:: Display for GenericArg {
3426
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
3427
+ std:: fmt:: Display :: fmt ( self . syntax ( ) , f)
3428
+ }
3429
+ }
3383
3430
impl std:: fmt:: Display for Type {
3384
3431
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
3385
3432
std:: fmt:: Display :: fmt ( self . syntax ( ) , f)
@@ -3470,12 +3517,12 @@ impl std::fmt::Display for TypeArg {
3470
3517
std:: fmt:: Display :: fmt ( self . syntax ( ) , f)
3471
3518
}
3472
3519
}
3473
- impl std:: fmt:: Display for LifetimeArg {
3520
+ impl std:: fmt:: Display for AssocTypeArg {
3474
3521
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
3475
3522
std:: fmt:: Display :: fmt ( self . syntax ( ) , f)
3476
3523
}
3477
3524
}
3478
- impl std:: fmt:: Display for AssocTypeArg {
3525
+ impl std:: fmt:: Display for LifetimeArg {
3479
3526
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
3480
3527
std:: fmt:: Display :: fmt ( self . syntax ( ) , f)
3481
3528
}
0 commit comments