aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs8
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs1251
2 files changed, 650 insertions, 609 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs
index 8d3e42f25..04746ef8f 100644
--- a/crates/ra_syntax/src/ast/edit.rs
+++ b/crates/ra_syntax/src/ast/edit.rs
@@ -237,17 +237,17 @@ impl ast::Path {
237 237
238impl ast::PathSegment { 238impl ast::PathSegment {
239 #[must_use] 239 #[must_use]
240 pub fn with_type_args(&self, type_args: ast::TypeArgList) -> ast::PathSegment { 240 pub fn with_type_args(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
241 self._with_type_args(type_args, false) 241 self._with_type_args(type_args, false)
242 } 242 }
243 243
244 #[must_use] 244 #[must_use]
245 pub fn with_turbo_fish(&self, type_args: ast::TypeArgList) -> ast::PathSegment { 245 pub fn with_turbo_fish(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
246 self._with_type_args(type_args, true) 246 self._with_type_args(type_args, true)
247 } 247 }
248 248
249 fn _with_type_args(&self, type_args: ast::TypeArgList, turbo: bool) -> ast::PathSegment { 249 fn _with_type_args(&self, type_args: ast::GenericArgList, turbo: bool) -> ast::PathSegment {
250 if let Some(old) = self.type_arg_list() { 250 if let Some(old) = self.generic_arg_list() {
251 return self.replace_children( 251 return self.replace_children(
252 single_node(old.syntax().clone()), 252 single_node(old.syntax().clone()),
253 iter::once(type_args.syntax().clone().into()), 253 iter::once(type_args.syntax().clone().into()),
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 3f075a5f8..6ce9c4adc 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -6,6 +6,116 @@ use crate::{
6 SyntaxNode, SyntaxToken, T, 6 SyntaxNode, SyntaxToken, T,
7}; 7};
8#[derive(Debug, Clone, PartialEq, Eq, Hash)] 8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct Path {
10 pub(crate) syntax: SyntaxNode,
11}
12impl Path {
13 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
14 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
15 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
16}
17#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18pub struct PathSegment {
19 pub(crate) syntax: SyntaxNode,
20}
21impl PathSegment {
22 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
23 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
24 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
25 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
26 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
27 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
28 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
29 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
30 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
31 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
32 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
33 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
34}
35#[derive(Debug, Clone, PartialEq, Eq, Hash)]
36pub struct NameRef {
37 pub(crate) syntax: SyntaxNode,
38}
39impl NameRef {
40 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
41}
42#[derive(Debug, Clone, PartialEq, Eq, Hash)]
43pub struct GenericArgList {
44 pub(crate) syntax: SyntaxNode,
45}
46impl GenericArgList {
47 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
48 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
49 pub fn generic_args(&self) -> AstChildren<GenericArg> { support::children(&self.syntax) }
50 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
51}
52#[derive(Debug, Clone, PartialEq, Eq, Hash)]
53pub struct ParamList {
54 pub(crate) syntax: SyntaxNode,
55}
56impl ParamList {
57 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
58 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
59 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
60 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
61 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
62}
63#[derive(Debug, Clone, PartialEq, Eq, Hash)]
64pub struct RetType {
65 pub(crate) syntax: SyntaxNode,
66}
67impl RetType {
68 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
69 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
70}
71#[derive(Debug, Clone, PartialEq, Eq, Hash)]
72pub struct PathType {
73 pub(crate) syntax: SyntaxNode,
74}
75impl PathType {
76 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
77}
78#[derive(Debug, Clone, PartialEq, Eq, Hash)]
79pub struct TypeArg {
80 pub(crate) syntax: SyntaxNode,
81}
82impl TypeArg {
83 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
84}
85#[derive(Debug, Clone, PartialEq, Eq, Hash)]
86pub struct AssocTypeArg {
87 pub(crate) syntax: SyntaxNode,
88}
89impl ast::TypeBoundsOwner for AssocTypeArg {}
90impl AssocTypeArg {
91 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
92 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
93 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
94}
95#[derive(Debug, Clone, PartialEq, Eq, Hash)]
96pub struct LifetimeArg {
97 pub(crate) syntax: SyntaxNode,
98}
99impl 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)]
105pub struct ConstArg {
106 pub(crate) syntax: SyntaxNode,
107}
108impl ConstArg {
109 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
110}
111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
112pub struct TypeBoundList {
113 pub(crate) syntax: SyntaxNode,
114}
115impl TypeBoundList {
116 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
117}
118#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct SourceFile { 119pub struct SourceFile {
10 pub(crate) syntax: SyntaxNode, 120 pub(crate) syntax: SyntaxNode,
11} 121}
@@ -256,13 +366,6 @@ impl ItemList {
256 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 366 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
257} 367}
258#[derive(Debug, Clone, PartialEq, Eq, Hash)] 368#[derive(Debug, Clone, PartialEq, Eq, Hash)]
259pub struct NameRef {
260 pub(crate) syntax: SyntaxNode,
261}
262impl NameRef {
263 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
264}
265#[derive(Debug, Clone, PartialEq, Eq, Hash)]
266pub struct Rename { 369pub struct Rename {
267 pub(crate) syntax: SyntaxNode, 370 pub(crate) syntax: SyntaxNode,
268} 371}
@@ -283,15 +386,6 @@ impl UseTree {
283 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) } 386 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
284} 387}
285#[derive(Debug, Clone, PartialEq, Eq, Hash)] 388#[derive(Debug, Clone, PartialEq, Eq, Hash)]
286pub struct Path {
287 pub(crate) syntax: SyntaxNode,
288}
289impl Path {
290 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
291 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
292 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
293}
294#[derive(Debug, Clone, PartialEq, Eq, Hash)]
295pub struct UseTreeList { 389pub struct UseTreeList {
296 pub(crate) syntax: SyntaxNode, 390 pub(crate) syntax: SyntaxNode,
297} 391}
@@ -317,25 +411,6 @@ impl GenericParamList {
317 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } 411 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
318} 412}
319#[derive(Debug, Clone, PartialEq, Eq, Hash)] 413#[derive(Debug, Clone, PartialEq, Eq, Hash)]
320pub struct ParamList {
321 pub(crate) syntax: SyntaxNode,
322}
323impl ParamList {
324 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
325 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
326 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
327 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
328 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
329}
330#[derive(Debug, Clone, PartialEq, Eq, Hash)]
331pub struct RetType {
332 pub(crate) syntax: SyntaxNode,
333}
334impl RetType {
335 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
336 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
337}
338#[derive(Debug, Clone, PartialEq, Eq, Hash)]
339pub struct WhereClause { 414pub struct WhereClause {
340 pub(crate) syntax: SyntaxNode, 415 pub(crate) syntax: SyntaxNode,
341} 416}
@@ -381,13 +456,6 @@ impl Param {
381 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } 456 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
382} 457}
383#[derive(Debug, Clone, PartialEq, Eq, Hash)] 458#[derive(Debug, Clone, PartialEq, Eq, Hash)]
384pub struct TypeBoundList {
385 pub(crate) syntax: SyntaxNode,
386}
387impl TypeBoundList {
388 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
389}
390#[derive(Debug, Clone, PartialEq, Eq, Hash)]
391pub struct RecordFieldList { 459pub struct RecordFieldList {
392 pub(crate) syntax: SyntaxNode, 460 pub(crate) syntax: SyntaxNode,
393} 461}
@@ -624,6 +692,19 @@ impl CastExpr {
624 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } 692 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
625} 693}
626#[derive(Debug, Clone, PartialEq, Eq, Hash)] 694#[derive(Debug, Clone, PartialEq, Eq, Hash)]
695pub struct ClosureExpr {
696 pub(crate) syntax: SyntaxNode,
697}
698impl ast::AttrsOwner for ClosureExpr {}
699impl ClosureExpr {
700 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
701 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
702 pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
703 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
704 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
705 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
706}
707#[derive(Debug, Clone, PartialEq, Eq, Hash)]
627pub struct ContinueExpr { 708pub struct ContinueExpr {
628 pub(crate) syntax: SyntaxNode, 709 pub(crate) syntax: SyntaxNode,
629} 710}
@@ -690,28 +771,6 @@ impl IndexExpr {
690 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 771 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
691} 772}
692#[derive(Debug, Clone, PartialEq, Eq, Hash)] 773#[derive(Debug, Clone, PartialEq, Eq, Hash)]
693pub struct Label {
694 pub(crate) syntax: SyntaxNode,
695}
696impl Label {
697 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
698 support::token(&self.syntax, T![lifetime])
699 }
700}
701#[derive(Debug, Clone, PartialEq, Eq, Hash)]
702pub struct ClosureExpr {
703 pub(crate) syntax: SyntaxNode,
704}
705impl ast::AttrsOwner for ClosureExpr {}
706impl ClosureExpr {
707 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
708 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
709 pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
710 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
711 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
712 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
713}
714#[derive(Debug, Clone, PartialEq, Eq, Hash)]
715pub struct LoopExpr { 774pub struct LoopExpr {
716 pub(crate) syntax: SyntaxNode, 775 pub(crate) syntax: SyntaxNode,
717} 776}
@@ -740,7 +799,7 @@ impl MethodCallExpr {
740 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 799 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
741 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 800 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
742 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 801 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
743 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } 802 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
744} 803}
745#[derive(Debug, Clone, PartialEq, Eq, Hash)] 804#[derive(Debug, Clone, PartialEq, Eq, Hash)]
746pub struct ParenExpr { 805pub struct ParenExpr {
@@ -835,6 +894,15 @@ impl WhileExpr {
835 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 894 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
836} 895}
837#[derive(Debug, Clone, PartialEq, Eq, Hash)] 896#[derive(Debug, Clone, PartialEq, Eq, Hash)]
897pub struct Label {
898 pub(crate) syntax: SyntaxNode,
899}
900impl Label {
901 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
902 support::token(&self.syntax, T![lifetime])
903 }
904}
905#[derive(Debug, Clone, PartialEq, Eq, Hash)]
838pub struct RecordExprFieldList { 906pub struct RecordExprFieldList {
839 pub(crate) syntax: SyntaxNode, 907 pub(crate) syntax: SyntaxNode,
840} 908}
@@ -866,19 +934,6 @@ impl ArgList {
866 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 934 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
867} 935}
868#[derive(Debug, Clone, PartialEq, Eq, Hash)] 936#[derive(Debug, Clone, PartialEq, Eq, Hash)]
869pub struct TypeArgList {
870 pub(crate) syntax: SyntaxNode,
871}
872impl TypeArgList {
873 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
874 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
875 pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) }
876 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) }
877 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) }
878 pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) }
879 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
880}
881#[derive(Debug, Clone, PartialEq, Eq, Hash)]
882pub struct Condition { 937pub struct Condition {
883 pub(crate) syntax: SyntaxNode, 938 pub(crate) syntax: SyntaxNode,
884} 939}
@@ -991,13 +1046,6 @@ impl ParenType {
991 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1046 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
992} 1047}
993#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1048#[derive(Debug, Clone, PartialEq, Eq, Hash)]
994pub struct PathType {
995 pub(crate) syntax: SyntaxNode,
996}
997impl PathType {
998 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
999}
1000#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1001pub struct PointerType { 1049pub struct PointerType {
1002 pub(crate) syntax: SyntaxNode, 1050 pub(crate) syntax: SyntaxNode,
1003} 1051}
@@ -1212,75 +1260,13 @@ impl MacroStmts {
1212 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1260 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1213} 1261}
1214#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1262#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1215pub struct PathSegment { 1263pub enum GenericArg {
1216 pub(crate) syntax: SyntaxNode, 1264 TypeArg(TypeArg),
1217} 1265 AssocTypeArg(AssocTypeArg),
1218impl PathSegment { 1266 LifetimeArg(LifetimeArg),
1219 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } 1267 ConstArg(ConstArg),
1220 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
1221 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
1222 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
1223 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
1224 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1225 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) }
1226 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
1227 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
1228 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
1229 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1230}
1231#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1232pub struct TypeArg {
1233 pub(crate) syntax: SyntaxNode,
1234}
1235impl TypeArg {
1236 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1237}
1238#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1239pub struct LifetimeArg {
1240 pub(crate) syntax: SyntaxNode,
1241}
1242impl LifetimeArg {
1243 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1244 support::token(&self.syntax, T![lifetime])
1245 }
1246}
1247#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1248pub struct AssocTypeArg {
1249 pub(crate) syntax: SyntaxNode,
1250}
1251impl ast::TypeBoundsOwner for AssocTypeArg {}
1252impl AssocTypeArg {
1253 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1254 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1255 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1256}
1257#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1258pub struct ConstArg {
1259 pub(crate) syntax: SyntaxNode,
1260}
1261impl ConstArg {
1262 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
1263 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
1264} 1268}
1265#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1269#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1266pub enum Item {
1267 Const(Const),
1268 Enum(Enum),
1269 ExternBlock(ExternBlock),
1270 ExternCrate(ExternCrate),
1271 Fn(Fn),
1272 Impl(Impl),
1273 MacroCall(MacroCall),
1274 Module(Module),
1275 Static(Static),
1276 Struct(Struct),
1277 Trait(Trait),
1278 TypeAlias(TypeAlias),
1279 Union(Union),
1280 Use(Use),
1281}
1282impl ast::AttrsOwner for Item {}
1283#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1284pub enum Type { 1270pub enum Type {
1285 ArrayType(ArrayType), 1271 ArrayType(ArrayType),
1286 DynTraitType(DynTraitType), 1272 DynTraitType(DynTraitType),
@@ -1297,29 +1283,6 @@ pub enum Type {
1297 TupleType(TupleType), 1283 TupleType(TupleType),
1298} 1284}
1299#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1285#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1300pub enum Pat {
1301 OrPat(OrPat),
1302 ParenPat(ParenPat),
1303 RefPat(RefPat),
1304 BoxPat(BoxPat),
1305 BindPat(BindPat),
1306 PlaceholderPat(PlaceholderPat),
1307 DotDotPat(DotDotPat),
1308 PathPat(PathPat),
1309 RecordPat(RecordPat),
1310 TupleStructPat(TupleStructPat),
1311 TuplePat(TuplePat),
1312 SlicePat(SlicePat),
1313 RangePat(RangePat),
1314 LiteralPat(LiteralPat),
1315 MacroPat(MacroPat),
1316}
1317#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1318pub enum FieldList {
1319 RecordFieldList(RecordFieldList),
1320 TupleFieldList(TupleFieldList),
1321}
1322#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1323pub enum Expr { 1286pub enum Expr {
1324 ArrayExpr(ArrayExpr), 1287 ArrayExpr(ArrayExpr),
1325 AwaitExpr(AwaitExpr), 1288 AwaitExpr(AwaitExpr),
@@ -1329,14 +1292,13 @@ pub enum Expr {
1329 BreakExpr(BreakExpr), 1292 BreakExpr(BreakExpr),
1330 CallExpr(CallExpr), 1293 CallExpr(CallExpr),
1331 CastExpr(CastExpr), 1294 CastExpr(CastExpr),
1295 ClosureExpr(ClosureExpr),
1332 ContinueExpr(ContinueExpr), 1296 ContinueExpr(ContinueExpr),
1333 EffectExpr(EffectExpr), 1297 EffectExpr(EffectExpr),
1334 FieldExpr(FieldExpr), 1298 FieldExpr(FieldExpr),
1335 ForExpr(ForExpr), 1299 ForExpr(ForExpr),
1336 IfExpr(IfExpr), 1300 IfExpr(IfExpr),
1337 IndexExpr(IndexExpr), 1301 IndexExpr(IndexExpr),
1338 Label(Label),
1339 ClosureExpr(ClosureExpr),
1340 Literal(Literal), 1302 Literal(Literal),
1341 LoopExpr(LoopExpr), 1303 LoopExpr(LoopExpr),
1342 MacroCall(MacroCall), 1304 MacroCall(MacroCall),
@@ -1354,6 +1316,47 @@ pub enum Expr {
1354 WhileExpr(WhileExpr), 1316 WhileExpr(WhileExpr),
1355} 1317}
1356#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1318#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1319pub enum Item {
1320 Const(Const),
1321 Enum(Enum),
1322 ExternBlock(ExternBlock),
1323 ExternCrate(ExternCrate),
1324 Fn(Fn),
1325 Impl(Impl),
1326 MacroCall(MacroCall),
1327 Module(Module),
1328 Static(Static),
1329 Struct(Struct),
1330 Trait(Trait),
1331 TypeAlias(TypeAlias),
1332 Union(Union),
1333 Use(Use),
1334}
1335impl ast::AttrsOwner for Item {}
1336#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1337pub enum Pat {
1338 OrPat(OrPat),
1339 ParenPat(ParenPat),
1340 RefPat(RefPat),
1341 BoxPat(BoxPat),
1342 BindPat(BindPat),
1343 PlaceholderPat(PlaceholderPat),
1344 DotDotPat(DotDotPat),
1345 PathPat(PathPat),
1346 RecordPat(RecordPat),
1347 TupleStructPat(TupleStructPat),
1348 TuplePat(TuplePat),
1349 SlicePat(SlicePat),
1350 RangePat(RangePat),
1351 LiteralPat(LiteralPat),
1352 MacroPat(MacroPat),
1353}
1354#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1355pub enum FieldList {
1356 RecordFieldList(RecordFieldList),
1357 TupleFieldList(TupleFieldList),
1358}
1359#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1357pub enum AdtDef { 1360pub enum AdtDef {
1358 Enum(Enum), 1361 Enum(Enum),
1359 Struct(Struct), 1362 Struct(Struct),
@@ -1393,6 +1396,138 @@ pub enum Stmt {
1393 Item(Item), 1396 Item(Item),
1394 LetStmt(LetStmt), 1397 LetStmt(LetStmt),
1395} 1398}
1399impl AstNode for Path {
1400 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
1401 fn cast(syntax: SyntaxNode) -> Option<Self> {
1402 if Self::can_cast(syntax.kind()) {
1403 Some(Self { syntax })
1404 } else {
1405 None
1406 }
1407 }
1408 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1409}
1410impl AstNode for PathSegment {
1411 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
1412 fn cast(syntax: SyntaxNode) -> Option<Self> {
1413 if Self::can_cast(syntax.kind()) {
1414 Some(Self { syntax })
1415 } else {
1416 None
1417 }
1418 }
1419 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1420}
1421impl AstNode for NameRef {
1422 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
1423 fn cast(syntax: SyntaxNode) -> Option<Self> {
1424 if Self::can_cast(syntax.kind()) {
1425 Some(Self { syntax })
1426 } else {
1427 None
1428 }
1429 }
1430 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1431}
1432impl AstNode for GenericArgList {
1433 fn can_cast(kind: SyntaxKind) -> bool { kind == GENERIC_ARG_LIST }
1434 fn cast(syntax: SyntaxNode) -> Option<Self> {
1435 if Self::can_cast(syntax.kind()) {
1436 Some(Self { syntax })
1437 } else {
1438 None
1439 }
1440 }
1441 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1442}
1443impl AstNode for ParamList {
1444 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
1445 fn cast(syntax: SyntaxNode) -> Option<Self> {
1446 if Self::can_cast(syntax.kind()) {
1447 Some(Self { syntax })
1448 } else {
1449 None
1450 }
1451 }
1452 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1453}
1454impl AstNode for RetType {
1455 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE }
1456 fn cast(syntax: SyntaxNode) -> Option<Self> {
1457 if Self::can_cast(syntax.kind()) {
1458 Some(Self { syntax })
1459 } else {
1460 None
1461 }
1462 }
1463 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1464}
1465impl AstNode for PathType {
1466 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_TYPE }
1467 fn cast(syntax: SyntaxNode) -> Option<Self> {
1468 if Self::can_cast(syntax.kind()) {
1469 Some(Self { syntax })
1470 } else {
1471 None
1472 }
1473 }
1474 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1475}
1476impl AstNode for TypeArg {
1477 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG }
1478 fn cast(syntax: SyntaxNode) -> Option<Self> {
1479 if Self::can_cast(syntax.kind()) {
1480 Some(Self { syntax })
1481 } else {
1482 None
1483 }
1484 }
1485 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1486}
1487impl AstNode for AssocTypeArg {
1488 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
1489 fn cast(syntax: SyntaxNode) -> Option<Self> {
1490 if Self::can_cast(syntax.kind()) {
1491 Some(Self { syntax })
1492 } else {
1493 None
1494 }
1495 }
1496 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1497}
1498impl AstNode for LifetimeArg {
1499 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG }
1500 fn cast(syntax: SyntaxNode) -> Option<Self> {
1501 if Self::can_cast(syntax.kind()) {
1502 Some(Self { syntax })
1503 } else {
1504 None
1505 }
1506 }
1507 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1508}
1509impl AstNode for ConstArg {
1510 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG }
1511 fn cast(syntax: SyntaxNode) -> Option<Self> {
1512 if Self::can_cast(syntax.kind()) {
1513 Some(Self { syntax })
1514 } else {
1515 None
1516 }
1517 }
1518 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1519}
1520impl AstNode for TypeBoundList {
1521 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
1522 fn cast(syntax: SyntaxNode) -> Option<Self> {
1523 if Self::can_cast(syntax.kind()) {
1524 Some(Self { syntax })
1525 } else {
1526 None
1527 }
1528 }
1529 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1530}
1396impl AstNode for SourceFile { 1531impl AstNode for SourceFile {
1397 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } 1532 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE }
1398 fn cast(syntax: SyntaxNode) -> Option<Self> { 1533 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1602,17 +1737,6 @@ impl AstNode for ItemList {
1602 } 1737 }
1603 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1738 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1604} 1739}
1605impl AstNode for NameRef {
1606 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
1607 fn cast(syntax: SyntaxNode) -> Option<Self> {
1608 if Self::can_cast(syntax.kind()) {
1609 Some(Self { syntax })
1610 } else {
1611 None
1612 }
1613 }
1614 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1615}
1616impl AstNode for Rename { 1740impl AstNode for Rename {
1617 fn can_cast(kind: SyntaxKind) -> bool { kind == RENAME } 1741 fn can_cast(kind: SyntaxKind) -> bool { kind == RENAME }
1618 fn cast(syntax: SyntaxNode) -> Option<Self> { 1742 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1635,17 +1759,6 @@ impl AstNode for UseTree {
1635 } 1759 }
1636 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1760 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1637} 1761}
1638impl AstNode for Path {
1639 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
1640 fn cast(syntax: SyntaxNode) -> Option<Self> {
1641 if Self::can_cast(syntax.kind()) {
1642 Some(Self { syntax })
1643 } else {
1644 None
1645 }
1646 }
1647 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1648}
1649impl AstNode for UseTreeList { 1762impl AstNode for UseTreeList {
1650 fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } 1763 fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST }
1651 fn cast(syntax: SyntaxNode) -> Option<Self> { 1764 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1679,28 +1792,6 @@ impl AstNode for GenericParamList {
1679 } 1792 }
1680 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1793 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1681} 1794}
1682impl AstNode for ParamList {
1683 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
1684 fn cast(syntax: SyntaxNode) -> Option<Self> {
1685 if Self::can_cast(syntax.kind()) {
1686 Some(Self { syntax })
1687 } else {
1688 None
1689 }
1690 }
1691 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1692}
1693impl AstNode for RetType {
1694 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE }
1695 fn cast(syntax: SyntaxNode) -> Option<Self> {
1696 if Self::can_cast(syntax.kind()) {
1697 Some(Self { syntax })
1698 } else {
1699 None
1700 }
1701 }
1702 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1703}
1704impl AstNode for WhereClause { 1795impl AstNode for WhereClause {
1705 fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE } 1796 fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE }
1706 fn cast(syntax: SyntaxNode) -> Option<Self> { 1797 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -1745,17 +1836,6 @@ impl AstNode for Param {
1745 } 1836 }
1746 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1837 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1747} 1838}
1748impl AstNode for TypeBoundList {
1749 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
1750 fn cast(syntax: SyntaxNode) -> Option<Self> {
1751 if Self::can_cast(syntax.kind()) {
1752 Some(Self { syntax })
1753 } else {
1754 None
1755 }
1756 }
1757 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1758}
1759impl AstNode for RecordFieldList { 1839impl AstNode for RecordFieldList {
1760 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_LIST } 1840 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_LIST }
1761 fn cast(syntax: SyntaxNode) -> Option<Self> { 1841 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2009,6 +2089,17 @@ impl AstNode for CastExpr {
2009 } 2089 }
2010 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2090 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2011} 2091}
2092impl AstNode for ClosureExpr {
2093 fn can_cast(kind: SyntaxKind) -> bool { kind == CLOSURE_EXPR }
2094 fn cast(syntax: SyntaxNode) -> Option<Self> {
2095 if Self::can_cast(syntax.kind()) {
2096 Some(Self { syntax })
2097 } else {
2098 None
2099 }
2100 }
2101 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2102}
2012impl AstNode for ContinueExpr { 2103impl AstNode for ContinueExpr {
2013 fn can_cast(kind: SyntaxKind) -> bool { kind == CONTINUE_EXPR } 2104 fn can_cast(kind: SyntaxKind) -> bool { kind == CONTINUE_EXPR }
2014 fn cast(syntax: SyntaxNode) -> Option<Self> { 2105 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2075,28 +2166,6 @@ impl AstNode for IndexExpr {
2075 } 2166 }
2076 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2167 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2077} 2168}
2078impl AstNode for Label {
2079 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL }
2080 fn cast(syntax: SyntaxNode) -> Option<Self> {
2081 if Self::can_cast(syntax.kind()) {
2082 Some(Self { syntax })
2083 } else {
2084 None
2085 }
2086 }
2087 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2088}
2089impl AstNode for ClosureExpr {
2090 fn can_cast(kind: SyntaxKind) -> bool { kind == CLOSURE_EXPR }
2091 fn cast(syntax: SyntaxNode) -> Option<Self> {
2092 if Self::can_cast(syntax.kind()) {
2093 Some(Self { syntax })
2094 } else {
2095 None
2096 }
2097 }
2098 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2099}
2100impl AstNode for LoopExpr { 2169impl AstNode for LoopExpr {
2101 fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } 2170 fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR }
2102 fn cast(syntax: SyntaxNode) -> Option<Self> { 2171 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2240,8 +2309,8 @@ impl AstNode for WhileExpr {
2240 } 2309 }
2241 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2310 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2242} 2311}
2243impl AstNode for RecordExprFieldList { 2312impl AstNode for Label {
2244 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST } 2313 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL }
2245 fn cast(syntax: SyntaxNode) -> Option<Self> { 2314 fn cast(syntax: SyntaxNode) -> Option<Self> {
2246 if Self::can_cast(syntax.kind()) { 2315 if Self::can_cast(syntax.kind()) {
2247 Some(Self { syntax }) 2316 Some(Self { syntax })
@@ -2251,8 +2320,8 @@ impl AstNode for RecordExprFieldList {
2251 } 2320 }
2252 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2321 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2253} 2322}
2254impl AstNode for RecordExprField { 2323impl AstNode for RecordExprFieldList {
2255 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD } 2324 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST }
2256 fn cast(syntax: SyntaxNode) -> Option<Self> { 2325 fn cast(syntax: SyntaxNode) -> Option<Self> {
2257 if Self::can_cast(syntax.kind()) { 2326 if Self::can_cast(syntax.kind()) {
2258 Some(Self { syntax }) 2327 Some(Self { syntax })
@@ -2262,8 +2331,8 @@ impl AstNode for RecordExprField {
2262 } 2331 }
2263 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2332 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2264} 2333}
2265impl AstNode for ArgList { 2334impl AstNode for RecordExprField {
2266 fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST } 2335 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD }
2267 fn cast(syntax: SyntaxNode) -> Option<Self> { 2336 fn cast(syntax: SyntaxNode) -> Option<Self> {
2268 if Self::can_cast(syntax.kind()) { 2337 if Self::can_cast(syntax.kind()) {
2269 Some(Self { syntax }) 2338 Some(Self { syntax })
@@ -2273,8 +2342,8 @@ impl AstNode for ArgList {
2273 } 2342 }
2274 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2343 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2275} 2344}
2276impl AstNode for TypeArgList { 2345impl AstNode for ArgList {
2277 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST } 2346 fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST }
2278 fn cast(syntax: SyntaxNode) -> Option<Self> { 2347 fn cast(syntax: SyntaxNode) -> Option<Self> {
2279 if Self::can_cast(syntax.kind()) { 2348 if Self::can_cast(syntax.kind()) {
2280 Some(Self { syntax }) 2349 Some(Self { syntax })
@@ -2416,17 +2485,6 @@ impl AstNode for ParenType {
2416 } 2485 }
2417 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2486 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2418} 2487}
2419impl AstNode for PathType {
2420 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_TYPE }
2421 fn cast(syntax: SyntaxNode) -> Option<Self> {
2422 if Self::can_cast(syntax.kind()) {
2423 Some(Self { syntax })
2424 } else {
2425 None
2426 }
2427 }
2428 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2429}
2430impl AstNode for PointerType { 2488impl AstNode for PointerType {
2431 fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } 2489 fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE }
2432 fn cast(syntax: SyntaxNode) -> Option<Self> { 2490 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2691,147 +2749,41 @@ impl AstNode for MacroStmts {
2691 } 2749 }
2692 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2750 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2693} 2751}
2694impl AstNode for PathSegment { 2752impl From<TypeArg> for GenericArg {
2695 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } 2753 fn from(node: TypeArg) -> GenericArg { GenericArg::TypeArg(node) }
2696 fn cast(syntax: SyntaxNode) -> Option<Self> {
2697 if Self::can_cast(syntax.kind()) {
2698 Some(Self { syntax })
2699 } else {
2700 None
2701 }
2702 }
2703 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2704} 2754}
2705impl AstNode for TypeArg { 2755impl From<AssocTypeArg> for GenericArg {
2706 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG } 2756 fn from(node: AssocTypeArg) -> GenericArg { GenericArg::AssocTypeArg(node) }
2707 fn cast(syntax: SyntaxNode) -> Option<Self> {
2708 if Self::can_cast(syntax.kind()) {
2709 Some(Self { syntax })
2710 } else {
2711 None
2712 }
2713 }
2714 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2715}
2716impl AstNode for LifetimeArg {
2717 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG }
2718 fn cast(syntax: SyntaxNode) -> Option<Self> {
2719 if Self::can_cast(syntax.kind()) {
2720 Some(Self { syntax })
2721 } else {
2722 None
2723 }
2724 }
2725 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2726}
2727impl AstNode for AssocTypeArg {
2728 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
2729 fn cast(syntax: SyntaxNode) -> Option<Self> {
2730 if Self::can_cast(syntax.kind()) {
2731 Some(Self { syntax })
2732 } else {
2733 None
2734 }
2735 }
2736 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2737} 2757}
2738impl AstNode for ConstArg { 2758impl From<LifetimeArg> for GenericArg {
2739 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG } 2759 fn from(node: LifetimeArg) -> GenericArg { GenericArg::LifetimeArg(node) }
2740 fn cast(syntax: SyntaxNode) -> Option<Self> {
2741 if Self::can_cast(syntax.kind()) {
2742 Some(Self { syntax })
2743 } else {
2744 None
2745 }
2746 }
2747 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2748} 2760}
2749impl From<Const> for Item { 2761impl From<ConstArg> for GenericArg {
2750 fn from(node: Const) -> Item { Item::Const(node) } 2762 fn from(node: ConstArg) -> GenericArg { GenericArg::ConstArg(node) }
2751}
2752impl From<Enum> for Item {
2753 fn from(node: Enum) -> Item { Item::Enum(node) }
2754} 2763}
2755impl From<ExternBlock> for Item { 2764impl AstNode for GenericArg {
2756 fn from(node: ExternBlock) -> Item { Item::ExternBlock(node) }
2757}
2758impl From<ExternCrate> for Item {
2759 fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) }
2760}
2761impl From<Fn> for Item {
2762 fn from(node: Fn) -> Item { Item::Fn(node) }
2763}
2764impl From<Impl> for Item {
2765 fn from(node: Impl) -> Item { Item::Impl(node) }
2766}
2767impl From<MacroCall> for Item {
2768 fn from(node: MacroCall) -> Item { Item::MacroCall(node) }
2769}
2770impl From<Module> for Item {
2771 fn from(node: Module) -> Item { Item::Module(node) }
2772}
2773impl From<Static> for Item {
2774 fn from(node: Static) -> Item { Item::Static(node) }
2775}
2776impl From<Struct> for Item {
2777 fn from(node: Struct) -> Item { Item::Struct(node) }
2778}
2779impl From<Trait> for Item {
2780 fn from(node: Trait) -> Item { Item::Trait(node) }
2781}
2782impl From<TypeAlias> for Item {
2783 fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) }
2784}
2785impl From<Union> for Item {
2786 fn from(node: Union) -> Item { Item::Union(node) }
2787}
2788impl From<Use> for Item {
2789 fn from(node: Use) -> Item { Item::Use(node) }
2790}
2791impl AstNode for Item {
2792 fn can_cast(kind: SyntaxKind) -> bool { 2765 fn can_cast(kind: SyntaxKind) -> bool {
2793 match kind { 2766 match kind {
2794 CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MODULE 2767 TYPE_ARG | ASSOC_TYPE_ARG | LIFETIME_ARG | CONST_ARG => true,
2795 | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true,
2796 _ => false, 2768 _ => false,
2797 } 2769 }
2798 } 2770 }
2799 fn cast(syntax: SyntaxNode) -> Option<Self> { 2771 fn cast(syntax: SyntaxNode) -> Option<Self> {
2800 let res = match syntax.kind() { 2772 let res = match syntax.kind() {
2801 CONST => Item::Const(Const { syntax }), 2773 TYPE_ARG => GenericArg::TypeArg(TypeArg { syntax }),
2802 ENUM => Item::Enum(Enum { syntax }), 2774 ASSOC_TYPE_ARG => GenericArg::AssocTypeArg(AssocTypeArg { syntax }),
2803 EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), 2775 LIFETIME_ARG => GenericArg::LifetimeArg(LifetimeArg { syntax }),
2804 EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), 2776 CONST_ARG => GenericArg::ConstArg(ConstArg { syntax }),
2805 FN => Item::Fn(Fn { syntax }),
2806 IMPL => Item::Impl(Impl { syntax }),
2807 MACRO_CALL => Item::MacroCall(MacroCall { syntax }),
2808 MODULE => Item::Module(Module { syntax }),
2809 STATIC => Item::Static(Static { syntax }),
2810 STRUCT => Item::Struct(Struct { syntax }),
2811 TRAIT => Item::Trait(Trait { syntax }),
2812 TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }),
2813 UNION => Item::Union(Union { syntax }),
2814 USE => Item::Use(Use { syntax }),
2815 _ => return None, 2777 _ => return None,
2816 }; 2778 };
2817 Some(res) 2779 Some(res)
2818 } 2780 }
2819 fn syntax(&self) -> &SyntaxNode { 2781 fn syntax(&self) -> &SyntaxNode {
2820 match self { 2782 match self {
2821 Item::Const(it) => &it.syntax, 2783 GenericArg::TypeArg(it) => &it.syntax,
2822 Item::Enum(it) => &it.syntax, 2784 GenericArg::AssocTypeArg(it) => &it.syntax,
2823 Item::ExternBlock(it) => &it.syntax, 2785 GenericArg::LifetimeArg(it) => &it.syntax,
2824 Item::ExternCrate(it) => &it.syntax, 2786 GenericArg::ConstArg(it) => &it.syntax,
2825 Item::Fn(it) => &it.syntax,
2826 Item::Impl(it) => &it.syntax,
2827 Item::MacroCall(it) => &it.syntax,
2828 Item::Module(it) => &it.syntax,
2829 Item::Static(it) => &it.syntax,
2830 Item::Struct(it) => &it.syntax,
2831 Item::Trait(it) => &it.syntax,
2832 Item::TypeAlias(it) => &it.syntax,
2833 Item::Union(it) => &it.syntax,
2834 Item::Use(it) => &it.syntax,
2835 } 2787 }
2836 } 2788 }
2837} 2789}
@@ -2920,129 +2872,6 @@ impl AstNode for Type {
2920 } 2872 }
2921 } 2873 }
2922} 2874}
2923impl From<OrPat> for Pat {
2924 fn from(node: OrPat) -> Pat { Pat::OrPat(node) }
2925}
2926impl From<ParenPat> for Pat {
2927 fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) }
2928}
2929impl From<RefPat> for Pat {
2930 fn from(node: RefPat) -> Pat { Pat::RefPat(node) }
2931}
2932impl From<BoxPat> for Pat {
2933 fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) }
2934}
2935impl From<BindPat> for Pat {
2936 fn from(node: BindPat) -> Pat { Pat::BindPat(node) }
2937}
2938impl From<PlaceholderPat> for Pat {
2939 fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) }
2940}
2941impl From<DotDotPat> for Pat {
2942 fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) }
2943}
2944impl From<PathPat> for Pat {
2945 fn from(node: PathPat) -> Pat { Pat::PathPat(node) }
2946}
2947impl From<RecordPat> for Pat {
2948 fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) }
2949}
2950impl From<TupleStructPat> for Pat {
2951 fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) }
2952}
2953impl From<TuplePat> for Pat {
2954 fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) }
2955}
2956impl From<SlicePat> for Pat {
2957 fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) }
2958}
2959impl From<RangePat> for Pat {
2960 fn from(node: RangePat) -> Pat { Pat::RangePat(node) }
2961}
2962impl From<LiteralPat> for Pat {
2963 fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) }
2964}
2965impl From<MacroPat> for Pat {
2966 fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) }
2967}
2968impl AstNode for Pat {
2969 fn can_cast(kind: SyntaxKind) -> bool {
2970 match kind {
2971 OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT
2972 | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT
2973 | LITERAL_PAT | MACRO_PAT => true,
2974 _ => false,
2975 }
2976 }
2977 fn cast(syntax: SyntaxNode) -> Option<Self> {
2978 let res = match syntax.kind() {
2979 OR_PAT => Pat::OrPat(OrPat { syntax }),
2980 PAREN_PAT => Pat::ParenPat(ParenPat { syntax }),
2981 REF_PAT => Pat::RefPat(RefPat { syntax }),
2982 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2983 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2984 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2985 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2986 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2987 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2988 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
2989 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
2990 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
2991 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
2992 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
2993 MACRO_PAT => Pat::MacroPat(MacroPat { syntax }),
2994 _ => return None,
2995 };
2996 Some(res)
2997 }
2998 fn syntax(&self) -> &SyntaxNode {
2999 match self {
3000 Pat::OrPat(it) => &it.syntax,
3001 Pat::ParenPat(it) => &it.syntax,
3002 Pat::RefPat(it) => &it.syntax,
3003 Pat::BoxPat(it) => &it.syntax,
3004 Pat::BindPat(it) => &it.syntax,
3005 Pat::PlaceholderPat(it) => &it.syntax,
3006 Pat::DotDotPat(it) => &it.syntax,
3007 Pat::PathPat(it) => &it.syntax,
3008 Pat::RecordPat(it) => &it.syntax,
3009 Pat::TupleStructPat(it) => &it.syntax,
3010 Pat::TuplePat(it) => &it.syntax,
3011 Pat::SlicePat(it) => &it.syntax,
3012 Pat::RangePat(it) => &it.syntax,
3013 Pat::LiteralPat(it) => &it.syntax,
3014 Pat::MacroPat(it) => &it.syntax,
3015 }
3016 }
3017}
3018impl From<RecordFieldList> for FieldList {
3019 fn from(node: RecordFieldList) -> FieldList { FieldList::RecordFieldList(node) }
3020}
3021impl From<TupleFieldList> for FieldList {
3022 fn from(node: TupleFieldList) -> FieldList { FieldList::TupleFieldList(node) }
3023}
3024impl AstNode for FieldList {
3025 fn can_cast(kind: SyntaxKind) -> bool {
3026 match kind {
3027 RECORD_FIELD_LIST | TUPLE_FIELD_LIST => true,
3028 _ => false,
3029 }
3030 }
3031 fn cast(syntax: SyntaxNode) -> Option<Self> {
3032 let res = match syntax.kind() {
3033 RECORD_FIELD_LIST => FieldList::RecordFieldList(RecordFieldList { syntax }),
3034 TUPLE_FIELD_LIST => FieldList::TupleFieldList(TupleFieldList { syntax }),
3035 _ => return None,
3036 };
3037 Some(res)
3038 }
3039 fn syntax(&self) -> &SyntaxNode {
3040 match self {
3041 FieldList::RecordFieldList(it) => &it.syntax,
3042 FieldList::TupleFieldList(it) => &it.syntax,
3043 }
3044 }
3045}
3046impl From<ArrayExpr> for Expr { 2875impl From<ArrayExpr> for Expr {
3047 fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) } 2876 fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) }
3048} 2877}
@@ -3067,6 +2896,9 @@ impl From<CallExpr> for Expr {
3067impl From<CastExpr> for Expr { 2896impl From<CastExpr> for Expr {
3068 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } 2897 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) }
3069} 2898}
2899impl From<ClosureExpr> for Expr {
2900 fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) }
2901}
3070impl From<ContinueExpr> for Expr { 2902impl From<ContinueExpr> for Expr {
3071 fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } 2903 fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) }
3072} 2904}
@@ -3085,12 +2917,6 @@ impl From<IfExpr> for Expr {
3085impl From<IndexExpr> for Expr { 2917impl From<IndexExpr> for Expr {
3086 fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } 2918 fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) }
3087} 2919}
3088impl From<Label> for Expr {
3089 fn from(node: Label) -> Expr { Expr::Label(node) }
3090}
3091impl From<ClosureExpr> for Expr {
3092 fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) }
3093}
3094impl From<Literal> for Expr { 2920impl From<Literal> for Expr {
3095 fn from(node: Literal) -> Expr { Expr::Literal(node) } 2921 fn from(node: Literal) -> Expr { Expr::Literal(node) }
3096} 2922}
@@ -3140,8 +2966,8 @@ impl AstNode for Expr {
3140 fn can_cast(kind: SyntaxKind) -> bool { 2966 fn can_cast(kind: SyntaxKind) -> bool {
3141 match kind { 2967 match kind {
3142 ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR 2968 ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR
3143 | CAST_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR | IF_EXPR 2969 | CAST_EXPR | CLOSURE_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR
3144 | INDEX_EXPR | LABEL | CLOSURE_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR 2970 | IF_EXPR | INDEX_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR
3145 | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR 2971 | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR
3146 | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true, 2972 | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true,
3147 _ => false, 2973 _ => false,
@@ -3157,14 +2983,13 @@ impl AstNode for Expr {
3157 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }), 2983 BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
3158 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), 2984 CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
3159 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), 2985 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
2986 CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }),
3160 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }), 2987 CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
3161 EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }), 2988 EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }),
3162 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), 2989 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
3163 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }), 2990 FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
3164 IF_EXPR => Expr::IfExpr(IfExpr { syntax }), 2991 IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
3165 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), 2992 INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
3166 LABEL => Expr::Label(Label { syntax }),
3167 CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }),
3168 LITERAL => Expr::Literal(Literal { syntax }), 2993 LITERAL => Expr::Literal(Literal { syntax }),
3169 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }), 2994 LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
3170 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }), 2995 MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
@@ -3194,14 +3019,13 @@ impl AstNode for Expr {
3194 Expr::BreakExpr(it) => &it.syntax, 3019 Expr::BreakExpr(it) => &it.syntax,
3195 Expr::CallExpr(it) => &it.syntax, 3020 Expr::CallExpr(it) => &it.syntax,
3196 Expr::CastExpr(it) => &it.syntax, 3021 Expr::CastExpr(it) => &it.syntax,
3022 Expr::ClosureExpr(it) => &it.syntax,
3197 Expr::ContinueExpr(it) => &it.syntax, 3023 Expr::ContinueExpr(it) => &it.syntax,
3198 Expr::EffectExpr(it) => &it.syntax, 3024 Expr::EffectExpr(it) => &it.syntax,
3199 Expr::FieldExpr(it) => &it.syntax, 3025 Expr::FieldExpr(it) => &it.syntax,
3200 Expr::ForExpr(it) => &it.syntax, 3026 Expr::ForExpr(it) => &it.syntax,
3201 Expr::IfExpr(it) => &it.syntax, 3027 Expr::IfExpr(it) => &it.syntax,
3202 Expr::IndexExpr(it) => &it.syntax, 3028 Expr::IndexExpr(it) => &it.syntax,
3203 Expr::Label(it) => &it.syntax,
3204 Expr::ClosureExpr(it) => &it.syntax,
3205 Expr::Literal(it) => &it.syntax, 3029 Expr::Literal(it) => &it.syntax,
3206 Expr::LoopExpr(it) => &it.syntax, 3030 Expr::LoopExpr(it) => &it.syntax,
3207 Expr::MacroCall(it) => &it.syntax, 3031 Expr::MacroCall(it) => &it.syntax,
@@ -3220,6 +3044,218 @@ impl AstNode for Expr {
3220 } 3044 }
3221 } 3045 }
3222} 3046}
3047impl From<Const> for Item {
3048 fn from(node: Const) -> Item { Item::Const(node) }
3049}
3050impl From<Enum> for Item {
3051 fn from(node: Enum) -> Item { Item::Enum(node) }
3052}
3053impl From<ExternBlock> for Item {
3054 fn from(node: ExternBlock) -> Item { Item::ExternBlock(node) }
3055}
3056impl From<ExternCrate> for Item {
3057 fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) }
3058}
3059impl From<Fn> for Item {
3060 fn from(node: Fn) -> Item { Item::Fn(node) }
3061}
3062impl From<Impl> for Item {
3063 fn from(node: Impl) -> Item { Item::Impl(node) }
3064}
3065impl From<MacroCall> for Item {
3066 fn from(node: MacroCall) -> Item { Item::MacroCall(node) }
3067}
3068impl From<Module> for Item {
3069 fn from(node: Module) -> Item { Item::Module(node) }
3070}
3071impl From<Static> for Item {
3072 fn from(node: Static) -> Item { Item::Static(node) }
3073}
3074impl From<Struct> for Item {
3075 fn from(node: Struct) -> Item { Item::Struct(node) }
3076}
3077impl From<Trait> for Item {
3078 fn from(node: Trait) -> Item { Item::Trait(node) }
3079}
3080impl From<TypeAlias> for Item {
3081 fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) }
3082}
3083impl From<Union> for Item {
3084 fn from(node: Union) -> Item { Item::Union(node) }
3085}
3086impl From<Use> for Item {
3087 fn from(node: Use) -> Item { Item::Use(node) }
3088}
3089impl AstNode for Item {
3090 fn can_cast(kind: SyntaxKind) -> bool {
3091 match kind {
3092 CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MODULE
3093 | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true,
3094 _ => false,
3095 }
3096 }
3097 fn cast(syntax: SyntaxNode) -> Option<Self> {
3098 let res = match syntax.kind() {
3099 CONST => Item::Const(Const { syntax }),
3100 ENUM => Item::Enum(Enum { syntax }),
3101 EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }),
3102 EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }),
3103 FN => Item::Fn(Fn { syntax }),
3104 IMPL => Item::Impl(Impl { syntax }),
3105 MACRO_CALL => Item::MacroCall(MacroCall { syntax }),
3106 MODULE => Item::Module(Module { syntax }),
3107 STATIC => Item::Static(Static { syntax }),
3108 STRUCT => Item::Struct(Struct { syntax }),
3109 TRAIT => Item::Trait(Trait { syntax }),
3110 TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }),
3111 UNION => Item::Union(Union { syntax }),
3112 USE => Item::Use(Use { syntax }),
3113 _ => return None,
3114 };
3115 Some(res)
3116 }
3117 fn syntax(&self) -> &SyntaxNode {
3118 match self {
3119 Item::Const(it) => &it.syntax,
3120 Item::Enum(it) => &it.syntax,
3121 Item::ExternBlock(it) => &it.syntax,
3122 Item::ExternCrate(it) => &it.syntax,
3123 Item::Fn(it) => &it.syntax,
3124 Item::Impl(it) => &it.syntax,
3125 Item::MacroCall(it) => &it.syntax,
3126 Item::Module(it) => &it.syntax,
3127 Item::Static(it) => &it.syntax,
3128 Item::Struct(it) => &it.syntax,
3129 Item::Trait(it) => &it.syntax,
3130 Item::TypeAlias(it) => &it.syntax,
3131 Item::Union(it) => &it.syntax,
3132 Item::Use(it) => &it.syntax,
3133 }
3134 }
3135}
3136impl From<OrPat> for Pat {
3137 fn from(node: OrPat) -> Pat { Pat::OrPat(node) }
3138}
3139impl From<ParenPat> for Pat {
3140 fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) }
3141}
3142impl From<RefPat> for Pat {
3143 fn from(node: RefPat) -> Pat { Pat::RefPat(node) }
3144}
3145impl From<BoxPat> for Pat {
3146 fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) }
3147}
3148impl From<BindPat> for Pat {
3149 fn from(node: BindPat) -> Pat { Pat::BindPat(node) }
3150}
3151impl From<PlaceholderPat> for Pat {
3152 fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) }
3153}
3154impl From<DotDotPat> for Pat {
3155 fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) }
3156}
3157impl From<PathPat> for Pat {
3158 fn from(node: PathPat) -> Pat { Pat::PathPat(node) }
3159}
3160impl From<RecordPat> for Pat {
3161 fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) }
3162}
3163impl From<TupleStructPat> for Pat {
3164 fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) }
3165}
3166impl From<TuplePat> for Pat {
3167 fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) }
3168}
3169impl From<SlicePat> for Pat {
3170 fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) }
3171}
3172impl From<RangePat> for Pat {
3173 fn from(node: RangePat) -> Pat { Pat::RangePat(node) }
3174}
3175impl From<LiteralPat> for Pat {
3176 fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) }
3177}
3178impl From<MacroPat> for Pat {
3179 fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) }
3180}
3181impl AstNode for Pat {
3182 fn can_cast(kind: SyntaxKind) -> bool {
3183 match kind {
3184 OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT
3185 | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT
3186 | LITERAL_PAT | MACRO_PAT => true,
3187 _ => false,
3188 }
3189 }
3190 fn cast(syntax: SyntaxNode) -> Option<Self> {
3191 let res = match syntax.kind() {
3192 OR_PAT => Pat::OrPat(OrPat { syntax }),
3193 PAREN_PAT => Pat::ParenPat(ParenPat { syntax }),
3194 REF_PAT => Pat::RefPat(RefPat { syntax }),
3195 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
3196 BIND_PAT => Pat::BindPat(BindPat { syntax }),
3197 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
3198 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
3199 PATH_PAT => Pat::PathPat(PathPat { syntax }),
3200 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
3201 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
3202 TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }),
3203 SLICE_PAT => Pat::SlicePat(SlicePat { syntax }),
3204 RANGE_PAT => Pat::RangePat(RangePat { syntax }),
3205 LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
3206 MACRO_PAT => Pat::MacroPat(MacroPat { syntax }),
3207 _ => return None,
3208 };
3209 Some(res)
3210 }
3211 fn syntax(&self) -> &SyntaxNode {
3212 match self {
3213 Pat::OrPat(it) => &it.syntax,
3214 Pat::ParenPat(it) => &it.syntax,
3215 Pat::RefPat(it) => &it.syntax,
3216 Pat::BoxPat(it) => &it.syntax,
3217 Pat::BindPat(it) => &it.syntax,
3218 Pat::PlaceholderPat(it) => &it.syntax,
3219 Pat::DotDotPat(it) => &it.syntax,
3220 Pat::PathPat(it) => &it.syntax,
3221 Pat::RecordPat(it) => &it.syntax,
3222 Pat::TupleStructPat(it) => &it.syntax,
3223 Pat::TuplePat(it) => &it.syntax,
3224 Pat::SlicePat(it) => &it.syntax,
3225 Pat::RangePat(it) => &it.syntax,
3226 Pat::LiteralPat(it) => &it.syntax,
3227 Pat::MacroPat(it) => &it.syntax,
3228 }
3229 }
3230}
3231impl From<RecordFieldList> for FieldList {
3232 fn from(node: RecordFieldList) -> FieldList { FieldList::RecordFieldList(node) }
3233}
3234impl From<TupleFieldList> for FieldList {
3235 fn from(node: TupleFieldList) -> FieldList { FieldList::TupleFieldList(node) }
3236}
3237impl AstNode for FieldList {
3238 fn can_cast(kind: SyntaxKind) -> bool {
3239 match kind {
3240 RECORD_FIELD_LIST | TUPLE_FIELD_LIST => true,
3241 _ => false,
3242 }
3243 }
3244 fn cast(syntax: SyntaxNode) -> Option<Self> {
3245 let res = match syntax.kind() {
3246 RECORD_FIELD_LIST => FieldList::RecordFieldList(RecordFieldList { syntax }),
3247 TUPLE_FIELD_LIST => FieldList::TupleFieldList(TupleFieldList { syntax }),
3248 _ => return None,
3249 };
3250 Some(res)
3251 }
3252 fn syntax(&self) -> &SyntaxNode {
3253 match self {
3254 FieldList::RecordFieldList(it) => &it.syntax,
3255 FieldList::TupleFieldList(it) => &it.syntax,
3256 }
3257 }
3258}
3223impl From<Enum> for AdtDef { 3259impl From<Enum> for AdtDef {
3224 fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) } 3260 fn from(node: Enum) -> AdtDef { AdtDef::Enum(node) }
3225} 3261}
@@ -3366,7 +3402,7 @@ impl From<Item> for Stmt {
3366impl From<LetStmt> for Stmt { 3402impl From<LetStmt> for Stmt {
3367 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } 3403 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
3368} 3404}
3369impl std::fmt::Display for Item { 3405impl std::fmt::Display for GenericArg {
3370 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3406 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3371 std::fmt::Display::fmt(self.syntax(), f) 3407 std::fmt::Display::fmt(self.syntax(), f)
3372 } 3408 }
@@ -3376,17 +3412,22 @@ impl std::fmt::Display for Type {
3376 std::fmt::Display::fmt(self.syntax(), f) 3412 std::fmt::Display::fmt(self.syntax(), f)
3377 } 3413 }
3378} 3414}
3379impl std::fmt::Display for Pat { 3415impl std::fmt::Display for Expr {
3380 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3416 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3381 std::fmt::Display::fmt(self.syntax(), f) 3417 std::fmt::Display::fmt(self.syntax(), f)
3382 } 3418 }
3383} 3419}
3384impl std::fmt::Display for FieldList { 3420impl std::fmt::Display for Item {
3385 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3421 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3386 std::fmt::Display::fmt(self.syntax(), f) 3422 std::fmt::Display::fmt(self.syntax(), f)
3387 } 3423 }
3388} 3424}
3389impl std::fmt::Display for Expr { 3425impl std::fmt::Display for Pat {
3426 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3427 std::fmt::Display::fmt(self.syntax(), f)
3428 }
3429}
3430impl std::fmt::Display for FieldList {
3390 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3431 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3391 std::fmt::Display::fmt(self.syntax(), f) 3432 std::fmt::Display::fmt(self.syntax(), f)
3392 } 3433 }
@@ -3416,6 +3457,66 @@ impl std::fmt::Display for Stmt {
3416 std::fmt::Display::fmt(self.syntax(), f) 3457 std::fmt::Display::fmt(self.syntax(), f)
3417 } 3458 }
3418} 3459}
3460impl std::fmt::Display for Path {
3461 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3462 std::fmt::Display::fmt(self.syntax(), f)
3463 }
3464}
3465impl std::fmt::Display for PathSegment {
3466 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3467 std::fmt::Display::fmt(self.syntax(), f)
3468 }
3469}
3470impl std::fmt::Display for NameRef {
3471 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3472 std::fmt::Display::fmt(self.syntax(), f)
3473 }
3474}
3475impl std::fmt::Display for GenericArgList {
3476 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3477 std::fmt::Display::fmt(self.syntax(), f)
3478 }
3479}
3480impl std::fmt::Display for ParamList {
3481 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3482 std::fmt::Display::fmt(self.syntax(), f)
3483 }
3484}
3485impl std::fmt::Display for RetType {
3486 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3487 std::fmt::Display::fmt(self.syntax(), f)
3488 }
3489}
3490impl std::fmt::Display for PathType {
3491 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3492 std::fmt::Display::fmt(self.syntax(), f)
3493 }
3494}
3495impl std::fmt::Display for TypeArg {
3496 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3497 std::fmt::Display::fmt(self.syntax(), f)
3498 }
3499}
3500impl std::fmt::Display for AssocTypeArg {
3501 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3502 std::fmt::Display::fmt(self.syntax(), f)
3503 }
3504}
3505impl std::fmt::Display for LifetimeArg {
3506 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3507 std::fmt::Display::fmt(self.syntax(), f)
3508 }
3509}
3510impl std::fmt::Display for ConstArg {
3511 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3512 std::fmt::Display::fmt(self.syntax(), f)
3513 }
3514}
3515impl std::fmt::Display for TypeBoundList {
3516 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3517 std::fmt::Display::fmt(self.syntax(), f)
3518 }
3519}
3419impl std::fmt::Display for SourceFile { 3520impl std::fmt::Display for SourceFile {
3420 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3521 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3421 std::fmt::Display::fmt(self.syntax(), f) 3522 std::fmt::Display::fmt(self.syntax(), f)
@@ -3511,11 +3612,6 @@ impl std::fmt::Display for ItemList {
3511 std::fmt::Display::fmt(self.syntax(), f) 3612 std::fmt::Display::fmt(self.syntax(), f)
3512 } 3613 }
3513} 3614}
3514impl std::fmt::Display for NameRef {
3515 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3516 std::fmt::Display::fmt(self.syntax(), f)
3517 }
3518}
3519impl std::fmt::Display for Rename { 3615impl std::fmt::Display for Rename {
3520 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3616 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3521 std::fmt::Display::fmt(self.syntax(), f) 3617 std::fmt::Display::fmt(self.syntax(), f)
@@ -3526,11 +3622,6 @@ impl std::fmt::Display for UseTree {
3526 std::fmt::Display::fmt(self.syntax(), f) 3622 std::fmt::Display::fmt(self.syntax(), f)
3527 } 3623 }
3528} 3624}
3529impl std::fmt::Display for Path {
3530 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3531 std::fmt::Display::fmt(self.syntax(), f)
3532 }
3533}
3534impl std::fmt::Display for UseTreeList { 3625impl std::fmt::Display for UseTreeList {
3535 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3626 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3536 std::fmt::Display::fmt(self.syntax(), f) 3627 std::fmt::Display::fmt(self.syntax(), f)
@@ -3546,16 +3637,6 @@ impl std::fmt::Display for GenericParamList {
3546 std::fmt::Display::fmt(self.syntax(), f) 3637 std::fmt::Display::fmt(self.syntax(), f)
3547 } 3638 }
3548} 3639}
3549impl std::fmt::Display for ParamList {
3550 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3551 std::fmt::Display::fmt(self.syntax(), f)
3552 }
3553}
3554impl std::fmt::Display for RetType {
3555 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3556 std::fmt::Display::fmt(self.syntax(), f)
3557 }
3558}
3559impl std::fmt::Display for WhereClause { 3640impl std::fmt::Display for WhereClause {
3560 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3641 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3561 std::fmt::Display::fmt(self.syntax(), f) 3642 std::fmt::Display::fmt(self.syntax(), f)
@@ -3576,11 +3657,6 @@ impl std::fmt::Display for Param {
3576 std::fmt::Display::fmt(self.syntax(), f) 3657 std::fmt::Display::fmt(self.syntax(), f)
3577 } 3658 }
3578} 3659}
3579impl std::fmt::Display for TypeBoundList {
3580 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3581 std::fmt::Display::fmt(self.syntax(), f)
3582 }
3583}
3584impl std::fmt::Display for RecordFieldList { 3660impl std::fmt::Display for RecordFieldList {
3585 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3661 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3586 std::fmt::Display::fmt(self.syntax(), f) 3662 std::fmt::Display::fmt(self.syntax(), f)
@@ -3696,6 +3772,11 @@ impl std::fmt::Display for CastExpr {
3696 std::fmt::Display::fmt(self.syntax(), f) 3772 std::fmt::Display::fmt(self.syntax(), f)
3697 } 3773 }
3698} 3774}
3775impl std::fmt::Display for ClosureExpr {
3776 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3777 std::fmt::Display::fmt(self.syntax(), f)
3778 }
3779}
3699impl std::fmt::Display for ContinueExpr { 3780impl std::fmt::Display for ContinueExpr {
3700 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3781 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3701 std::fmt::Display::fmt(self.syntax(), f) 3782 std::fmt::Display::fmt(self.syntax(), f)
@@ -3726,16 +3807,6 @@ impl std::fmt::Display for IndexExpr {
3726 std::fmt::Display::fmt(self.syntax(), f) 3807 std::fmt::Display::fmt(self.syntax(), f)
3727 } 3808 }
3728} 3809}
3729impl std::fmt::Display for Label {
3730 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3731 std::fmt::Display::fmt(self.syntax(), f)
3732 }
3733}
3734impl std::fmt::Display for ClosureExpr {
3735 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3736 std::fmt::Display::fmt(self.syntax(), f)
3737 }
3738}
3739impl std::fmt::Display for LoopExpr { 3810impl std::fmt::Display for LoopExpr {
3740 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3811 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3741 std::fmt::Display::fmt(self.syntax(), f) 3812 std::fmt::Display::fmt(self.syntax(), f)
@@ -3801,22 +3872,22 @@ impl std::fmt::Display for WhileExpr {
3801 std::fmt::Display::fmt(self.syntax(), f) 3872 std::fmt::Display::fmt(self.syntax(), f)
3802 } 3873 }
3803} 3874}
3804impl std::fmt::Display for RecordExprFieldList { 3875impl std::fmt::Display for Label {
3805 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3876 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3806 std::fmt::Display::fmt(self.syntax(), f) 3877 std::fmt::Display::fmt(self.syntax(), f)
3807 } 3878 }
3808} 3879}
3809impl std::fmt::Display for RecordExprField { 3880impl std::fmt::Display for RecordExprFieldList {
3810 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3881 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3811 std::fmt::Display::fmt(self.syntax(), f) 3882 std::fmt::Display::fmt(self.syntax(), f)
3812 } 3883 }
3813} 3884}
3814impl std::fmt::Display for ArgList { 3885impl std::fmt::Display for RecordExprField {
3815 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3886 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3816 std::fmt::Display::fmt(self.syntax(), f) 3887 std::fmt::Display::fmt(self.syntax(), f)
3817 } 3888 }
3818} 3889}
3819impl std::fmt::Display for TypeArgList { 3890impl std::fmt::Display for ArgList {
3820 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3891 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3821 std::fmt::Display::fmt(self.syntax(), f) 3892 std::fmt::Display::fmt(self.syntax(), f)
3822 } 3893 }
@@ -3881,11 +3952,6 @@ impl std::fmt::Display for ParenType {
3881 std::fmt::Display::fmt(self.syntax(), f) 3952 std::fmt::Display::fmt(self.syntax(), f)
3882 } 3953 }
3883} 3954}
3884impl std::fmt::Display for PathType {
3885 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3886 std::fmt::Display::fmt(self.syntax(), f)
3887 }
3888}
3889impl std::fmt::Display for PointerType { 3955impl std::fmt::Display for PointerType {
3890 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3956 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3891 std::fmt::Display::fmt(self.syntax(), f) 3957 std::fmt::Display::fmt(self.syntax(), f)
@@ -4006,28 +4072,3 @@ impl std::fmt::Display for MacroStmts {
4006 std::fmt::Display::fmt(self.syntax(), f) 4072 std::fmt::Display::fmt(self.syntax(), f)
4007 } 4073 }
4008} 4074}
4009impl std::fmt::Display for PathSegment {
4010 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4011 std::fmt::Display::fmt(self.syntax(), f)
4012 }
4013}
4014impl std::fmt::Display for TypeArg {
4015 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4016 std::fmt::Display::fmt(self.syntax(), f)
4017 }
4018}
4019impl std::fmt::Display for LifetimeArg {
4020 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4021 std::fmt::Display::fmt(self.syntax(), f)
4022 }
4023}
4024impl std::fmt::Display for AssocTypeArg {
4025 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4026 std::fmt::Display::fmt(self.syntax(), f)
4027 }
4028}
4029impl std::fmt::Display for ConstArg {
4030 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4031 std::fmt::Display::fmt(self.syntax(), f)
4032 }
4033}