aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-19 16:33:19 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-19 16:33:19 +0100
commit7bc9dec7cf195bc73a88d7c740f9d0bed1019e98 (patch)
tree12e2301c22b893d8f25abd7ded41f8b163e82efa /crates/ra_syntax/src/ast
parent8718a47088585bdb411f37d1b7cd1244d7528eaa (diff)
parenta6df224f7d3893f5a742b58818eac6c5a953721d (diff)
Merge #1553
1553: cleanup casts r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs1737
-rw-r--r--crates/ra_syntax/src/ast/generated.rs.tera56
2 files changed, 959 insertions, 834 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index a1f320257..99fcdbd9a 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -10,7 +10,7 @@
10#![cfg_attr(rustfmt, rustfmt_skip)] 10#![cfg_attr(rustfmt, rustfmt_skip)]
11 11
12use crate::{ 12use crate::{
13 SyntaxNode, SyntaxKind::*, 13 SyntaxNode, SyntaxKind::{self, *},
14 ast::{self, AstNode}, 14 ast::{self, AstNode},
15}; 15};
16 16
@@ -21,12 +21,15 @@ pub struct Alias {
21} 21}
22 22
23impl AstNode for Alias { 23impl AstNode for Alias {
24 fn cast(syntax: SyntaxNode) -> Option<Self> { 24 fn can_cast(kind: SyntaxKind) -> bool {
25 match syntax.kind() { 25 match kind {
26 ALIAS => Some(Alias { syntax }), 26 ALIAS => true,
27 _ => None, 27 _ => false,
28 } 28 }
29 } 29 }
30 fn cast(syntax: SyntaxNode) -> Option<Self> {
31 if Self::can_cast(syntax.kind()) { Some(Alias { syntax }) } else { None }
32 }
30 fn syntax(&self) -> &SyntaxNode { &self.syntax } 33 fn syntax(&self) -> &SyntaxNode { &self.syntax }
31} 34}
32 35
@@ -41,12 +44,15 @@ pub struct ArgList {
41} 44}
42 45
43impl AstNode for ArgList { 46impl AstNode for ArgList {
44 fn cast(syntax: SyntaxNode) -> Option<Self> { 47 fn can_cast(kind: SyntaxKind) -> bool {
45 match syntax.kind() { 48 match kind {
46 ARG_LIST => Some(ArgList { syntax }), 49 ARG_LIST => true,
47 _ => None, 50 _ => false,
48 } 51 }
49 } 52 }
53 fn cast(syntax: SyntaxNode) -> Option<Self> {
54 if Self::can_cast(syntax.kind()) { Some(ArgList { syntax }) } else { None }
55 }
50 fn syntax(&self) -> &SyntaxNode { &self.syntax } 56 fn syntax(&self) -> &SyntaxNode { &self.syntax }
51} 57}
52 58
@@ -64,12 +70,15 @@ pub struct ArrayExpr {
64} 70}
65 71
66impl AstNode for ArrayExpr { 72impl AstNode for ArrayExpr {
67 fn cast(syntax: SyntaxNode) -> Option<Self> { 73 fn can_cast(kind: SyntaxKind) -> bool {
68 match syntax.kind() { 74 match kind {
69 ARRAY_EXPR => Some(ArrayExpr { syntax }), 75 ARRAY_EXPR => true,
70 _ => None, 76 _ => false,
71 } 77 }
72 } 78 }
79 fn cast(syntax: SyntaxNode) -> Option<Self> {
80 if Self::can_cast(syntax.kind()) { Some(ArrayExpr { syntax }) } else { None }
81 }
73 fn syntax(&self) -> &SyntaxNode { &self.syntax } 82 fn syntax(&self) -> &SyntaxNode { &self.syntax }
74} 83}
75 84
@@ -87,12 +96,15 @@ pub struct ArrayType {
87} 96}
88 97
89impl AstNode for ArrayType { 98impl AstNode for ArrayType {
90 fn cast(syntax: SyntaxNode) -> Option<Self> { 99 fn can_cast(kind: SyntaxKind) -> bool {
91 match syntax.kind() { 100 match kind {
92 ARRAY_TYPE => Some(ArrayType { syntax }), 101 ARRAY_TYPE => true,
93 _ => None, 102 _ => false,
94 } 103 }
95 } 104 }
105 fn cast(syntax: SyntaxNode) -> Option<Self> {
106 if Self::can_cast(syntax.kind()) { Some(ArrayType { syntax }) } else { None }
107 }
96 fn syntax(&self) -> &SyntaxNode { &self.syntax } 108 fn syntax(&self) -> &SyntaxNode { &self.syntax }
97} 109}
98 110
@@ -114,12 +126,15 @@ pub struct AssocTypeArg {
114} 126}
115 127
116impl AstNode for AssocTypeArg { 128impl AstNode for AssocTypeArg {
117 fn cast(syntax: SyntaxNode) -> Option<Self> { 129 fn can_cast(kind: SyntaxKind) -> bool {
118 match syntax.kind() { 130 match kind {
119 ASSOC_TYPE_ARG => Some(AssocTypeArg { syntax }), 131 ASSOC_TYPE_ARG => true,
120 _ => None, 132 _ => false,
121 } 133 }
122 } 134 }
135 fn cast(syntax: SyntaxNode) -> Option<Self> {
136 if Self::can_cast(syntax.kind()) { Some(AssocTypeArg { syntax }) } else { None }
137 }
123 fn syntax(&self) -> &SyntaxNode { &self.syntax } 138 fn syntax(&self) -> &SyntaxNode { &self.syntax }
124} 139}
125 140
@@ -141,12 +156,15 @@ pub struct Attr {
141} 156}
142 157
143impl AstNode for Attr { 158impl AstNode for Attr {
144 fn cast(syntax: SyntaxNode) -> Option<Self> { 159 fn can_cast(kind: SyntaxKind) -> bool {
145 match syntax.kind() { 160 match kind {
146 ATTR => Some(Attr { syntax }), 161 ATTR => true,
147 _ => None, 162 _ => false,
148 } 163 }
149 } 164 }
165 fn cast(syntax: SyntaxNode) -> Option<Self> {
166 if Self::can_cast(syntax.kind()) { Some(Attr { syntax }) } else { None }
167 }
150 fn syntax(&self) -> &SyntaxNode { &self.syntax } 168 fn syntax(&self) -> &SyntaxNode { &self.syntax }
151} 169}
152 170
@@ -164,12 +182,15 @@ pub struct BinExpr {
164} 182}
165 183
166impl AstNode for BinExpr { 184impl AstNode for BinExpr {
167 fn cast(syntax: SyntaxNode) -> Option<Self> { 185 fn can_cast(kind: SyntaxKind) -> bool {
168 match syntax.kind() { 186 match kind {
169 BIN_EXPR => Some(BinExpr { syntax }), 187 BIN_EXPR => true,
170 _ => None, 188 _ => false,
171 } 189 }
172 } 190 }
191 fn cast(syntax: SyntaxNode) -> Option<Self> {
192 if Self::can_cast(syntax.kind()) { Some(BinExpr { syntax }) } else { None }
193 }
173 fn syntax(&self) -> &SyntaxNode { &self.syntax } 194 fn syntax(&self) -> &SyntaxNode { &self.syntax }
174} 195}
175 196
@@ -183,12 +204,15 @@ pub struct BindPat {
183} 204}
184 205
185impl AstNode for BindPat { 206impl AstNode for BindPat {
186 fn cast(syntax: SyntaxNode) -> Option<Self> { 207 fn can_cast(kind: SyntaxKind) -> bool {
187 match syntax.kind() { 208 match kind {
188 BIND_PAT => Some(BindPat { syntax }), 209 BIND_PAT => true,
189 _ => None, 210 _ => false,
190 } 211 }
191 } 212 }
213 fn cast(syntax: SyntaxNode) -> Option<Self> {
214 if Self::can_cast(syntax.kind()) { Some(BindPat { syntax }) } else { None }
215 }
192 fn syntax(&self) -> &SyntaxNode { &self.syntax } 216 fn syntax(&self) -> &SyntaxNode { &self.syntax }
193} 217}
194 218
@@ -207,12 +231,15 @@ pub struct Block {
207} 231}
208 232
209impl AstNode for Block { 233impl AstNode for Block {
210 fn cast(syntax: SyntaxNode) -> Option<Self> { 234 fn can_cast(kind: SyntaxKind) -> bool {
211 match syntax.kind() { 235 match kind {
212 BLOCK => Some(Block { syntax }), 236 BLOCK => true,
213 _ => None, 237 _ => false,
214 } 238 }
215 } 239 }
240 fn cast(syntax: SyntaxNode) -> Option<Self> {
241 if Self::can_cast(syntax.kind()) { Some(Block { syntax }) } else { None }
242 }
216 fn syntax(&self) -> &SyntaxNode { &self.syntax } 243 fn syntax(&self) -> &SyntaxNode { &self.syntax }
217} 244}
218 245
@@ -235,12 +262,15 @@ pub struct BlockExpr {
235} 262}
236 263
237impl AstNode for BlockExpr { 264impl AstNode for BlockExpr {
238 fn cast(syntax: SyntaxNode) -> Option<Self> { 265 fn can_cast(kind: SyntaxKind) -> bool {
239 match syntax.kind() { 266 match kind {
240 BLOCK_EXPR => Some(BlockExpr { syntax }), 267 BLOCK_EXPR => true,
241 _ => None, 268 _ => false,
242 } 269 }
243 } 270 }
271 fn cast(syntax: SyntaxNode) -> Option<Self> {
272 if Self::can_cast(syntax.kind()) { Some(BlockExpr { syntax }) } else { None }
273 }
244 fn syntax(&self) -> &SyntaxNode { &self.syntax } 274 fn syntax(&self) -> &SyntaxNode { &self.syntax }
245} 275}
246 276
@@ -258,12 +288,15 @@ pub struct BreakExpr {
258} 288}
259 289
260impl AstNode for BreakExpr { 290impl AstNode for BreakExpr {
261 fn cast(syntax: SyntaxNode) -> Option<Self> { 291 fn can_cast(kind: SyntaxKind) -> bool {
262 match syntax.kind() { 292 match kind {
263 BREAK_EXPR => Some(BreakExpr { syntax }), 293 BREAK_EXPR => true,
264 _ => None, 294 _ => false,
265 } 295 }
266 } 296 }
297 fn cast(syntax: SyntaxNode) -> Option<Self> {
298 if Self::can_cast(syntax.kind()) { Some(BreakExpr { syntax }) } else { None }
299 }
267 fn syntax(&self) -> &SyntaxNode { &self.syntax } 300 fn syntax(&self) -> &SyntaxNode { &self.syntax }
268} 301}
269 302
@@ -281,12 +314,15 @@ pub struct CallExpr {
281} 314}
282 315
283impl AstNode for CallExpr { 316impl AstNode for CallExpr {
284 fn cast(syntax: SyntaxNode) -> Option<Self> { 317 fn can_cast(kind: SyntaxKind) -> bool {
285 match syntax.kind() { 318 match kind {
286 CALL_EXPR => Some(CallExpr { syntax }), 319 CALL_EXPR => true,
287 _ => None, 320 _ => false,
288 } 321 }
289 } 322 }
323 fn cast(syntax: SyntaxNode) -> Option<Self> {
324 if Self::can_cast(syntax.kind()) { Some(CallExpr { syntax }) } else { None }
325 }
290 fn syntax(&self) -> &SyntaxNode { &self.syntax } 326 fn syntax(&self) -> &SyntaxNode { &self.syntax }
291} 327}
292 328
@@ -305,12 +341,15 @@ pub struct CastExpr {
305} 341}
306 342
307impl AstNode for CastExpr { 343impl AstNode for CastExpr {
308 fn cast(syntax: SyntaxNode) -> Option<Self> { 344 fn can_cast(kind: SyntaxKind) -> bool {
309 match syntax.kind() { 345 match kind {
310 CAST_EXPR => Some(CastExpr { syntax }), 346 CAST_EXPR => true,
311 _ => None, 347 _ => false,
312 } 348 }
313 } 349 }
350 fn cast(syntax: SyntaxNode) -> Option<Self> {
351 if Self::can_cast(syntax.kind()) { Some(CastExpr { syntax }) } else { None }
352 }
314 fn syntax(&self) -> &SyntaxNode { &self.syntax } 353 fn syntax(&self) -> &SyntaxNode { &self.syntax }
315} 354}
316 355
@@ -332,12 +371,15 @@ pub struct Condition {
332} 371}
333 372
334impl AstNode for Condition { 373impl AstNode for Condition {
335 fn cast(syntax: SyntaxNode) -> Option<Self> { 374 fn can_cast(kind: SyntaxKind) -> bool {
336 match syntax.kind() { 375 match kind {
337 CONDITION => Some(Condition { syntax }), 376 CONDITION => true,
338 _ => None, 377 _ => false,
339 } 378 }
340 } 379 }
380 fn cast(syntax: SyntaxNode) -> Option<Self> {
381 if Self::can_cast(syntax.kind()) { Some(Condition { syntax }) } else { None }
382 }
341 fn syntax(&self) -> &SyntaxNode { &self.syntax } 383 fn syntax(&self) -> &SyntaxNode { &self.syntax }
342} 384}
343 385
@@ -359,12 +401,15 @@ pub struct ConstDef {
359} 401}
360 402
361impl AstNode for ConstDef { 403impl AstNode for ConstDef {
362 fn cast(syntax: SyntaxNode) -> Option<Self> { 404 fn can_cast(kind: SyntaxKind) -> bool {
363 match syntax.kind() { 405 match kind {
364 CONST_DEF => Some(ConstDef { syntax }), 406 CONST_DEF => true,
365 _ => None, 407 _ => false,
366 } 408 }
367 } 409 }
410 fn cast(syntax: SyntaxNode) -> Option<Self> {
411 if Self::can_cast(syntax.kind()) { Some(ConstDef { syntax }) } else { None }
412 }
368 fn syntax(&self) -> &SyntaxNode { &self.syntax } 413 fn syntax(&self) -> &SyntaxNode { &self.syntax }
369} 414}
370 415
@@ -388,12 +433,15 @@ pub struct ContinueExpr {
388} 433}
389 434
390impl AstNode for ContinueExpr { 435impl AstNode for ContinueExpr {
391 fn cast(syntax: SyntaxNode) -> Option<Self> { 436 fn can_cast(kind: SyntaxKind) -> bool {
392 match syntax.kind() { 437 match kind {
393 CONTINUE_EXPR => Some(ContinueExpr { syntax }), 438 CONTINUE_EXPR => true,
394 _ => None, 439 _ => false,
395 } 440 }
396 } 441 }
442 fn cast(syntax: SyntaxNode) -> Option<Self> {
443 if Self::can_cast(syntax.kind()) { Some(ContinueExpr { syntax }) } else { None }
444 }
397 fn syntax(&self) -> &SyntaxNode { &self.syntax } 445 fn syntax(&self) -> &SyntaxNode { &self.syntax }
398} 446}
399 447
@@ -407,12 +455,15 @@ pub struct DynTraitType {
407} 455}
408 456
409impl AstNode for DynTraitType { 457impl AstNode for DynTraitType {
410 fn cast(syntax: SyntaxNode) -> Option<Self> { 458 fn can_cast(kind: SyntaxKind) -> bool {
411 match syntax.kind() { 459 match kind {
412 DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), 460 DYN_TRAIT_TYPE => true,
413 _ => None, 461 _ => false,
414 } 462 }
415 } 463 }
464 fn cast(syntax: SyntaxNode) -> Option<Self> {
465 if Self::can_cast(syntax.kind()) { Some(DynTraitType { syntax }) } else { None }
466 }
416 fn syntax(&self) -> &SyntaxNode { &self.syntax } 467 fn syntax(&self) -> &SyntaxNode { &self.syntax }
417} 468}
418 469
@@ -427,12 +478,15 @@ pub struct EnumDef {
427} 478}
428 479
429impl AstNode for EnumDef { 480impl AstNode for EnumDef {
430 fn cast(syntax: SyntaxNode) -> Option<Self> { 481 fn can_cast(kind: SyntaxKind) -> bool {
431 match syntax.kind() { 482 match kind {
432 ENUM_DEF => Some(EnumDef { syntax }), 483 ENUM_DEF => true,
433 _ => None, 484 _ => false,
434 } 485 }
435 } 486 }
487 fn cast(syntax: SyntaxNode) -> Option<Self> {
488 if Self::can_cast(syntax.kind()) { Some(EnumDef { syntax }) } else { None }
489 }
436 fn syntax(&self) -> &SyntaxNode { &self.syntax } 490 fn syntax(&self) -> &SyntaxNode { &self.syntax }
437} 491}
438 492
@@ -455,12 +509,15 @@ pub struct EnumVariant {
455} 509}
456 510
457impl AstNode for EnumVariant { 511impl AstNode for EnumVariant {
458 fn cast(syntax: SyntaxNode) -> Option<Self> { 512 fn can_cast(kind: SyntaxKind) -> bool {
459 match syntax.kind() { 513 match kind {
460 ENUM_VARIANT => Some(EnumVariant { syntax }), 514 ENUM_VARIANT => true,
461 _ => None, 515 _ => false,
462 } 516 }
463 } 517 }
518 fn cast(syntax: SyntaxNode) -> Option<Self> {
519 if Self::can_cast(syntax.kind()) { Some(EnumVariant { syntax }) } else { None }
520 }
464 fn syntax(&self) -> &SyntaxNode { &self.syntax } 521 fn syntax(&self) -> &SyntaxNode { &self.syntax }
465} 522}
466 523
@@ -481,12 +538,15 @@ pub struct EnumVariantList {
481} 538}
482 539
483impl AstNode for EnumVariantList { 540impl AstNode for EnumVariantList {
484 fn cast(syntax: SyntaxNode) -> Option<Self> { 541 fn can_cast(kind: SyntaxKind) -> bool {
485 match syntax.kind() { 542 match kind {
486 ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), 543 ENUM_VARIANT_LIST => true,
487 _ => None, 544 _ => false,
488 } 545 }
489 } 546 }
547 fn cast(syntax: SyntaxNode) -> Option<Self> {
548 if Self::can_cast(syntax.kind()) { Some(EnumVariantList { syntax }) } else { None }
549 }
490 fn syntax(&self) -> &SyntaxNode { &self.syntax } 550 fn syntax(&self) -> &SyntaxNode { &self.syntax }
491} 551}
492 552
@@ -503,6 +563,20 @@ pub struct Expr {
503 pub(crate) syntax: SyntaxNode, 563 pub(crate) syntax: SyntaxNode,
504} 564}
505 565
566impl AstNode for Expr {
567 fn can_cast(kind: SyntaxKind) -> bool {
568 match kind {
569 | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true,
570 _ => false,
571 }
572 }
573 fn cast(syntax: SyntaxNode) -> Option<Self> {
574 if Self::can_cast(syntax.kind()) { Some(Expr { syntax }) } else { None }
575 }
576 fn syntax(&self) -> &SyntaxNode { &self.syntax }
577}
578
579
506#[derive(Debug, Clone, PartialEq, Eq)] 580#[derive(Debug, Clone, PartialEq, Eq)]
507pub enum ExprKind { 581pub enum ExprKind {
508 TupleExpr(TupleExpr), 582 TupleExpr(TupleExpr),
@@ -536,190 +610,92 @@ pub enum ExprKind {
536 MacroCall(MacroCall), 610 MacroCall(MacroCall),
537} 611}
538impl From<TupleExpr> for Expr { 612impl From<TupleExpr> for Expr {
539 fn from(n: TupleExpr) -> Expr { 613 fn from(n: TupleExpr) -> Expr { Expr { syntax: n.syntax } }
540 Expr::cast(n.syntax).unwrap()
541 }
542} 614}
543impl From<ArrayExpr> for Expr { 615impl From<ArrayExpr> for Expr {
544 fn from(n: ArrayExpr) -> Expr { 616 fn from(n: ArrayExpr) -> Expr { Expr { syntax: n.syntax } }
545 Expr::cast(n.syntax).unwrap()
546 }
547} 617}
548impl From<ParenExpr> for Expr { 618impl From<ParenExpr> for Expr {
549 fn from(n: ParenExpr) -> Expr { 619 fn from(n: ParenExpr) -> Expr { Expr { syntax: n.syntax } }
550 Expr::cast(n.syntax).unwrap()
551 }
552} 620}
553impl From<PathExpr> for Expr { 621impl From<PathExpr> for Expr {
554 fn from(n: PathExpr) -> Expr { 622 fn from(n: PathExpr) -> Expr { Expr { syntax: n.syntax } }
555 Expr::cast(n.syntax).unwrap()
556 }
557} 623}
558impl From<LambdaExpr> for Expr { 624impl From<LambdaExpr> for Expr {
559 fn from(n: LambdaExpr) -> Expr { 625 fn from(n: LambdaExpr) -> Expr { Expr { syntax: n.syntax } }
560 Expr::cast(n.syntax).unwrap()
561 }
562} 626}
563impl From<IfExpr> for Expr { 627impl From<IfExpr> for Expr {
564 fn from(n: IfExpr) -> Expr { 628 fn from(n: IfExpr) -> Expr { Expr { syntax: n.syntax } }
565 Expr::cast(n.syntax).unwrap()
566 }
567} 629}
568impl From<LoopExpr> for Expr { 630impl From<LoopExpr> for Expr {
569 fn from(n: LoopExpr) -> Expr { 631 fn from(n: LoopExpr) -> Expr { Expr { syntax: n.syntax } }
570 Expr::cast(n.syntax).unwrap()
571 }
572} 632}
573impl From<ForExpr> for Expr { 633impl From<ForExpr> for Expr {
574 fn from(n: ForExpr) -> Expr { 634 fn from(n: ForExpr) -> Expr { Expr { syntax: n.syntax } }
575 Expr::cast(n.syntax).unwrap()
576 }
577} 635}
578impl From<WhileExpr> for Expr { 636impl From<WhileExpr> for Expr {
579 fn from(n: WhileExpr) -> Expr { 637 fn from(n: WhileExpr) -> Expr { Expr { syntax: n.syntax } }
580 Expr::cast(n.syntax).unwrap()
581 }
582} 638}
583impl From<ContinueExpr> for Expr { 639impl From<ContinueExpr> for Expr {
584 fn from(n: ContinueExpr) -> Expr { 640 fn from(n: ContinueExpr) -> Expr { Expr { syntax: n.syntax } }
585 Expr::cast(n.syntax).unwrap()
586 }
587} 641}
588impl From<BreakExpr> for Expr { 642impl From<BreakExpr> for Expr {
589 fn from(n: BreakExpr) -> Expr { 643 fn from(n: BreakExpr) -> Expr { Expr { syntax: n.syntax } }
590 Expr::cast(n.syntax).unwrap()
591 }
592} 644}
593impl From<Label> for Expr { 645impl From<Label> for Expr {
594 fn from(n: Label) -> Expr { 646 fn from(n: Label) -> Expr { Expr { syntax: n.syntax } }
595 Expr::cast(n.syntax).unwrap()
596 }
597} 647}
598impl From<BlockExpr> for Expr { 648impl From<BlockExpr> for Expr {
599 fn from(n: BlockExpr) -> Expr { 649 fn from(n: BlockExpr) -> Expr { Expr { syntax: n.syntax } }
600 Expr::cast(n.syntax).unwrap()
601 }
602} 650}
603impl From<ReturnExpr> for Expr { 651impl From<ReturnExpr> for Expr {
604 fn from(n: ReturnExpr) -> Expr { 652 fn from(n: ReturnExpr) -> Expr { Expr { syntax: n.syntax } }
605 Expr::cast(n.syntax).unwrap()
606 }
607} 653}
608impl From<MatchExpr> for Expr { 654impl From<MatchExpr> for Expr {
609 fn from(n: MatchExpr) -> Expr { 655 fn from(n: MatchExpr) -> Expr { Expr { syntax: n.syntax } }
610 Expr::cast(n.syntax).unwrap()
611 }
612} 656}
613impl From<StructLit> for Expr { 657impl From<StructLit> for Expr {
614 fn from(n: StructLit) -> Expr { 658 fn from(n: StructLit) -> Expr { Expr { syntax: n.syntax } }
615 Expr::cast(n.syntax).unwrap()
616 }
617} 659}
618impl From<CallExpr> for Expr { 660impl From<CallExpr> for Expr {
619 fn from(n: CallExpr) -> Expr { 661 fn from(n: CallExpr) -> Expr { Expr { syntax: n.syntax } }
620 Expr::cast(n.syntax).unwrap()
621 }
622} 662}
623impl From<IndexExpr> for Expr { 663impl From<IndexExpr> for Expr {
624 fn from(n: IndexExpr) -> Expr { 664 fn from(n: IndexExpr) -> Expr { Expr { syntax: n.syntax } }
625 Expr::cast(n.syntax).unwrap()
626 }
627} 665}
628impl From<MethodCallExpr> for Expr { 666impl From<MethodCallExpr> for Expr {
629 fn from(n: MethodCallExpr) -> Expr { 667 fn from(n: MethodCallExpr) -> Expr { Expr { syntax: n.syntax } }
630 Expr::cast(n.syntax).unwrap()
631 }
632} 668}
633impl From<FieldExpr> for Expr { 669impl From<FieldExpr> for Expr {
634 fn from(n: FieldExpr) -> Expr { 670 fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } }
635 Expr::cast(n.syntax).unwrap()
636 }
637} 671}
638impl From<TryExpr> for Expr { 672impl From<TryExpr> for Expr {
639 fn from(n: TryExpr) -> Expr { 673 fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } }
640 Expr::cast(n.syntax).unwrap()
641 }
642} 674}
643impl From<TryBlockExpr> for Expr { 675impl From<TryBlockExpr> for Expr {
644 fn from(n: TryBlockExpr) -> Expr { 676 fn from(n: TryBlockExpr) -> Expr { Expr { syntax: n.syntax } }
645 Expr::cast(n.syntax).unwrap()
646 }
647} 677}
648impl From<CastExpr> for Expr { 678impl From<CastExpr> for Expr {
649 fn from(n: CastExpr) -> Expr { 679 fn from(n: CastExpr) -> Expr { Expr { syntax: n.syntax } }
650 Expr::cast(n.syntax).unwrap()
651 }
652} 680}
653impl From<RefExpr> for Expr { 681impl From<RefExpr> for Expr {
654 fn from(n: RefExpr) -> Expr { 682 fn from(n: RefExpr) -> Expr { Expr { syntax: n.syntax } }
655 Expr::cast(n.syntax).unwrap()
656 }
657} 683}
658impl From<PrefixExpr> for Expr { 684impl From<PrefixExpr> for Expr {
659 fn from(n: PrefixExpr) -> Expr { 685 fn from(n: PrefixExpr) -> Expr { Expr { syntax: n.syntax } }
660 Expr::cast(n.syntax).unwrap()
661 }
662} 686}
663impl From<RangeExpr> for Expr { 687impl From<RangeExpr> for Expr {
664 fn from(n: RangeExpr) -> Expr { 688 fn from(n: RangeExpr) -> Expr { Expr { syntax: n.syntax } }
665 Expr::cast(n.syntax).unwrap()
666 }
667} 689}
668impl From<BinExpr> for Expr { 690impl From<BinExpr> for Expr {
669 fn from(n: BinExpr) -> Expr { 691 fn from(n: BinExpr) -> Expr { Expr { syntax: n.syntax } }
670 Expr::cast(n.syntax).unwrap()
671 }
672} 692}
673impl From<Literal> for Expr { 693impl From<Literal> for Expr {
674 fn from(n: Literal) -> Expr { 694 fn from(n: Literal) -> Expr { Expr { syntax: n.syntax } }
675 Expr::cast(n.syntax).unwrap()
676 }
677} 695}
678impl From<MacroCall> for Expr { 696impl From<MacroCall> for Expr {
679 fn from(n: MacroCall) -> Expr { 697 fn from(n: MacroCall) -> Expr { Expr { syntax: n.syntax } }
680 Expr::cast(n.syntax).unwrap()
681 }
682}
683
684
685impl AstNode for Expr {
686 fn cast(syntax: SyntaxNode) -> Option<Self> {
687 match syntax.kind() {
688 | TUPLE_EXPR
689 | ARRAY_EXPR
690 | PAREN_EXPR
691 | PATH_EXPR
692 | LAMBDA_EXPR
693 | IF_EXPR
694 | LOOP_EXPR
695 | FOR_EXPR
696 | WHILE_EXPR
697 | CONTINUE_EXPR
698 | BREAK_EXPR
699 | LABEL
700 | BLOCK_EXPR
701 | RETURN_EXPR
702 | MATCH_EXPR
703 | STRUCT_LIT
704 | CALL_EXPR
705 | INDEX_EXPR
706 | METHOD_CALL_EXPR
707 | FIELD_EXPR
708 | TRY_EXPR
709 | TRY_BLOCK_EXPR
710 | CAST_EXPR
711 | REF_EXPR
712 | PREFIX_EXPR
713 | RANGE_EXPR
714 | BIN_EXPR
715 | LITERAL
716 | MACRO_CALL => Some(Expr { syntax }),
717 _ => None,
718 }
719 }
720 fn syntax(&self) -> &SyntaxNode { &self.syntax }
721} 698}
722
723impl Expr { 699impl Expr {
724 pub fn kind(&self) -> ExprKind { 700 pub fn kind(&self) -> ExprKind {
725 match self.syntax.kind() { 701 match self.syntax.kind() {
@@ -766,12 +742,15 @@ pub struct ExprStmt {
766} 742}
767 743
768impl AstNode for ExprStmt { 744impl AstNode for ExprStmt {
769 fn cast(syntax: SyntaxNode) -> Option<Self> { 745 fn can_cast(kind: SyntaxKind) -> bool {
770 match syntax.kind() { 746 match kind {
771 EXPR_STMT => Some(ExprStmt { syntax }), 747 EXPR_STMT => true,
772 _ => None, 748 _ => false,
773 } 749 }
774 } 750 }
751 fn cast(syntax: SyntaxNode) -> Option<Self> {
752 if Self::can_cast(syntax.kind()) { Some(ExprStmt { syntax }) } else { None }
753 }
775 fn syntax(&self) -> &SyntaxNode { &self.syntax } 754 fn syntax(&self) -> &SyntaxNode { &self.syntax }
776} 755}
777 756
@@ -789,12 +768,15 @@ pub struct ExternCrateItem {
789} 768}
790 769
791impl AstNode for ExternCrateItem { 770impl AstNode for ExternCrateItem {
792 fn cast(syntax: SyntaxNode) -> Option<Self> { 771 fn can_cast(kind: SyntaxKind) -> bool {
793 match syntax.kind() { 772 match kind {
794 EXTERN_CRATE_ITEM => Some(ExternCrateItem { syntax }), 773 EXTERN_CRATE_ITEM => true,
795 _ => None, 774 _ => false,
796 } 775 }
797 } 776 }
777 fn cast(syntax: SyntaxNode) -> Option<Self> {
778 if Self::can_cast(syntax.kind()) { Some(ExternCrateItem { syntax }) } else { None }
779 }
798 fn syntax(&self) -> &SyntaxNode { &self.syntax } 780 fn syntax(&self) -> &SyntaxNode { &self.syntax }
799} 781}
800 782
@@ -816,12 +798,15 @@ pub struct FieldExpr {
816} 798}
817 799
818impl AstNode for FieldExpr { 800impl AstNode for FieldExpr {
819 fn cast(syntax: SyntaxNode) -> Option<Self> { 801 fn can_cast(kind: SyntaxKind) -> bool {
820 match syntax.kind() { 802 match kind {
821 FIELD_EXPR => Some(FieldExpr { syntax }), 803 FIELD_EXPR => true,
822 _ => None, 804 _ => false,
823 } 805 }
824 } 806 }
807 fn cast(syntax: SyntaxNode) -> Option<Self> {
808 if Self::can_cast(syntax.kind()) { Some(FieldExpr { syntax }) } else { None }
809 }
825 fn syntax(&self) -> &SyntaxNode { &self.syntax } 810 fn syntax(&self) -> &SyntaxNode { &self.syntax }
826} 811}
827 812
@@ -843,12 +828,15 @@ pub struct FieldPat {
843} 828}
844 829
845impl AstNode for FieldPat { 830impl AstNode for FieldPat {
846 fn cast(syntax: SyntaxNode) -> Option<Self> { 831 fn can_cast(kind: SyntaxKind) -> bool {
847 match syntax.kind() { 832 match kind {
848 FIELD_PAT => Some(FieldPat { syntax }), 833 FIELD_PAT => true,
849 _ => None, 834 _ => false,
850 } 835 }
851 } 836 }
837 fn cast(syntax: SyntaxNode) -> Option<Self> {
838 if Self::can_cast(syntax.kind()) { Some(FieldPat { syntax }) } else { None }
839 }
852 fn syntax(&self) -> &SyntaxNode { &self.syntax } 840 fn syntax(&self) -> &SyntaxNode { &self.syntax }
853} 841}
854 842
@@ -867,12 +855,15 @@ pub struct FieldPatList {
867} 855}
868 856
869impl AstNode for FieldPatList { 857impl AstNode for FieldPatList {
870 fn cast(syntax: SyntaxNode) -> Option<Self> { 858 fn can_cast(kind: SyntaxKind) -> bool {
871 match syntax.kind() { 859 match kind {
872 FIELD_PAT_LIST => Some(FieldPatList { syntax }), 860 FIELD_PAT_LIST => true,
873 _ => None, 861 _ => false,
874 } 862 }
875 } 863 }
864 fn cast(syntax: SyntaxNode) -> Option<Self> {
865 if Self::can_cast(syntax.kind()) { Some(FieldPatList { syntax }) } else { None }
866 }
876 fn syntax(&self) -> &SyntaxNode { &self.syntax } 867 fn syntax(&self) -> &SyntaxNode { &self.syntax }
877} 868}
878 869
@@ -894,12 +885,15 @@ pub struct FnDef {
894} 885}
895 886
896impl AstNode for FnDef { 887impl AstNode for FnDef {
897 fn cast(syntax: SyntaxNode) -> Option<Self> { 888 fn can_cast(kind: SyntaxKind) -> bool {
898 match syntax.kind() { 889 match kind {
899 FN_DEF => Some(FnDef { syntax }), 890 FN_DEF => true,
900 _ => None, 891 _ => false,
901 } 892 }
902 } 893 }
894 fn cast(syntax: SyntaxNode) -> Option<Self> {
895 if Self::can_cast(syntax.kind()) { Some(FnDef { syntax }) } else { None }
896 }
903 fn syntax(&self) -> &SyntaxNode { &self.syntax } 897 fn syntax(&self) -> &SyntaxNode { &self.syntax }
904} 898}
905 899
@@ -930,12 +924,15 @@ pub struct FnPointerType {
930} 924}
931 925
932impl AstNode for FnPointerType { 926impl AstNode for FnPointerType {
933 fn cast(syntax: SyntaxNode) -> Option<Self> { 927 fn can_cast(kind: SyntaxKind) -> bool {
934 match syntax.kind() { 928 match kind {
935 FN_POINTER_TYPE => Some(FnPointerType { syntax }), 929 FN_POINTER_TYPE => true,
936 _ => None, 930 _ => false,
937 } 931 }
938 } 932 }
933 fn cast(syntax: SyntaxNode) -> Option<Self> {
934 if Self::can_cast(syntax.kind()) { Some(FnPointerType { syntax }) } else { None }
935 }
939 fn syntax(&self) -> &SyntaxNode { &self.syntax } 936 fn syntax(&self) -> &SyntaxNode { &self.syntax }
940} 937}
941 938
@@ -957,12 +954,15 @@ pub struct ForExpr {
957} 954}
958 955
959impl AstNode for ForExpr { 956impl AstNode for ForExpr {
960 fn cast(syntax: SyntaxNode) -> Option<Self> { 957 fn can_cast(kind: SyntaxKind) -> bool {
961 match syntax.kind() { 958 match kind {
962 FOR_EXPR => Some(ForExpr { syntax }), 959 FOR_EXPR => true,
963 _ => None, 960 _ => false,
964 } 961 }
965 } 962 }
963 fn cast(syntax: SyntaxNode) -> Option<Self> {
964 if Self::can_cast(syntax.kind()) { Some(ForExpr { syntax }) } else { None }
965 }
966 fn syntax(&self) -> &SyntaxNode { &self.syntax } 966 fn syntax(&self) -> &SyntaxNode { &self.syntax }
967} 967}
968 968
@@ -985,12 +985,15 @@ pub struct ForType {
985} 985}
986 986
987impl AstNode for ForType { 987impl AstNode for ForType {
988 fn cast(syntax: SyntaxNode) -> Option<Self> { 988 fn can_cast(kind: SyntaxKind) -> bool {
989 match syntax.kind() { 989 match kind {
990 FOR_TYPE => Some(ForType { syntax }), 990 FOR_TYPE => true,
991 _ => None, 991 _ => false,
992 } 992 }
993 } 993 }
994 fn cast(syntax: SyntaxNode) -> Option<Self> {
995 if Self::can_cast(syntax.kind()) { Some(ForType { syntax }) } else { None }
996 }
994 fn syntax(&self) -> &SyntaxNode { &self.syntax } 997 fn syntax(&self) -> &SyntaxNode { &self.syntax }
995} 998}
996 999
@@ -1008,12 +1011,15 @@ pub struct IfExpr {
1008} 1011}
1009 1012
1010impl AstNode for IfExpr { 1013impl AstNode for IfExpr {
1011 fn cast(syntax: SyntaxNode) -> Option<Self> { 1014 fn can_cast(kind: SyntaxKind) -> bool {
1012 match syntax.kind() { 1015 match kind {
1013 IF_EXPR => Some(IfExpr { syntax }), 1016 IF_EXPR => true,
1014 _ => None, 1017 _ => false,
1015 } 1018 }
1016 } 1019 }
1020 fn cast(syntax: SyntaxNode) -> Option<Self> {
1021 if Self::can_cast(syntax.kind()) { Some(IfExpr { syntax }) } else { None }
1022 }
1017 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1023 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1018} 1024}
1019 1025
@@ -1031,12 +1037,15 @@ pub struct ImplBlock {
1031} 1037}
1032 1038
1033impl AstNode for ImplBlock { 1039impl AstNode for ImplBlock {
1034 fn cast(syntax: SyntaxNode) -> Option<Self> { 1040 fn can_cast(kind: SyntaxKind) -> bool {
1035 match syntax.kind() { 1041 match kind {
1036 IMPL_BLOCK => Some(ImplBlock { syntax }), 1042 IMPL_BLOCK => true,
1037 _ => None, 1043 _ => false,
1038 } 1044 }
1039 } 1045 }
1046 fn cast(syntax: SyntaxNode) -> Option<Self> {
1047 if Self::can_cast(syntax.kind()) { Some(ImplBlock { syntax }) } else { None }
1048 }
1040 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1049 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1041} 1050}
1042 1051
@@ -1055,6 +1064,20 @@ pub struct ImplItem {
1055 pub(crate) syntax: SyntaxNode, 1064 pub(crate) syntax: SyntaxNode,
1056} 1065}
1057 1066
1067impl AstNode for ImplItem {
1068 fn can_cast(kind: SyntaxKind) -> bool {
1069 match kind {
1070 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
1071 _ => false,
1072 }
1073 }
1074 fn cast(syntax: SyntaxNode) -> Option<Self> {
1075 if Self::can_cast(syntax.kind()) { Some(ImplItem { syntax }) } else { None }
1076 }
1077 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1078}
1079
1080
1058#[derive(Debug, Clone, PartialEq, Eq)] 1081#[derive(Debug, Clone, PartialEq, Eq)]
1059pub enum ImplItemKind { 1082pub enum ImplItemKind {
1060 FnDef(FnDef), 1083 FnDef(FnDef),
@@ -1062,34 +1085,14 @@ pub enum ImplItemKind {
1062 ConstDef(ConstDef), 1085 ConstDef(ConstDef),
1063} 1086}
1064impl From<FnDef> for ImplItem { 1087impl From<FnDef> for ImplItem {
1065 fn from(n: FnDef) -> ImplItem { 1088 fn from(n: FnDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1066 ImplItem::cast(n.syntax).unwrap()
1067 }
1068} 1089}
1069impl From<TypeAliasDef> for ImplItem { 1090impl From<TypeAliasDef> for ImplItem {
1070 fn from(n: TypeAliasDef) -> ImplItem { 1091 fn from(n: TypeAliasDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1071 ImplItem::cast(n.syntax).unwrap()
1072 }
1073} 1092}
1074impl From<ConstDef> for ImplItem { 1093impl From<ConstDef> for ImplItem {
1075 fn from(n: ConstDef) -> ImplItem { 1094 fn from(n: ConstDef) -> ImplItem { ImplItem { syntax: n.syntax } }
1076 ImplItem::cast(n.syntax).unwrap()
1077 }
1078}
1079
1080
1081impl AstNode for ImplItem {
1082 fn cast(syntax: SyntaxNode) -> Option<Self> {
1083 match syntax.kind() {
1084 | FN_DEF
1085 | TYPE_ALIAS_DEF
1086 | CONST_DEF => Some(ImplItem { syntax }),
1087 _ => None,
1088 }
1089 }
1090 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1091} 1095}
1092
1093impl ImplItem { 1096impl ImplItem {
1094 pub fn kind(&self) -> ImplItemKind { 1097 pub fn kind(&self) -> ImplItemKind {
1095 match self.syntax.kind() { 1098 match self.syntax.kind() {
@@ -1110,12 +1113,15 @@ pub struct ImplTraitType {
1110} 1113}
1111 1114
1112impl AstNode for ImplTraitType { 1115impl AstNode for ImplTraitType {
1113 fn cast(syntax: SyntaxNode) -> Option<Self> { 1116 fn can_cast(kind: SyntaxKind) -> bool {
1114 match syntax.kind() { 1117 match kind {
1115 IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), 1118 IMPL_TRAIT_TYPE => true,
1116 _ => None, 1119 _ => false,
1117 } 1120 }
1118 } 1121 }
1122 fn cast(syntax: SyntaxNode) -> Option<Self> {
1123 if Self::can_cast(syntax.kind()) { Some(ImplTraitType { syntax }) } else { None }
1124 }
1119 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1125 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1120} 1126}
1121 1127
@@ -1130,12 +1136,15 @@ pub struct IndexExpr {
1130} 1136}
1131 1137
1132impl AstNode for IndexExpr { 1138impl AstNode for IndexExpr {
1133 fn cast(syntax: SyntaxNode) -> Option<Self> { 1139 fn can_cast(kind: SyntaxKind) -> bool {
1134 match syntax.kind() { 1140 match kind {
1135 INDEX_EXPR => Some(IndexExpr { syntax }), 1141 INDEX_EXPR => true,
1136 _ => None, 1142 _ => false,
1137 } 1143 }
1138 } 1144 }
1145 fn cast(syntax: SyntaxNode) -> Option<Self> {
1146 if Self::can_cast(syntax.kind()) { Some(IndexExpr { syntax }) } else { None }
1147 }
1139 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1148 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1140} 1149}
1141 1150
@@ -1149,12 +1158,15 @@ pub struct ItemList {
1149} 1158}
1150 1159
1151impl AstNode for ItemList { 1160impl AstNode for ItemList {
1152 fn cast(syntax: SyntaxNode) -> Option<Self> { 1161 fn can_cast(kind: SyntaxKind) -> bool {
1153 match syntax.kind() { 1162 match kind {
1154 ITEM_LIST => Some(ItemList { syntax }), 1163 ITEM_LIST => true,
1155 _ => None, 1164 _ => false,
1156 } 1165 }
1157 } 1166 }
1167 fn cast(syntax: SyntaxNode) -> Option<Self> {
1168 if Self::can_cast(syntax.kind()) { Some(ItemList { syntax }) } else { None }
1169 }
1158 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1170 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1159} 1171}
1160 1172
@@ -1174,12 +1186,15 @@ pub struct Label {
1174} 1186}
1175 1187
1176impl AstNode for Label { 1188impl AstNode for Label {
1177 fn cast(syntax: SyntaxNode) -> Option<Self> { 1189 fn can_cast(kind: SyntaxKind) -> bool {
1178 match syntax.kind() { 1190 match kind {
1179 LABEL => Some(Label { syntax }), 1191 LABEL => true,
1180 _ => None, 1192 _ => false,
1181 } 1193 }
1182 } 1194 }
1195 fn cast(syntax: SyntaxNode) -> Option<Self> {
1196 if Self::can_cast(syntax.kind()) { Some(Label { syntax }) } else { None }
1197 }
1183 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1198 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1184} 1199}
1185 1200
@@ -1193,12 +1208,15 @@ pub struct LambdaExpr {
1193} 1208}
1194 1209
1195impl AstNode for LambdaExpr { 1210impl AstNode for LambdaExpr {
1196 fn cast(syntax: SyntaxNode) -> Option<Self> { 1211 fn can_cast(kind: SyntaxKind) -> bool {
1197 match syntax.kind() { 1212 match kind {
1198 LAMBDA_EXPR => Some(LambdaExpr { syntax }), 1213 LAMBDA_EXPR => true,
1199 _ => None, 1214 _ => false,
1200 } 1215 }
1201 } 1216 }
1217 fn cast(syntax: SyntaxNode) -> Option<Self> {
1218 if Self::can_cast(syntax.kind()) { Some(LambdaExpr { syntax }) } else { None }
1219 }
1202 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1220 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1203} 1221}
1204 1222
@@ -1220,12 +1238,15 @@ pub struct LetStmt {
1220} 1238}
1221 1239
1222impl AstNode for LetStmt { 1240impl AstNode for LetStmt {
1223 fn cast(syntax: SyntaxNode) -> Option<Self> { 1241 fn can_cast(kind: SyntaxKind) -> bool {
1224 match syntax.kind() { 1242 match kind {
1225 LET_STMT => Some(LetStmt { syntax }), 1243 LET_STMT => true,
1226 _ => None, 1244 _ => false,
1227 } 1245 }
1228 } 1246 }
1247 fn cast(syntax: SyntaxNode) -> Option<Self> {
1248 if Self::can_cast(syntax.kind()) { Some(LetStmt { syntax }) } else { None }
1249 }
1229 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1250 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1230} 1251}
1231 1252
@@ -1248,12 +1269,15 @@ pub struct LifetimeArg {
1248} 1269}
1249 1270
1250impl AstNode for LifetimeArg { 1271impl AstNode for LifetimeArg {
1251 fn cast(syntax: SyntaxNode) -> Option<Self> { 1272 fn can_cast(kind: SyntaxKind) -> bool {
1252 match syntax.kind() { 1273 match kind {
1253 LIFETIME_ARG => Some(LifetimeArg { syntax }), 1274 LIFETIME_ARG => true,
1254 _ => None, 1275 _ => false,
1255 } 1276 }
1256 } 1277 }
1278 fn cast(syntax: SyntaxNode) -> Option<Self> {
1279 if Self::can_cast(syntax.kind()) { Some(LifetimeArg { syntax }) } else { None }
1280 }
1257 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1281 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1258} 1282}
1259 1283
@@ -1267,12 +1291,15 @@ pub struct LifetimeParam {
1267} 1291}
1268 1292
1269impl AstNode for LifetimeParam { 1293impl AstNode for LifetimeParam {
1270 fn cast(syntax: SyntaxNode) -> Option<Self> { 1294 fn can_cast(kind: SyntaxKind) -> bool {
1271 match syntax.kind() { 1295 match kind {
1272 LIFETIME_PARAM => Some(LifetimeParam { syntax }), 1296 LIFETIME_PARAM => true,
1273 _ => None, 1297 _ => false,
1274 } 1298 }
1275 } 1299 }
1300 fn cast(syntax: SyntaxNode) -> Option<Self> {
1301 if Self::can_cast(syntax.kind()) { Some(LifetimeParam { syntax }) } else { None }
1302 }
1276 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1303 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1277} 1304}
1278 1305
@@ -1287,12 +1314,15 @@ pub struct Literal {
1287} 1314}
1288 1315
1289impl AstNode for Literal { 1316impl AstNode for Literal {
1290 fn cast(syntax: SyntaxNode) -> Option<Self> { 1317 fn can_cast(kind: SyntaxKind) -> bool {
1291 match syntax.kind() { 1318 match kind {
1292 LITERAL => Some(Literal { syntax }), 1319 LITERAL => true,
1293 _ => None, 1320 _ => false,
1294 } 1321 }
1295 } 1322 }
1323 fn cast(syntax: SyntaxNode) -> Option<Self> {
1324 if Self::can_cast(syntax.kind()) { Some(Literal { syntax }) } else { None }
1325 }
1296 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1326 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1297} 1327}
1298 1328
@@ -1306,12 +1336,15 @@ pub struct LiteralPat {
1306} 1336}
1307 1337
1308impl AstNode for LiteralPat { 1338impl AstNode for LiteralPat {
1309 fn cast(syntax: SyntaxNode) -> Option<Self> { 1339 fn can_cast(kind: SyntaxKind) -> bool {
1310 match syntax.kind() { 1340 match kind {
1311 LITERAL_PAT => Some(LiteralPat { syntax }), 1341 LITERAL_PAT => true,
1312 _ => None, 1342 _ => false,
1313 } 1343 }
1314 } 1344 }
1345 fn cast(syntax: SyntaxNode) -> Option<Self> {
1346 if Self::can_cast(syntax.kind()) { Some(LiteralPat { syntax }) } else { None }
1347 }
1315 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1348 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1316} 1349}
1317 1350
@@ -1329,12 +1362,15 @@ pub struct LoopExpr {
1329} 1362}
1330 1363
1331impl AstNode for LoopExpr { 1364impl AstNode for LoopExpr {
1332 fn cast(syntax: SyntaxNode) -> Option<Self> { 1365 fn can_cast(kind: SyntaxKind) -> bool {
1333 match syntax.kind() { 1366 match kind {
1334 LOOP_EXPR => Some(LoopExpr { syntax }), 1367 LOOP_EXPR => true,
1335 _ => None, 1368 _ => false,
1336 } 1369 }
1337 } 1370 }
1371 fn cast(syntax: SyntaxNode) -> Option<Self> {
1372 if Self::can_cast(syntax.kind()) { Some(LoopExpr { syntax }) } else { None }
1373 }
1338 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1374 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1339} 1375}
1340 1376
@@ -1349,12 +1385,15 @@ pub struct MacroCall {
1349} 1385}
1350 1386
1351impl AstNode for MacroCall { 1387impl AstNode for MacroCall {
1352 fn cast(syntax: SyntaxNode) -> Option<Self> { 1388 fn can_cast(kind: SyntaxKind) -> bool {
1353 match syntax.kind() { 1389 match kind {
1354 MACRO_CALL => Some(MacroCall { syntax }), 1390 MACRO_CALL => true,
1355 _ => None, 1391 _ => false,
1356 } 1392 }
1357 } 1393 }
1394 fn cast(syntax: SyntaxNode) -> Option<Self> {
1395 if Self::can_cast(syntax.kind()) { Some(MacroCall { syntax }) } else { None }
1396 }
1358 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1397 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1359} 1398}
1360 1399
@@ -1379,12 +1418,15 @@ pub struct MacroItems {
1379} 1418}
1380 1419
1381impl AstNode for MacroItems { 1420impl AstNode for MacroItems {
1382 fn cast(syntax: SyntaxNode) -> Option<Self> { 1421 fn can_cast(kind: SyntaxKind) -> bool {
1383 match syntax.kind() { 1422 match kind {
1384 MACRO_ITEMS => Some(MacroItems { syntax }), 1423 MACRO_ITEMS => true,
1385 _ => None, 1424 _ => false,
1386 } 1425 }
1387 } 1426 }
1427 fn cast(syntax: SyntaxNode) -> Option<Self> {
1428 if Self::can_cast(syntax.kind()) { Some(MacroItems { syntax }) } else { None }
1429 }
1388 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1430 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1389} 1431}
1390 1432
@@ -1400,12 +1442,15 @@ pub struct MacroStmts {
1400} 1442}
1401 1443
1402impl AstNode for MacroStmts { 1444impl AstNode for MacroStmts {
1403 fn cast(syntax: SyntaxNode) -> Option<Self> { 1445 fn can_cast(kind: SyntaxKind) -> bool {
1404 match syntax.kind() { 1446 match kind {
1405 MACRO_STMTS => Some(MacroStmts { syntax }), 1447 MACRO_STMTS => true,
1406 _ => None, 1448 _ => false,
1407 } 1449 }
1408 } 1450 }
1451 fn cast(syntax: SyntaxNode) -> Option<Self> {
1452 if Self::can_cast(syntax.kind()) { Some(MacroStmts { syntax }) } else { None }
1453 }
1409 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1454 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1410} 1455}
1411 1456
@@ -1427,12 +1472,15 @@ pub struct MatchArm {
1427} 1472}
1428 1473
1429impl AstNode for MatchArm { 1474impl AstNode for MatchArm {
1430 fn cast(syntax: SyntaxNode) -> Option<Self> { 1475 fn can_cast(kind: SyntaxKind) -> bool {
1431 match syntax.kind() { 1476 match kind {
1432 MATCH_ARM => Some(MatchArm { syntax }), 1477 MATCH_ARM => true,
1433 _ => None, 1478 _ => false,
1434 } 1479 }
1435 } 1480 }
1481 fn cast(syntax: SyntaxNode) -> Option<Self> {
1482 if Self::can_cast(syntax.kind()) { Some(MatchArm { syntax }) } else { None }
1483 }
1436 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1484 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1437} 1485}
1438 1486
@@ -1459,12 +1507,15 @@ pub struct MatchArmList {
1459} 1507}
1460 1508
1461impl AstNode for MatchArmList { 1509impl AstNode for MatchArmList {
1462 fn cast(syntax: SyntaxNode) -> Option<Self> { 1510 fn can_cast(kind: SyntaxKind) -> bool {
1463 match syntax.kind() { 1511 match kind {
1464 MATCH_ARM_LIST => Some(MatchArmList { syntax }), 1512 MATCH_ARM_LIST => true,
1465 _ => None, 1513 _ => false,
1466 } 1514 }
1467 } 1515 }
1516 fn cast(syntax: SyntaxNode) -> Option<Self> {
1517 if Self::can_cast(syntax.kind()) { Some(MatchArmList { syntax }) } else { None }
1518 }
1468 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1519 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1469} 1520}
1470 1521
@@ -1483,12 +1534,15 @@ pub struct MatchExpr {
1483} 1534}
1484 1535
1485impl AstNode for MatchExpr { 1536impl AstNode for MatchExpr {
1486 fn cast(syntax: SyntaxNode) -> Option<Self> { 1537 fn can_cast(kind: SyntaxKind) -> bool {
1487 match syntax.kind() { 1538 match kind {
1488 MATCH_EXPR => Some(MatchExpr { syntax }), 1539 MATCH_EXPR => true,
1489 _ => None, 1540 _ => false,
1490 } 1541 }
1491 } 1542 }
1543 fn cast(syntax: SyntaxNode) -> Option<Self> {
1544 if Self::can_cast(syntax.kind()) { Some(MatchExpr { syntax }) } else { None }
1545 }
1492 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1546 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1493} 1547}
1494 1548
@@ -1510,12 +1564,15 @@ pub struct MatchGuard {
1510} 1564}
1511 1565
1512impl AstNode for MatchGuard { 1566impl AstNode for MatchGuard {
1513 fn cast(syntax: SyntaxNode) -> Option<Self> { 1567 fn can_cast(kind: SyntaxKind) -> bool {
1514 match syntax.kind() { 1568 match kind {
1515 MATCH_GUARD => Some(MatchGuard { syntax }), 1569 MATCH_GUARD => true,
1516 _ => None, 1570 _ => false,
1517 } 1571 }
1518 } 1572 }
1573 fn cast(syntax: SyntaxNode) -> Option<Self> {
1574 if Self::can_cast(syntax.kind()) { Some(MatchGuard { syntax }) } else { None }
1575 }
1519 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1576 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1520} 1577}
1521 1578
@@ -1533,12 +1590,15 @@ pub struct MethodCallExpr {
1533} 1590}
1534 1591
1535impl AstNode for MethodCallExpr { 1592impl AstNode for MethodCallExpr {
1536 fn cast(syntax: SyntaxNode) -> Option<Self> { 1593 fn can_cast(kind: SyntaxKind) -> bool {
1537 match syntax.kind() { 1594 match kind {
1538 METHOD_CALL_EXPR => Some(MethodCallExpr { syntax }), 1595 METHOD_CALL_EXPR => true,
1539 _ => None, 1596 _ => false,
1540 } 1597 }
1541 } 1598 }
1599 fn cast(syntax: SyntaxNode) -> Option<Self> {
1600 if Self::can_cast(syntax.kind()) { Some(MethodCallExpr { syntax }) } else { None }
1601 }
1542 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1602 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1543} 1603}
1544 1604
@@ -1565,12 +1625,15 @@ pub struct Module {
1565} 1625}
1566 1626
1567impl AstNode for Module { 1627impl AstNode for Module {
1568 fn cast(syntax: SyntaxNode) -> Option<Self> { 1628 fn can_cast(kind: SyntaxKind) -> bool {
1569 match syntax.kind() { 1629 match kind {
1570 MODULE => Some(Module { syntax }), 1630 MODULE => true,
1571 _ => None, 1631 _ => false,
1572 } 1632 }
1573 } 1633 }
1634 fn cast(syntax: SyntaxNode) -> Option<Self> {
1635 if Self::can_cast(syntax.kind()) { Some(Module { syntax }) } else { None }
1636 }
1574 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1637 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1575} 1638}
1576 1639
@@ -1591,6 +1654,20 @@ pub struct ModuleItem {
1591 pub(crate) syntax: SyntaxNode, 1654 pub(crate) syntax: SyntaxNode,
1592} 1655}
1593 1656
1657impl AstNode for ModuleItem {
1658 fn can_cast(kind: SyntaxKind) -> bool {
1659 match kind {
1660 | STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
1661 _ => false,
1662 }
1663 }
1664 fn cast(syntax: SyntaxNode) -> Option<Self> {
1665 if Self::can_cast(syntax.kind()) { Some(ModuleItem { syntax }) } else { None }
1666 }
1667 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1668}
1669
1670
1594#[derive(Debug, Clone, PartialEq, Eq)] 1671#[derive(Debug, Clone, PartialEq, Eq)]
1595pub enum ModuleItemKind { 1672pub enum ModuleItemKind {
1596 StructDef(StructDef), 1673 StructDef(StructDef),
@@ -1606,82 +1683,38 @@ pub enum ModuleItemKind {
1606 Module(Module), 1683 Module(Module),
1607} 1684}
1608impl From<StructDef> for ModuleItem { 1685impl From<StructDef> for ModuleItem {
1609 fn from(n: StructDef) -> ModuleItem { 1686 fn from(n: StructDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1610 ModuleItem::cast(n.syntax).unwrap()
1611 }
1612} 1687}
1613impl From<EnumDef> for ModuleItem { 1688impl From<EnumDef> for ModuleItem {
1614 fn from(n: EnumDef) -> ModuleItem { 1689 fn from(n: EnumDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1615 ModuleItem::cast(n.syntax).unwrap()
1616 }
1617} 1690}
1618impl From<FnDef> for ModuleItem { 1691impl From<FnDef> for ModuleItem {
1619 fn from(n: FnDef) -> ModuleItem { 1692 fn from(n: FnDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1620 ModuleItem::cast(n.syntax).unwrap()
1621 }
1622} 1693}
1623impl From<TraitDef> for ModuleItem { 1694impl From<TraitDef> for ModuleItem {
1624 fn from(n: TraitDef) -> ModuleItem { 1695 fn from(n: TraitDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1625 ModuleItem::cast(n.syntax).unwrap()
1626 }
1627} 1696}
1628impl From<TypeAliasDef> for ModuleItem { 1697impl From<TypeAliasDef> for ModuleItem {
1629 fn from(n: TypeAliasDef) -> ModuleItem { 1698 fn from(n: TypeAliasDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1630 ModuleItem::cast(n.syntax).unwrap()
1631 }
1632} 1699}
1633impl From<ImplBlock> for ModuleItem { 1700impl From<ImplBlock> for ModuleItem {
1634 fn from(n: ImplBlock) -> ModuleItem { 1701 fn from(n: ImplBlock) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1635 ModuleItem::cast(n.syntax).unwrap()
1636 }
1637} 1702}
1638impl From<UseItem> for ModuleItem { 1703impl From<UseItem> for ModuleItem {
1639 fn from(n: UseItem) -> ModuleItem { 1704 fn from(n: UseItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1640 ModuleItem::cast(n.syntax).unwrap()
1641 }
1642} 1705}
1643impl From<ExternCrateItem> for ModuleItem { 1706impl From<ExternCrateItem> for ModuleItem {
1644 fn from(n: ExternCrateItem) -> ModuleItem { 1707 fn from(n: ExternCrateItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1645 ModuleItem::cast(n.syntax).unwrap()
1646 }
1647} 1708}
1648impl From<ConstDef> for ModuleItem { 1709impl From<ConstDef> for ModuleItem {
1649 fn from(n: ConstDef) -> ModuleItem { 1710 fn from(n: ConstDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1650 ModuleItem::cast(n.syntax).unwrap()
1651 }
1652} 1711}
1653impl From<StaticDef> for ModuleItem { 1712impl From<StaticDef> for ModuleItem {
1654 fn from(n: StaticDef) -> ModuleItem { 1713 fn from(n: StaticDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1655 ModuleItem::cast(n.syntax).unwrap()
1656 }
1657} 1714}
1658impl From<Module> for ModuleItem { 1715impl From<Module> for ModuleItem {
1659 fn from(n: Module) -> ModuleItem { 1716 fn from(n: Module) -> ModuleItem { ModuleItem { syntax: n.syntax } }
1660 ModuleItem::cast(n.syntax).unwrap()
1661 }
1662}
1663
1664
1665impl AstNode for ModuleItem {
1666 fn cast(syntax: SyntaxNode) -> Option<Self> {
1667 match syntax.kind() {
1668 | STRUCT_DEF
1669 | ENUM_DEF
1670 | FN_DEF
1671 | TRAIT_DEF
1672 | TYPE_ALIAS_DEF
1673 | IMPL_BLOCK
1674 | USE_ITEM
1675 | EXTERN_CRATE_ITEM
1676 | CONST_DEF
1677 | STATIC_DEF
1678 | MODULE => Some(ModuleItem { syntax }),
1679 _ => None,
1680 }
1681 }
1682 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1683} 1717}
1684
1685impl ModuleItem { 1718impl ModuleItem {
1686 pub fn kind(&self) -> ModuleItemKind { 1719 pub fn kind(&self) -> ModuleItemKind {
1687 match self.syntax.kind() { 1720 match self.syntax.kind() {
@@ -1710,12 +1743,15 @@ pub struct Name {
1710} 1743}
1711 1744
1712impl AstNode for Name { 1745impl AstNode for Name {
1713 fn cast(syntax: SyntaxNode) -> Option<Self> { 1746 fn can_cast(kind: SyntaxKind) -> bool {
1714 match syntax.kind() { 1747 match kind {
1715 NAME => Some(Name { syntax }), 1748 NAME => true,
1716 _ => None, 1749 _ => false,
1717 } 1750 }
1718 } 1751 }
1752 fn cast(syntax: SyntaxNode) -> Option<Self> {
1753 if Self::can_cast(syntax.kind()) { Some(Name { syntax }) } else { None }
1754 }
1719 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1755 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1720} 1756}
1721 1757
@@ -1729,12 +1765,15 @@ pub struct NameRef {
1729} 1765}
1730 1766
1731impl AstNode for NameRef { 1767impl AstNode for NameRef {
1732 fn cast(syntax: SyntaxNode) -> Option<Self> { 1768 fn can_cast(kind: SyntaxKind) -> bool {
1733 match syntax.kind() { 1769 match kind {
1734 NAME_REF => Some(NameRef { syntax }), 1770 NAME_REF => true,
1735 _ => None, 1771 _ => false,
1736 } 1772 }
1737 } 1773 }
1774 fn cast(syntax: SyntaxNode) -> Option<Self> {
1775 if Self::can_cast(syntax.kind()) { Some(NameRef { syntax }) } else { None }
1776 }
1738 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1777 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1739} 1778}
1740 1779
@@ -1748,12 +1787,15 @@ pub struct NamedField {
1748} 1787}
1749 1788
1750impl AstNode for NamedField { 1789impl AstNode for NamedField {
1751 fn cast(syntax: SyntaxNode) -> Option<Self> { 1790 fn can_cast(kind: SyntaxKind) -> bool {
1752 match syntax.kind() { 1791 match kind {
1753 NAMED_FIELD => Some(NamedField { syntax }), 1792 NAMED_FIELD => true,
1754 _ => None, 1793 _ => false,
1755 } 1794 }
1756 } 1795 }
1796 fn cast(syntax: SyntaxNode) -> Option<Self> {
1797 if Self::can_cast(syntax.kind()) { Some(NamedField { syntax }) } else { None }
1798 }
1757 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1799 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1758} 1800}
1759 1801
@@ -1775,12 +1817,15 @@ pub struct NamedFieldDef {
1775} 1817}
1776 1818
1777impl AstNode for NamedFieldDef { 1819impl AstNode for NamedFieldDef {
1778 fn cast(syntax: SyntaxNode) -> Option<Self> { 1820 fn can_cast(kind: SyntaxKind) -> bool {
1779 match syntax.kind() { 1821 match kind {
1780 NAMED_FIELD_DEF => Some(NamedFieldDef { syntax }), 1822 NAMED_FIELD_DEF => true,
1781 _ => None, 1823 _ => false,
1782 } 1824 }
1783 } 1825 }
1826 fn cast(syntax: SyntaxNode) -> Option<Self> {
1827 if Self::can_cast(syntax.kind()) { Some(NamedFieldDef { syntax }) } else { None }
1828 }
1784 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1829 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1785} 1830}
1786 1831
@@ -1799,12 +1844,15 @@ pub struct NamedFieldDefList {
1799} 1844}
1800 1845
1801impl AstNode for NamedFieldDefList { 1846impl AstNode for NamedFieldDefList {
1802 fn cast(syntax: SyntaxNode) -> Option<Self> { 1847 fn can_cast(kind: SyntaxKind) -> bool {
1803 match syntax.kind() { 1848 match kind {
1804 NAMED_FIELD_DEF_LIST => Some(NamedFieldDefList { syntax }), 1849 NAMED_FIELD_DEF_LIST => true,
1805 _ => None, 1850 _ => false,
1806 } 1851 }
1807 } 1852 }
1853 fn cast(syntax: SyntaxNode) -> Option<Self> {
1854 if Self::can_cast(syntax.kind()) { Some(NamedFieldDefList { syntax }) } else { None }
1855 }
1808 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1856 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1809} 1857}
1810 1858
@@ -1822,12 +1870,15 @@ pub struct NamedFieldList {
1822} 1870}
1823 1871
1824impl AstNode for NamedFieldList { 1872impl AstNode for NamedFieldList {
1825 fn cast(syntax: SyntaxNode) -> Option<Self> { 1873 fn can_cast(kind: SyntaxKind) -> bool {
1826 match syntax.kind() { 1874 match kind {
1827 NAMED_FIELD_LIST => Some(NamedFieldList { syntax }), 1875 NAMED_FIELD_LIST => true,
1828 _ => None, 1876 _ => false,
1829 } 1877 }
1830 } 1878 }
1879 fn cast(syntax: SyntaxNode) -> Option<Self> {
1880 if Self::can_cast(syntax.kind()) { Some(NamedFieldList { syntax }) } else { None }
1881 }
1831 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1882 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1832} 1883}
1833 1884
@@ -1849,12 +1900,15 @@ pub struct NeverType {
1849} 1900}
1850 1901
1851impl AstNode for NeverType { 1902impl AstNode for NeverType {
1852 fn cast(syntax: SyntaxNode) -> Option<Self> { 1903 fn can_cast(kind: SyntaxKind) -> bool {
1853 match syntax.kind() { 1904 match kind {
1854 NEVER_TYPE => Some(NeverType { syntax }), 1905 NEVER_TYPE => true,
1855 _ => None, 1906 _ => false,
1856 } 1907 }
1857 } 1908 }
1909 fn cast(syntax: SyntaxNode) -> Option<Self> {
1910 if Self::can_cast(syntax.kind()) { Some(NeverType { syntax }) } else { None }
1911 }
1858 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1912 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1859} 1913}
1860 1914
@@ -1867,34 +1921,31 @@ pub struct NominalDef {
1867 pub(crate) syntax: SyntaxNode, 1921 pub(crate) syntax: SyntaxNode,
1868} 1922}
1869 1923
1924impl AstNode for NominalDef {
1925 fn can_cast(kind: SyntaxKind) -> bool {
1926 match kind {
1927 | STRUCT_DEF | ENUM_DEF => true,
1928 _ => false,
1929 }
1930 }
1931 fn cast(syntax: SyntaxNode) -> Option<Self> {
1932 if Self::can_cast(syntax.kind()) { Some(NominalDef { syntax }) } else { None }
1933 }
1934 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1935}
1936
1937
1870#[derive(Debug, Clone, PartialEq, Eq)] 1938#[derive(Debug, Clone, PartialEq, Eq)]
1871pub enum NominalDefKind { 1939pub enum NominalDefKind {
1872 StructDef(StructDef), 1940 StructDef(StructDef),
1873 EnumDef(EnumDef), 1941 EnumDef(EnumDef),
1874} 1942}
1875impl From<StructDef> for NominalDef { 1943impl From<StructDef> for NominalDef {
1876 fn from(n: StructDef) -> NominalDef { 1944 fn from(n: StructDef) -> NominalDef { NominalDef { syntax: n.syntax } }
1877 NominalDef::cast(n.syntax).unwrap()
1878 }
1879} 1945}
1880impl From<EnumDef> for NominalDef { 1946impl From<EnumDef> for NominalDef {
1881 fn from(n: EnumDef) -> NominalDef { 1947 fn from(n: EnumDef) -> NominalDef { NominalDef { syntax: n.syntax } }
1882 NominalDef::cast(n.syntax).unwrap()
1883 }
1884}
1885
1886
1887impl AstNode for NominalDef {
1888 fn cast(syntax: SyntaxNode) -> Option<Self> {
1889 match syntax.kind() {
1890 | STRUCT_DEF
1891 | ENUM_DEF => Some(NominalDef { syntax }),
1892 _ => None,
1893 }
1894 }
1895 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1896} 1948}
1897
1898impl NominalDef { 1949impl NominalDef {
1899 pub fn kind(&self) -> NominalDefKind { 1950 pub fn kind(&self) -> NominalDefKind {
1900 match self.syntax.kind() { 1951 match self.syntax.kind() {
@@ -1917,12 +1968,15 @@ pub struct Param {
1917} 1968}
1918 1969
1919impl AstNode for Param { 1970impl AstNode for Param {
1920 fn cast(syntax: SyntaxNode) -> Option<Self> { 1971 fn can_cast(kind: SyntaxKind) -> bool {
1921 match syntax.kind() { 1972 match kind {
1922 PARAM => Some(Param { syntax }), 1973 PARAM => true,
1923 _ => None, 1974 _ => false,
1924 } 1975 }
1925 } 1976 }
1977 fn cast(syntax: SyntaxNode) -> Option<Self> {
1978 if Self::can_cast(syntax.kind()) { Some(Param { syntax }) } else { None }
1979 }
1926 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1980 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1927} 1981}
1928 1982
@@ -1941,12 +1995,15 @@ pub struct ParamList {
1941} 1995}
1942 1996
1943impl AstNode for ParamList { 1997impl AstNode for ParamList {
1944 fn cast(syntax: SyntaxNode) -> Option<Self> { 1998 fn can_cast(kind: SyntaxKind) -> bool {
1945 match syntax.kind() { 1999 match kind {
1946 PARAM_LIST => Some(ParamList { syntax }), 2000 PARAM_LIST => true,
1947 _ => None, 2001 _ => false,
1948 } 2002 }
1949 } 2003 }
2004 fn cast(syntax: SyntaxNode) -> Option<Self> {
2005 if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None }
2006 }
1950 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2007 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1951} 2008}
1952 2009
@@ -1968,12 +2025,15 @@ pub struct ParenExpr {
1968} 2025}
1969 2026
1970impl AstNode for ParenExpr { 2027impl AstNode for ParenExpr {
1971 fn cast(syntax: SyntaxNode) -> Option<Self> { 2028 fn can_cast(kind: SyntaxKind) -> bool {
1972 match syntax.kind() { 2029 match kind {
1973 PAREN_EXPR => Some(ParenExpr { syntax }), 2030 PAREN_EXPR => true,
1974 _ => None, 2031 _ => false,
1975 } 2032 }
1976 } 2033 }
2034 fn cast(syntax: SyntaxNode) -> Option<Self> {
2035 if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None }
2036 }
1977 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2037 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1978} 2038}
1979 2039
@@ -1991,12 +2051,15 @@ pub struct ParenType {
1991} 2051}
1992 2052
1993impl AstNode for ParenType { 2053impl AstNode for ParenType {
1994 fn cast(syntax: SyntaxNode) -> Option<Self> { 2054 fn can_cast(kind: SyntaxKind) -> bool {
1995 match syntax.kind() { 2055 match kind {
1996 PAREN_TYPE => Some(ParenType { syntax }), 2056 PAREN_TYPE => true,
1997 _ => None, 2057 _ => false,
1998 } 2058 }
1999 } 2059 }
2060 fn cast(syntax: SyntaxNode) -> Option<Self> {
2061 if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None }
2062 }
2000 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2063 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2001} 2064}
2002 2065
@@ -2013,6 +2076,20 @@ pub struct Pat {
2013 pub(crate) syntax: SyntaxNode, 2076 pub(crate) syntax: SyntaxNode,
2014} 2077}
2015 2078
2079impl AstNode for Pat {
2080 fn can_cast(kind: SyntaxKind) -> bool {
2081 match kind {
2082 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
2083 _ => false,
2084 }
2085 }
2086 fn cast(syntax: SyntaxNode) -> Option<Self> {
2087 if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None }
2088 }
2089 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2090}
2091
2092
2016#[derive(Debug, Clone, PartialEq, Eq)] 2093#[derive(Debug, Clone, PartialEq, Eq)]
2017pub enum PatKind { 2094pub enum PatKind {
2018 RefPat(RefPat), 2095 RefPat(RefPat),
@@ -2027,76 +2104,35 @@ pub enum PatKind {
2027 LiteralPat(LiteralPat), 2104 LiteralPat(LiteralPat),
2028} 2105}
2029impl From<RefPat> for Pat { 2106impl From<RefPat> for Pat {
2030 fn from(n: RefPat) -> Pat { 2107 fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } }
2031 Pat::cast(n.syntax).unwrap()
2032 }
2033} 2108}
2034impl From<BindPat> for Pat { 2109impl From<BindPat> for Pat {
2035 fn from(n: BindPat) -> Pat { 2110 fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } }
2036 Pat::cast(n.syntax).unwrap()
2037 }
2038} 2111}
2039impl From<PlaceholderPat> for Pat { 2112impl From<PlaceholderPat> for Pat {
2040 fn from(n: PlaceholderPat) -> Pat { 2113 fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } }
2041 Pat::cast(n.syntax).unwrap()
2042 }
2043} 2114}
2044impl From<PathPat> for Pat { 2115impl From<PathPat> for Pat {
2045 fn from(n: PathPat) -> Pat { 2116 fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } }
2046 Pat::cast(n.syntax).unwrap()
2047 }
2048} 2117}
2049impl From<StructPat> for Pat { 2118impl From<StructPat> for Pat {
2050 fn from(n: StructPat) -> Pat { 2119 fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } }
2051 Pat::cast(n.syntax).unwrap()
2052 }
2053} 2120}
2054impl From<TupleStructPat> for Pat { 2121impl From<TupleStructPat> for Pat {
2055 fn from(n: TupleStructPat) -> Pat { 2122 fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } }
2056 Pat::cast(n.syntax).unwrap()
2057 }
2058} 2123}
2059impl From<TuplePat> for Pat { 2124impl From<TuplePat> for Pat {
2060 fn from(n: TuplePat) -> Pat { 2125 fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } }
2061 Pat::cast(n.syntax).unwrap()
2062 }
2063} 2126}
2064impl From<SlicePat> for Pat { 2127impl From<SlicePat> for Pat {
2065 fn from(n: SlicePat) -> Pat { 2128 fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } }
2066 Pat::cast(n.syntax).unwrap()
2067 }
2068} 2129}
2069impl From<RangePat> for Pat { 2130impl From<RangePat> for Pat {
2070 fn from(n: RangePat) -> Pat { 2131 fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } }
2071 Pat::cast(n.syntax).unwrap()
2072 }
2073} 2132}
2074impl From<LiteralPat> for Pat { 2133impl From<LiteralPat> for Pat {
2075 fn from(n: LiteralPat) -> Pat { 2134 fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } }
2076 Pat::cast(n.syntax).unwrap()
2077 }
2078}
2079
2080
2081impl AstNode for Pat {
2082 fn cast(syntax: SyntaxNode) -> Option<Self> {
2083 match syntax.kind() {
2084 | REF_PAT
2085 | BIND_PAT
2086 | PLACEHOLDER_PAT
2087 | PATH_PAT
2088 | STRUCT_PAT
2089 | TUPLE_STRUCT_PAT
2090 | TUPLE_PAT
2091 | SLICE_PAT
2092 | RANGE_PAT
2093 | LITERAL_PAT => Some(Pat { syntax }),
2094 _ => None,
2095 }
2096 }
2097 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2098} 2135}
2099
2100impl Pat { 2136impl Pat {
2101 pub fn kind(&self) -> PatKind { 2137 pub fn kind(&self) -> PatKind {
2102 match self.syntax.kind() { 2138 match self.syntax.kind() {
@@ -2124,12 +2160,15 @@ pub struct Path {
2124} 2160}
2125 2161
2126impl AstNode for Path { 2162impl AstNode for Path {
2127 fn cast(syntax: SyntaxNode) -> Option<Self> { 2163 fn can_cast(kind: SyntaxKind) -> bool {
2128 match syntax.kind() { 2164 match kind {
2129 PATH => Some(Path { syntax }), 2165 PATH => true,
2130 _ => None, 2166 _ => false,
2131 } 2167 }
2132 } 2168 }
2169 fn cast(syntax: SyntaxNode) -> Option<Self> {
2170 if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None }
2171 }
2133 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2172 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2134} 2173}
2135 2174
@@ -2151,12 +2190,15 @@ pub struct PathExpr {
2151} 2190}
2152 2191
2153impl AstNode for PathExpr { 2192impl AstNode for PathExpr {
2154 fn cast(syntax: SyntaxNode) -> Option<Self> { 2193 fn can_cast(kind: SyntaxKind) -> bool {
2155 match syntax.kind() { 2194 match kind {
2156 PATH_EXPR => Some(PathExpr { syntax }), 2195 PATH_EXPR => true,
2157 _ => None, 2196 _ => false,
2158 } 2197 }
2159 } 2198 }
2199 fn cast(syntax: SyntaxNode) -> Option<Self> {
2200 if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None }
2201 }
2160 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2202 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2161} 2203}
2162 2204
@@ -2174,12 +2216,15 @@ pub struct PathPat {
2174} 2216}
2175 2217
2176impl AstNode for PathPat { 2218impl AstNode for PathPat {
2177 fn cast(syntax: SyntaxNode) -> Option<Self> { 2219 fn can_cast(kind: SyntaxKind) -> bool {
2178 match syntax.kind() { 2220 match kind {
2179 PATH_PAT => Some(PathPat { syntax }), 2221 PATH_PAT => true,
2180 _ => None, 2222 _ => false,
2181 } 2223 }
2182 } 2224 }
2225 fn cast(syntax: SyntaxNode) -> Option<Self> {
2226 if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None }
2227 }
2183 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2228 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2184} 2229}
2185 2230
@@ -2197,12 +2242,15 @@ pub struct PathSegment {
2197} 2242}
2198 2243
2199impl AstNode for PathSegment { 2244impl AstNode for PathSegment {
2200 fn cast(syntax: SyntaxNode) -> Option<Self> { 2245 fn can_cast(kind: SyntaxKind) -> bool {
2201 match syntax.kind() { 2246 match kind {
2202 PATH_SEGMENT => Some(PathSegment { syntax }), 2247 PATH_SEGMENT => true,
2203 _ => None, 2248 _ => false,
2204 } 2249 }
2205 } 2250 }
2251 fn cast(syntax: SyntaxNode) -> Option<Self> {
2252 if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None }
2253 }
2206 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2254 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2207} 2255}
2208 2256
@@ -2224,12 +2272,15 @@ pub struct PathType {
2224} 2272}
2225 2273
2226impl AstNode for PathType { 2274impl AstNode for PathType {
2227 fn cast(syntax: SyntaxNode) -> Option<Self> { 2275 fn can_cast(kind: SyntaxKind) -> bool {
2228 match syntax.kind() { 2276 match kind {
2229 PATH_TYPE => Some(PathType { syntax }), 2277 PATH_TYPE => true,
2230 _ => None, 2278 _ => false,
2231 } 2279 }
2232 } 2280 }
2281 fn cast(syntax: SyntaxNode) -> Option<Self> {
2282 if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None }
2283 }
2233 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2284 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2234} 2285}
2235 2286
@@ -2247,12 +2298,15 @@ pub struct PlaceholderPat {
2247} 2298}
2248 2299
2249impl AstNode for PlaceholderPat { 2300impl AstNode for PlaceholderPat {
2250 fn cast(syntax: SyntaxNode) -> Option<Self> { 2301 fn can_cast(kind: SyntaxKind) -> bool {
2251 match syntax.kind() { 2302 match kind {
2252 PLACEHOLDER_PAT => Some(PlaceholderPat { syntax }), 2303 PLACEHOLDER_PAT => true,
2253 _ => None, 2304 _ => false,
2254 } 2305 }
2255 } 2306 }
2307 fn cast(syntax: SyntaxNode) -> Option<Self> {
2308 if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None }
2309 }
2256 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2310 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2257} 2311}
2258 2312
@@ -2266,12 +2320,15 @@ pub struct PlaceholderType {
2266} 2320}
2267 2321
2268impl AstNode for PlaceholderType { 2322impl AstNode for PlaceholderType {
2269 fn cast(syntax: SyntaxNode) -> Option<Self> { 2323 fn can_cast(kind: SyntaxKind) -> bool {
2270 match syntax.kind() { 2324 match kind {
2271 PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), 2325 PLACEHOLDER_TYPE => true,
2272 _ => None, 2326 _ => false,
2273 } 2327 }
2274 } 2328 }
2329 fn cast(syntax: SyntaxNode) -> Option<Self> {
2330 if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None }
2331 }
2275 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2332 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2276} 2333}
2277 2334
@@ -2285,12 +2342,15 @@ pub struct PointerType {
2285} 2342}
2286 2343
2287impl AstNode for PointerType { 2344impl AstNode for PointerType {
2288 fn cast(syntax: SyntaxNode) -> Option<Self> { 2345 fn can_cast(kind: SyntaxKind) -> bool {
2289 match syntax.kind() { 2346 match kind {
2290 POINTER_TYPE => Some(PointerType { syntax }), 2347 POINTER_TYPE => true,
2291 _ => None, 2348 _ => false,
2292 } 2349 }
2293 } 2350 }
2351 fn cast(syntax: SyntaxNode) -> Option<Self> {
2352 if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None }
2353 }
2294 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2354 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2295} 2355}
2296 2356
@@ -2308,12 +2368,15 @@ pub struct PosFieldDef {
2308} 2368}
2309 2369
2310impl AstNode for PosFieldDef { 2370impl AstNode for PosFieldDef {
2311 fn cast(syntax: SyntaxNode) -> Option<Self> { 2371 fn can_cast(kind: SyntaxKind) -> bool {
2312 match syntax.kind() { 2372 match kind {
2313 POS_FIELD_DEF => Some(PosFieldDef { syntax }), 2373 POS_FIELD_DEF => true,
2314 _ => None, 2374 _ => false,
2315 } 2375 }
2316 } 2376 }
2377 fn cast(syntax: SyntaxNode) -> Option<Self> {
2378 if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None }
2379 }
2317 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2380 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2318} 2381}
2319 2382
@@ -2333,12 +2396,15 @@ pub struct PosFieldDefList {
2333} 2396}
2334 2397
2335impl AstNode for PosFieldDefList { 2398impl AstNode for PosFieldDefList {
2336 fn cast(syntax: SyntaxNode) -> Option<Self> { 2399 fn can_cast(kind: SyntaxKind) -> bool {
2337 match syntax.kind() { 2400 match kind {
2338 POS_FIELD_DEF_LIST => Some(PosFieldDefList { syntax }), 2401 POS_FIELD_DEF_LIST => true,
2339 _ => None, 2402 _ => false,
2340 } 2403 }
2341 } 2404 }
2405 fn cast(syntax: SyntaxNode) -> Option<Self> {
2406 if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None }
2407 }
2342 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2408 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2343} 2409}
2344 2410
@@ -2356,12 +2422,15 @@ pub struct PrefixExpr {
2356} 2422}
2357 2423
2358impl AstNode for PrefixExpr { 2424impl AstNode for PrefixExpr {
2359 fn cast(syntax: SyntaxNode) -> Option<Self> { 2425 fn can_cast(kind: SyntaxKind) -> bool {
2360 match syntax.kind() { 2426 match kind {
2361 PREFIX_EXPR => Some(PrefixExpr { syntax }), 2427 PREFIX_EXPR => true,
2362 _ => None, 2428 _ => false,
2363 } 2429 }
2364 } 2430 }
2431 fn cast(syntax: SyntaxNode) -> Option<Self> {
2432 if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None }
2433 }
2365 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2434 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2366} 2435}
2367 2436
@@ -2379,12 +2448,15 @@ pub struct RangeExpr {
2379} 2448}
2380 2449
2381impl AstNode for RangeExpr { 2450impl AstNode for RangeExpr {
2382 fn cast(syntax: SyntaxNode) -> Option<Self> { 2451 fn can_cast(kind: SyntaxKind) -> bool {
2383 match syntax.kind() { 2452 match kind {
2384 RANGE_EXPR => Some(RangeExpr { syntax }), 2453 RANGE_EXPR => true,
2385 _ => None, 2454 _ => false,
2386 } 2455 }
2387 } 2456 }
2457 fn cast(syntax: SyntaxNode) -> Option<Self> {
2458 if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None }
2459 }
2388 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2460 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2389} 2461}
2390 2462
@@ -2398,12 +2470,15 @@ pub struct RangePat {
2398} 2470}
2399 2471
2400impl AstNode for RangePat { 2472impl AstNode for RangePat {
2401 fn cast(syntax: SyntaxNode) -> Option<Self> { 2473 fn can_cast(kind: SyntaxKind) -> bool {
2402 match syntax.kind() { 2474 match kind {
2403 RANGE_PAT => Some(RangePat { syntax }), 2475 RANGE_PAT => true,
2404 _ => None, 2476 _ => false,
2405 } 2477 }
2406 } 2478 }
2479 fn cast(syntax: SyntaxNode) -> Option<Self> {
2480 if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None }
2481 }
2407 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2482 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2408} 2483}
2409 2484
@@ -2417,12 +2492,15 @@ pub struct RefExpr {
2417} 2492}
2418 2493
2419impl AstNode for RefExpr { 2494impl AstNode for RefExpr {
2420 fn cast(syntax: SyntaxNode) -> Option<Self> { 2495 fn can_cast(kind: SyntaxKind) -> bool {
2421 match syntax.kind() { 2496 match kind {
2422 REF_EXPR => Some(RefExpr { syntax }), 2497 REF_EXPR => true,
2423 _ => None, 2498 _ => false,
2424 } 2499 }
2425 } 2500 }
2501 fn cast(syntax: SyntaxNode) -> Option<Self> {
2502 if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None }
2503 }
2426 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2504 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2427} 2505}
2428 2506
@@ -2440,12 +2518,15 @@ pub struct RefPat {
2440} 2518}
2441 2519
2442impl AstNode for RefPat { 2520impl AstNode for RefPat {
2443 fn cast(syntax: SyntaxNode) -> Option<Self> { 2521 fn can_cast(kind: SyntaxKind) -> bool {
2444 match syntax.kind() { 2522 match kind {
2445 REF_PAT => Some(RefPat { syntax }), 2523 REF_PAT => true,
2446 _ => None, 2524 _ => false,
2447 } 2525 }
2448 } 2526 }
2527 fn cast(syntax: SyntaxNode) -> Option<Self> {
2528 if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None }
2529 }
2449 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2530 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2450} 2531}
2451 2532
@@ -2463,12 +2544,15 @@ pub struct ReferenceType {
2463} 2544}
2464 2545
2465impl AstNode for ReferenceType { 2546impl AstNode for ReferenceType {
2466 fn cast(syntax: SyntaxNode) -> Option<Self> { 2547 fn can_cast(kind: SyntaxKind) -> bool {
2467 match syntax.kind() { 2548 match kind {
2468 REFERENCE_TYPE => Some(ReferenceType { syntax }), 2549 REFERENCE_TYPE => true,
2469 _ => None, 2550 _ => false,
2470 } 2551 }
2471 } 2552 }
2553 fn cast(syntax: SyntaxNode) -> Option<Self> {
2554 if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None }
2555 }
2472 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2556 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2473} 2557}
2474 2558
@@ -2486,12 +2570,15 @@ pub struct RetType {
2486} 2570}
2487 2571
2488impl AstNode for RetType { 2572impl AstNode for RetType {
2489 fn cast(syntax: SyntaxNode) -> Option<Self> { 2573 fn can_cast(kind: SyntaxKind) -> bool {
2490 match syntax.kind() { 2574 match kind {
2491 RET_TYPE => Some(RetType { syntax }), 2575 RET_TYPE => true,
2492 _ => None, 2576 _ => false,
2493 } 2577 }
2494 } 2578 }
2579 fn cast(syntax: SyntaxNode) -> Option<Self> {
2580 if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None }
2581 }
2495 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2582 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2496} 2583}
2497 2584
@@ -2509,12 +2596,15 @@ pub struct ReturnExpr {
2509} 2596}
2510 2597
2511impl AstNode for ReturnExpr { 2598impl AstNode for ReturnExpr {
2512 fn cast(syntax: SyntaxNode) -> Option<Self> { 2599 fn can_cast(kind: SyntaxKind) -> bool {
2513 match syntax.kind() { 2600 match kind {
2514 RETURN_EXPR => Some(ReturnExpr { syntax }), 2601 RETURN_EXPR => true,
2515 _ => None, 2602 _ => false,
2516 } 2603 }
2517 } 2604 }
2605 fn cast(syntax: SyntaxNode) -> Option<Self> {
2606 if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None }
2607 }
2518 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2608 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2519} 2609}
2520 2610
@@ -2532,12 +2622,15 @@ pub struct SelfParam {
2532} 2622}
2533 2623
2534impl AstNode for SelfParam { 2624impl AstNode for SelfParam {
2535 fn cast(syntax: SyntaxNode) -> Option<Self> { 2625 fn can_cast(kind: SyntaxKind) -> bool {
2536 match syntax.kind() { 2626 match kind {
2537 SELF_PARAM => Some(SelfParam { syntax }), 2627 SELF_PARAM => true,
2538 _ => None, 2628 _ => false,
2539 } 2629 }
2540 } 2630 }
2631 fn cast(syntax: SyntaxNode) -> Option<Self> {
2632 if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None }
2633 }
2541 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2634 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2542} 2635}
2543 2636
@@ -2552,12 +2645,15 @@ pub struct SlicePat {
2552} 2645}
2553 2646
2554impl AstNode for SlicePat { 2647impl AstNode for SlicePat {
2555 fn cast(syntax: SyntaxNode) -> Option<Self> { 2648 fn can_cast(kind: SyntaxKind) -> bool {
2556 match syntax.kind() { 2649 match kind {
2557 SLICE_PAT => Some(SlicePat { syntax }), 2650 SLICE_PAT => true,
2558 _ => None, 2651 _ => false,
2559 } 2652 }
2560 } 2653 }
2654 fn cast(syntax: SyntaxNode) -> Option<Self> {
2655 if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None }
2656 }
2561 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2657 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2562} 2658}
2563 2659
@@ -2571,12 +2667,15 @@ pub struct SliceType {
2571} 2667}
2572 2668
2573impl AstNode for SliceType { 2669impl AstNode for SliceType {
2574 fn cast(syntax: SyntaxNode) -> Option<Self> { 2670 fn can_cast(kind: SyntaxKind) -> bool {
2575 match syntax.kind() { 2671 match kind {
2576 SLICE_TYPE => Some(SliceType { syntax }), 2672 SLICE_TYPE => true,
2577 _ => None, 2673 _ => false,
2578 } 2674 }
2579 } 2675 }
2676 fn cast(syntax: SyntaxNode) -> Option<Self> {
2677 if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None }
2678 }
2580 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2679 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2581} 2680}
2582 2681
@@ -2594,12 +2693,15 @@ pub struct SourceFile {
2594} 2693}
2595 2694
2596impl AstNode for SourceFile { 2695impl AstNode for SourceFile {
2597 fn cast(syntax: SyntaxNode) -> Option<Self> { 2696 fn can_cast(kind: SyntaxKind) -> bool {
2598 match syntax.kind() { 2697 match kind {
2599 SOURCE_FILE => Some(SourceFile { syntax }), 2698 SOURCE_FILE => true,
2600 _ => None, 2699 _ => false,
2601 } 2700 }
2602 } 2701 }
2702 fn cast(syntax: SyntaxNode) -> Option<Self> {
2703 if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None }
2704 }
2603 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2705 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2604} 2706}
2605 2707
@@ -2619,12 +2721,15 @@ pub struct StaticDef {
2619} 2721}
2620 2722
2621impl AstNode for StaticDef { 2723impl AstNode for StaticDef {
2622 fn cast(syntax: SyntaxNode) -> Option<Self> { 2724 fn can_cast(kind: SyntaxKind) -> bool {
2623 match syntax.kind() { 2725 match kind {
2624 STATIC_DEF => Some(StaticDef { syntax }), 2726 STATIC_DEF => true,
2625 _ => None, 2727 _ => false,
2626 } 2728 }
2627 } 2729 }
2730 fn cast(syntax: SyntaxNode) -> Option<Self> {
2731 if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None }
2732 }
2628 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2733 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2629} 2734}
2630 2735
@@ -2647,34 +2752,31 @@ pub struct Stmt {
2647 pub(crate) syntax: SyntaxNode, 2752 pub(crate) syntax: SyntaxNode,
2648} 2753}
2649 2754
2755impl AstNode for Stmt {
2756 fn can_cast(kind: SyntaxKind) -> bool {
2757 match kind {
2758 | EXPR_STMT | LET_STMT => true,
2759 _ => false,
2760 }
2761 }
2762 fn cast(syntax: SyntaxNode) -> Option<Self> {
2763 if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None }
2764 }
2765 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2766}
2767
2768
2650#[derive(Debug, Clone, PartialEq, Eq)] 2769#[derive(Debug, Clone, PartialEq, Eq)]
2651pub enum StmtKind { 2770pub enum StmtKind {
2652 ExprStmt(ExprStmt), 2771 ExprStmt(ExprStmt),
2653 LetStmt(LetStmt), 2772 LetStmt(LetStmt),
2654} 2773}
2655impl From<ExprStmt> for Stmt { 2774impl From<ExprStmt> for Stmt {
2656 fn from(n: ExprStmt) -> Stmt { 2775 fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } }
2657 Stmt::cast(n.syntax).unwrap()
2658 }
2659} 2776}
2660impl From<LetStmt> for Stmt { 2777impl From<LetStmt> for Stmt {
2661 fn from(n: LetStmt) -> Stmt { 2778 fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } }
2662 Stmt::cast(n.syntax).unwrap()
2663 }
2664} 2779}
2665
2666
2667impl AstNode for Stmt {
2668 fn cast(syntax: SyntaxNode) -> Option<Self> {
2669 match syntax.kind() {
2670 | EXPR_STMT
2671 | LET_STMT => Some(Stmt { syntax }),
2672 _ => None,
2673 }
2674 }
2675 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2676}
2677
2678impl Stmt { 2780impl Stmt {
2679 pub fn kind(&self) -> StmtKind { 2781 pub fn kind(&self) -> StmtKind {
2680 match self.syntax.kind() { 2782 match self.syntax.kind() {
@@ -2694,12 +2796,15 @@ pub struct StructDef {
2694} 2796}
2695 2797
2696impl AstNode for StructDef { 2798impl AstNode for StructDef {
2697 fn cast(syntax: SyntaxNode) -> Option<Self> { 2799 fn can_cast(kind: SyntaxKind) -> bool {
2698 match syntax.kind() { 2800 match kind {
2699 STRUCT_DEF => Some(StructDef { syntax }), 2801 STRUCT_DEF => true,
2700 _ => None, 2802 _ => false,
2701 } 2803 }
2702 } 2804 }
2805 fn cast(syntax: SyntaxNode) -> Option<Self> {
2806 if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None }
2807 }
2703 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2808 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2704} 2809}
2705 2810
@@ -2718,12 +2823,15 @@ pub struct StructLit {
2718} 2823}
2719 2824
2720impl AstNode for StructLit { 2825impl AstNode for StructLit {
2721 fn cast(syntax: SyntaxNode) -> Option<Self> { 2826 fn can_cast(kind: SyntaxKind) -> bool {
2722 match syntax.kind() { 2827 match kind {
2723 STRUCT_LIT => Some(StructLit { syntax }), 2828 STRUCT_LIT => true,
2724 _ => None, 2829 _ => false,
2725 } 2830 }
2726 } 2831 }
2832 fn cast(syntax: SyntaxNode) -> Option<Self> {
2833 if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None }
2834 }
2727 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2835 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2728} 2836}
2729 2837
@@ -2745,12 +2853,15 @@ pub struct StructPat {
2745} 2853}
2746 2854
2747impl AstNode for StructPat { 2855impl AstNode for StructPat {
2748 fn cast(syntax: SyntaxNode) -> Option<Self> { 2856 fn can_cast(kind: SyntaxKind) -> bool {
2749 match syntax.kind() { 2857 match kind {
2750 STRUCT_PAT => Some(StructPat { syntax }), 2858 STRUCT_PAT => true,
2751 _ => None, 2859 _ => false,
2752 } 2860 }
2753 } 2861 }
2862 fn cast(syntax: SyntaxNode) -> Option<Self> {
2863 if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None }
2864 }
2754 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2865 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2755} 2866}
2756 2867
@@ -2772,12 +2883,15 @@ pub struct TokenTree {
2772} 2883}
2773 2884
2774impl AstNode for TokenTree { 2885impl AstNode for TokenTree {
2775 fn cast(syntax: SyntaxNode) -> Option<Self> { 2886 fn can_cast(kind: SyntaxKind) -> bool {
2776 match syntax.kind() { 2887 match kind {
2777 TOKEN_TREE => Some(TokenTree { syntax }), 2888 TOKEN_TREE => true,
2778 _ => None, 2889 _ => false,
2779 } 2890 }
2780 } 2891 }
2892 fn cast(syntax: SyntaxNode) -> Option<Self> {
2893 if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None }
2894 }
2781 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2895 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2782} 2896}
2783 2897
@@ -2791,12 +2905,15 @@ pub struct TraitDef {
2791} 2905}
2792 2906
2793impl AstNode for TraitDef { 2907impl AstNode for TraitDef {
2794 fn cast(syntax: SyntaxNode) -> Option<Self> { 2908 fn can_cast(kind: SyntaxKind) -> bool {
2795 match syntax.kind() { 2909 match kind {
2796 TRAIT_DEF => Some(TraitDef { syntax }), 2910 TRAIT_DEF => true,
2797 _ => None, 2911 _ => false,
2798 } 2912 }
2799 } 2913 }
2914 fn cast(syntax: SyntaxNode) -> Option<Self> {
2915 if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None }
2916 }
2800 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2917 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2801} 2918}
2802 2919
@@ -2820,12 +2937,15 @@ pub struct TryBlockExpr {
2820} 2937}
2821 2938
2822impl AstNode for TryBlockExpr { 2939impl AstNode for TryBlockExpr {
2823 fn cast(syntax: SyntaxNode) -> Option<Self> { 2940 fn can_cast(kind: SyntaxKind) -> bool {
2824 match syntax.kind() { 2941 match kind {
2825 TRY_BLOCK_EXPR => Some(TryBlockExpr { syntax }), 2942 TRY_BLOCK_EXPR => true,
2826 _ => None, 2943 _ => false,
2827 } 2944 }
2828 } 2945 }
2946 fn cast(syntax: SyntaxNode) -> Option<Self> {
2947 if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None }
2948 }
2829 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2949 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2830} 2950}
2831 2951
@@ -2840,12 +2960,15 @@ pub struct TryExpr {
2840} 2960}
2841 2961
2842impl AstNode for TryExpr { 2962impl AstNode for TryExpr {
2843 fn cast(syntax: SyntaxNode) -> Option<Self> { 2963 fn can_cast(kind: SyntaxKind) -> bool {
2844 match syntax.kind() { 2964 match kind {
2845 TRY_EXPR => Some(TryExpr { syntax }), 2965 TRY_EXPR => true,
2846 _ => None, 2966 _ => false,
2847 } 2967 }
2848 } 2968 }
2969 fn cast(syntax: SyntaxNode) -> Option<Self> {
2970 if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None }
2971 }
2849 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2972 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2850} 2973}
2851 2974
@@ -2863,12 +2986,15 @@ pub struct TupleExpr {
2863} 2986}
2864 2987
2865impl AstNode for TupleExpr { 2988impl AstNode for TupleExpr {
2866 fn cast(syntax: SyntaxNode) -> Option<Self> { 2989 fn can_cast(kind: SyntaxKind) -> bool {
2867 match syntax.kind() { 2990 match kind {
2868 TUPLE_EXPR => Some(TupleExpr { syntax }), 2991 TUPLE_EXPR => true,
2869 _ => None, 2992 _ => false,
2870 } 2993 }
2871 } 2994 }
2995 fn cast(syntax: SyntaxNode) -> Option<Self> {
2996 if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None }
2997 }
2872 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2998 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2873} 2999}
2874 3000
@@ -2886,12 +3012,15 @@ pub struct TuplePat {
2886} 3012}
2887 3013
2888impl AstNode for TuplePat { 3014impl AstNode for TuplePat {
2889 fn cast(syntax: SyntaxNode) -> Option<Self> { 3015 fn can_cast(kind: SyntaxKind) -> bool {
2890 match syntax.kind() { 3016 match kind {
2891 TUPLE_PAT => Some(TuplePat { syntax }), 3017 TUPLE_PAT => true,
2892 _ => None, 3018 _ => false,
2893 } 3019 }
2894 } 3020 }
3021 fn cast(syntax: SyntaxNode) -> Option<Self> {
3022 if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None }
3023 }
2895 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3024 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2896} 3025}
2897 3026
@@ -2909,12 +3038,15 @@ pub struct TupleStructPat {
2909} 3038}
2910 3039
2911impl AstNode for TupleStructPat { 3040impl AstNode for TupleStructPat {
2912 fn cast(syntax: SyntaxNode) -> Option<Self> { 3041 fn can_cast(kind: SyntaxKind) -> bool {
2913 match syntax.kind() { 3042 match kind {
2914 TUPLE_STRUCT_PAT => Some(TupleStructPat { syntax }), 3043 TUPLE_STRUCT_PAT => true,
2915 _ => None, 3044 _ => false,
2916 } 3045 }
2917 } 3046 }
3047 fn cast(syntax: SyntaxNode) -> Option<Self> {
3048 if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None }
3049 }
2918 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3050 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2919} 3051}
2920 3052
@@ -2936,12 +3068,15 @@ pub struct TupleType {
2936} 3068}
2937 3069
2938impl AstNode for TupleType { 3070impl AstNode for TupleType {
2939 fn cast(syntax: SyntaxNode) -> Option<Self> { 3071 fn can_cast(kind: SyntaxKind) -> bool {
2940 match syntax.kind() { 3072 match kind {
2941 TUPLE_TYPE => Some(TupleType { syntax }), 3073 TUPLE_TYPE => true,
2942 _ => None, 3074 _ => false,
2943 } 3075 }
2944 } 3076 }
3077 fn cast(syntax: SyntaxNode) -> Option<Self> {
3078 if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None }
3079 }
2945 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3080 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2946} 3081}
2947 3082
@@ -2959,12 +3094,15 @@ pub struct TypeAliasDef {
2959} 3094}
2960 3095
2961impl AstNode for TypeAliasDef { 3096impl AstNode for TypeAliasDef {
2962 fn cast(syntax: SyntaxNode) -> Option<Self> { 3097 fn can_cast(kind: SyntaxKind) -> bool {
2963 match syntax.kind() { 3098 match kind {
2964 TYPE_ALIAS_DEF => Some(TypeAliasDef { syntax }), 3099 TYPE_ALIAS_DEF => true,
2965 _ => None, 3100 _ => false,
2966 } 3101 }
2967 } 3102 }
3103 fn cast(syntax: SyntaxNode) -> Option<Self> {
3104 if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None }
3105 }
2968 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3106 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2969} 3107}
2970 3108
@@ -2988,12 +3126,15 @@ pub struct TypeArg {
2988} 3126}
2989 3127
2990impl AstNode for TypeArg { 3128impl AstNode for TypeArg {
2991 fn cast(syntax: SyntaxNode) -> Option<Self> { 3129 fn can_cast(kind: SyntaxKind) -> bool {
2992 match syntax.kind() { 3130 match kind {
2993 TYPE_ARG => Some(TypeArg { syntax }), 3131 TYPE_ARG => true,
2994 _ => None, 3132 _ => false,
2995 } 3133 }
2996 } 3134 }
3135 fn cast(syntax: SyntaxNode) -> Option<Self> {
3136 if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None }
3137 }
2997 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3138 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2998} 3139}
2999 3140
@@ -3011,12 +3152,15 @@ pub struct TypeArgList {
3011} 3152}
3012 3153
3013impl AstNode for TypeArgList { 3154impl AstNode for TypeArgList {
3014 fn cast(syntax: SyntaxNode) -> Option<Self> { 3155 fn can_cast(kind: SyntaxKind) -> bool {
3015 match syntax.kind() { 3156 match kind {
3016 TYPE_ARG_LIST => Some(TypeArgList { syntax }), 3157 TYPE_ARG_LIST => true,
3017 _ => None, 3158 _ => false,
3018 } 3159 }
3019 } 3160 }
3161 fn cast(syntax: SyntaxNode) -> Option<Self> {
3162 if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None }
3163 }
3020 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3164 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3021} 3165}
3022 3166
@@ -3042,12 +3186,15 @@ pub struct TypeBound {
3042} 3186}
3043 3187
3044impl AstNode for TypeBound { 3188impl AstNode for TypeBound {
3045 fn cast(syntax: SyntaxNode) -> Option<Self> { 3189 fn can_cast(kind: SyntaxKind) -> bool {
3046 match syntax.kind() { 3190 match kind {
3047 TYPE_BOUND => Some(TypeBound { syntax }), 3191 TYPE_BOUND => true,
3048 _ => None, 3192 _ => false,
3049 } 3193 }
3050 } 3194 }
3195 fn cast(syntax: SyntaxNode) -> Option<Self> {
3196 if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None }
3197 }
3051 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3198 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3052} 3199}
3053 3200
@@ -3065,12 +3212,15 @@ pub struct TypeBoundList {
3065} 3212}
3066 3213
3067impl AstNode for TypeBoundList { 3214impl AstNode for TypeBoundList {
3068 fn cast(syntax: SyntaxNode) -> Option<Self> { 3215 fn can_cast(kind: SyntaxKind) -> bool {
3069 match syntax.kind() { 3216 match kind {
3070 TYPE_BOUND_LIST => Some(TypeBoundList { syntax }), 3217 TYPE_BOUND_LIST => true,
3071 _ => None, 3218 _ => false,
3072 } 3219 }
3073 } 3220 }
3221 fn cast(syntax: SyntaxNode) -> Option<Self> {
3222 if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None }
3223 }
3074 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3224 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3075} 3225}
3076 3226
@@ -3088,12 +3238,15 @@ pub struct TypeParam {
3088} 3238}
3089 3239
3090impl AstNode for TypeParam { 3240impl AstNode for TypeParam {
3091 fn cast(syntax: SyntaxNode) -> Option<Self> { 3241 fn can_cast(kind: SyntaxKind) -> bool {
3092 match syntax.kind() { 3242 match kind {
3093 TYPE_PARAM => Some(TypeParam { syntax }), 3243 TYPE_PARAM => true,
3094 _ => None, 3244 _ => false,
3095 } 3245 }
3096 } 3246 }
3247 fn cast(syntax: SyntaxNode) -> Option<Self> {
3248 if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None }
3249 }
3097 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3250 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3098} 3251}
3099 3252
@@ -3111,12 +3264,15 @@ pub struct TypeParamList {
3111} 3264}
3112 3265
3113impl AstNode for TypeParamList { 3266impl AstNode for TypeParamList {
3114 fn cast(syntax: SyntaxNode) -> Option<Self> { 3267 fn can_cast(kind: SyntaxKind) -> bool {
3115 match syntax.kind() { 3268 match kind {
3116 TYPE_PARAM_LIST => Some(TypeParamList { syntax }), 3269 TYPE_PARAM_LIST => true,
3117 _ => None, 3270 _ => false,
3118 } 3271 }
3119 } 3272 }
3273 fn cast(syntax: SyntaxNode) -> Option<Self> {
3274 if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None }
3275 }
3120 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3276 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3121} 3277}
3122 3278
@@ -3137,6 +3293,20 @@ pub struct TypeRef {
3137 pub(crate) syntax: SyntaxNode, 3293 pub(crate) syntax: SyntaxNode,
3138} 3294}
3139 3295
3296impl AstNode for TypeRef {
3297 fn can_cast(kind: SyntaxKind) -> bool {
3298 match kind {
3299 | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
3300 _ => false,
3301 }
3302 }
3303 fn cast(syntax: SyntaxNode) -> Option<Self> {
3304 if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None }
3305 }
3306 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3307}
3308
3309
3140#[derive(Debug, Clone, PartialEq, Eq)] 3310#[derive(Debug, Clone, PartialEq, Eq)]
3141pub enum TypeRefKind { 3311pub enum TypeRefKind {
3142 ParenType(ParenType), 3312 ParenType(ParenType),
@@ -3154,94 +3324,44 @@ pub enum TypeRefKind {
3154 DynTraitType(DynTraitType), 3324 DynTraitType(DynTraitType),
3155} 3325}
3156impl From<ParenType> for TypeRef { 3326impl From<ParenType> for TypeRef {
3157 fn from(n: ParenType) -> TypeRef { 3327 fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } }
3158 TypeRef::cast(n.syntax).unwrap()
3159 }
3160} 3328}
3161impl From<TupleType> for TypeRef { 3329impl From<TupleType> for TypeRef {
3162 fn from(n: TupleType) -> TypeRef { 3330 fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } }
3163 TypeRef::cast(n.syntax).unwrap()
3164 }
3165} 3331}
3166impl From<NeverType> for TypeRef { 3332impl From<NeverType> for TypeRef {
3167 fn from(n: NeverType) -> TypeRef { 3333 fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } }
3168 TypeRef::cast(n.syntax).unwrap()
3169 }
3170} 3334}
3171impl From<PathType> for TypeRef { 3335impl From<PathType> for TypeRef {
3172 fn from(n: PathType) -> TypeRef { 3336 fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } }
3173 TypeRef::cast(n.syntax).unwrap()
3174 }
3175} 3337}
3176impl From<PointerType> for TypeRef { 3338impl From<PointerType> for TypeRef {
3177 fn from(n: PointerType) -> TypeRef { 3339 fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3178 TypeRef::cast(n.syntax).unwrap()
3179 }
3180} 3340}
3181impl From<ArrayType> for TypeRef { 3341impl From<ArrayType> for TypeRef {
3182 fn from(n: ArrayType) -> TypeRef { 3342 fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } }
3183 TypeRef::cast(n.syntax).unwrap()
3184 }
3185} 3343}
3186impl From<SliceType> for TypeRef { 3344impl From<SliceType> for TypeRef {
3187 fn from(n: SliceType) -> TypeRef { 3345 fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3188 TypeRef::cast(n.syntax).unwrap()
3189 }
3190} 3346}
3191impl From<ReferenceType> for TypeRef { 3347impl From<ReferenceType> for TypeRef {
3192 fn from(n: ReferenceType) -> TypeRef { 3348 fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } }
3193 TypeRef::cast(n.syntax).unwrap()
3194 }
3195} 3349}
3196impl From<PlaceholderType> for TypeRef { 3350impl From<PlaceholderType> for TypeRef {
3197 fn from(n: PlaceholderType) -> TypeRef { 3351 fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } }
3198 TypeRef::cast(n.syntax).unwrap()
3199 }
3200} 3352}
3201impl From<FnPointerType> for TypeRef { 3353impl From<FnPointerType> for TypeRef {
3202 fn from(n: FnPointerType) -> TypeRef { 3354 fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
3203 TypeRef::cast(n.syntax).unwrap()
3204 }
3205} 3355}
3206impl From<ForType> for TypeRef { 3356impl From<ForType> for TypeRef {
3207 fn from(n: ForType) -> TypeRef { 3357 fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } }
3208 TypeRef::cast(n.syntax).unwrap()
3209 }
3210} 3358}
3211impl From<ImplTraitType> for TypeRef { 3359impl From<ImplTraitType> for TypeRef {
3212 fn from(n: ImplTraitType) -> TypeRef { 3360 fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3213 TypeRef::cast(n.syntax).unwrap()
3214 }
3215} 3361}
3216impl From<DynTraitType> for TypeRef { 3362impl From<DynTraitType> for TypeRef {
3217 fn from(n: DynTraitType) -> TypeRef { 3363 fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
3218 TypeRef::cast(n.syntax).unwrap()
3219 }
3220}
3221
3222
3223impl AstNode for TypeRef {
3224 fn cast(syntax: SyntaxNode) -> Option<Self> {
3225 match syntax.kind() {
3226 | PAREN_TYPE
3227 | TUPLE_TYPE
3228 | NEVER_TYPE
3229 | PATH_TYPE
3230 | POINTER_TYPE
3231 | ARRAY_TYPE
3232 | SLICE_TYPE
3233 | REFERENCE_TYPE
3234 | PLACEHOLDER_TYPE
3235 | FN_POINTER_TYPE
3236 | FOR_TYPE
3237 | IMPL_TRAIT_TYPE
3238 | DYN_TRAIT_TYPE => Some(TypeRef { syntax }),
3239 _ => None,
3240 }
3241 }
3242 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3243} 3364}
3244
3245impl TypeRef { 3365impl TypeRef {
3246 pub fn kind(&self) -> TypeRefKind { 3366 pub fn kind(&self) -> TypeRefKind {
3247 match self.syntax.kind() { 3367 match self.syntax.kind() {
@@ -3272,12 +3392,15 @@ pub struct UseItem {
3272} 3392}
3273 3393
3274impl AstNode for UseItem { 3394impl AstNode for UseItem {
3275 fn cast(syntax: SyntaxNode) -> Option<Self> { 3395 fn can_cast(kind: SyntaxKind) -> bool {
3276 match syntax.kind() { 3396 match kind {
3277 USE_ITEM => Some(UseItem { syntax }), 3397 USE_ITEM => true,
3278 _ => None, 3398 _ => false,
3279 } 3399 }
3280 } 3400 }
3401 fn cast(syntax: SyntaxNode) -> Option<Self> {
3402 if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None }
3403 }
3281 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3404 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3282} 3405}
3283 3406
@@ -3296,12 +3419,15 @@ pub struct UseTree {
3296} 3419}
3297 3420
3298impl AstNode for UseTree { 3421impl AstNode for UseTree {
3299 fn cast(syntax: SyntaxNode) -> Option<Self> { 3422 fn can_cast(kind: SyntaxKind) -> bool {
3300 match syntax.kind() { 3423 match kind {
3301 USE_TREE => Some(UseTree { syntax }), 3424 USE_TREE => true,
3302 _ => None, 3425 _ => false,
3303 } 3426 }
3304 } 3427 }
3428 fn cast(syntax: SyntaxNode) -> Option<Self> {
3429 if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None }
3430 }
3305 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3431 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3306} 3432}
3307 3433
@@ -3327,12 +3453,15 @@ pub struct UseTreeList {
3327} 3453}
3328 3454
3329impl AstNode for UseTreeList { 3455impl AstNode for UseTreeList {
3330 fn cast(syntax: SyntaxNode) -> Option<Self> { 3456 fn can_cast(kind: SyntaxKind) -> bool {
3331 match syntax.kind() { 3457 match kind {
3332 USE_TREE_LIST => Some(UseTreeList { syntax }), 3458 USE_TREE_LIST => true,
3333 _ => None, 3459 _ => false,
3334 } 3460 }
3335 } 3461 }
3462 fn cast(syntax: SyntaxNode) -> Option<Self> {
3463 if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None }
3464 }
3336 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3465 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3337} 3466}
3338 3467
@@ -3350,12 +3479,15 @@ pub struct Visibility {
3350} 3479}
3351 3480
3352impl AstNode for Visibility { 3481impl AstNode for Visibility {
3353 fn cast(syntax: SyntaxNode) -> Option<Self> { 3482 fn can_cast(kind: SyntaxKind) -> bool {
3354 match syntax.kind() { 3483 match kind {
3355 VISIBILITY => Some(Visibility { syntax }), 3484 VISIBILITY => true,
3356 _ => None, 3485 _ => false,
3357 } 3486 }
3358 } 3487 }
3488 fn cast(syntax: SyntaxNode) -> Option<Self> {
3489 if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None }
3490 }
3359 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3491 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3360} 3492}
3361 3493
@@ -3369,12 +3501,15 @@ pub struct WhereClause {
3369} 3501}
3370 3502
3371impl AstNode for WhereClause { 3503impl AstNode for WhereClause {
3372 fn cast(syntax: SyntaxNode) -> Option<Self> { 3504 fn can_cast(kind: SyntaxKind) -> bool {
3373 match syntax.kind() { 3505 match kind {
3374 WHERE_CLAUSE => Some(WhereClause { syntax }), 3506 WHERE_CLAUSE => true,
3375 _ => None, 3507 _ => false,
3376 } 3508 }
3377 } 3509 }
3510 fn cast(syntax: SyntaxNode) -> Option<Self> {
3511 if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None }
3512 }
3378 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3513 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3379} 3514}
3380 3515
@@ -3392,12 +3527,15 @@ pub struct WherePred {
3392} 3527}
3393 3528
3394impl AstNode for WherePred { 3529impl AstNode for WherePred {
3395 fn cast(syntax: SyntaxNode) -> Option<Self> { 3530 fn can_cast(kind: SyntaxKind) -> bool {
3396 match syntax.kind() { 3531 match kind {
3397 WHERE_PRED => Some(WherePred { syntax }), 3532 WHERE_PRED => true,
3398 _ => None, 3533 _ => false,
3399 } 3534 }
3400 } 3535 }
3536 fn cast(syntax: SyntaxNode) -> Option<Self> {
3537 if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None }
3538 }
3401 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3539 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3402} 3540}
3403 3541
@@ -3416,12 +3554,15 @@ pub struct WhileExpr {
3416} 3554}
3417 3555
3418impl AstNode for WhileExpr { 3556impl AstNode for WhileExpr {
3419 fn cast(syntax: SyntaxNode) -> Option<Self> { 3557 fn can_cast(kind: SyntaxKind) -> bool {
3420 match syntax.kind() { 3558 match kind {
3421 WHILE_EXPR => Some(WhileExpr { syntax }), 3559 WHILE_EXPR => true,
3422 _ => None, 3560 _ => false,
3423 } 3561 }
3424 } 3562 }
3563 fn cast(syntax: SyntaxNode) -> Option<Self> {
3564 if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None }
3565 }
3425 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3566 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3426} 3567}
3427 3568
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera
index f3365c560..03b4bf3a1 100644
--- a/crates/ra_syntax/src/ast/generated.rs.tera
+++ b/crates/ra_syntax/src/ast/generated.rs.tera
@@ -12,18 +12,34 @@ the below applies to the result of this template
12#![cfg_attr(rustfmt, rustfmt_skip)] 12#![cfg_attr(rustfmt, rustfmt_skip)]
13 13
14use crate::{ 14use crate::{
15 SyntaxNode, SyntaxKind::*, 15 SyntaxNode, SyntaxKind::{self, *},
16 ast::{self, AstNode}, 16 ast::{self, AstNode},
17}; 17};
18{% for node, methods in ast %} 18{% for node, methods in ast %}
19// {{ node }} 19// {{ node }}
20
21{%- if methods.enum %}
22#[derive(Debug, Clone, PartialEq, Eq, Hash)] 20#[derive(Debug, Clone, PartialEq, Eq, Hash)]
23pub struct {{ node }} { 21pub struct {{ node }} {
24 pub(crate) syntax: SyntaxNode, 22 pub(crate) syntax: SyntaxNode,
25} 23}
26 24
25impl AstNode for {{ node }} {
26 fn can_cast(kind: SyntaxKind) -> bool {
27 match kind {
28 {%- if methods.enum %}
29 {% for kind in methods.enum %} | {{ kind | SCREAM }} {%- endfor -%}
30 {% else %}
31 {{ node | SCREAM }}
32 {%- endif %} => true,
33 _ => false,
34 }
35 }
36 fn cast(syntax: SyntaxNode) -> Option<Self> {
37 if Self::can_cast(syntax.kind()) { Some({{ node }} { syntax }) } else { None }
38 }
39 fn syntax(&self) -> &SyntaxNode { &self.syntax }
40}
41
42{% if methods.enum %}
27#[derive(Debug, Clone, PartialEq, Eq)] 43#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum {{ node }}Kind { 44pub enum {{ node }}Kind {
29{%- for kind in methods.enum %} 45{%- for kind in methods.enum %}
@@ -33,25 +49,9 @@ pub enum {{ node }}Kind {
33 49
34{%- for kind in methods.enum %} 50{%- for kind in methods.enum %}
35impl From<{{ kind }}> for {{ node }} { 51impl From<{{ kind }}> for {{ node }} {
36 fn from(n: {{ kind }}) -> {{ node }} { 52 fn from(n: {{ kind }}) -> {{ node }} { {{ node }} { syntax: n.syntax } }
37 {{ node }}::cast(n.syntax).unwrap()
38 }
39} 53}
40{%- endfor %} 54{%- endfor %}
41
42
43impl AstNode for {{ node }} {
44 fn cast(syntax: SyntaxNode) -> Option<Self> {
45 match syntax.kind() {
46 {%- for kind in methods.enum %}
47 | {{ kind | SCREAM }}
48 {%- endfor %} => Some({{ node }} { syntax }),
49 _ => None,
50 }
51 }
52 fn syntax(&self) -> &SyntaxNode { &self.syntax }
53}
54
55impl {{ node }} { 55impl {{ node }} {
56 pub fn kind(&self) -> {{ node }}Kind { 56 pub fn kind(&self) -> {{ node }}Kind {
57 match self.syntax.kind() { 57 match self.syntax.kind() {
@@ -62,22 +62,6 @@ impl {{ node }} {
62 } 62 }
63 } 63 }
64} 64}
65{% else %}
66#[derive(Debug, Clone, PartialEq, Eq, Hash)]
67pub struct {{ node }} {
68 pub(crate) syntax: SyntaxNode,
69}
70
71impl AstNode for {{ node }} {
72 fn cast(syntax: SyntaxNode) -> Option<Self> {
73 match syntax.kind() {
74 {{ node | SCREAM }} => Some({{ node }} { syntax }),
75 _ => None,
76 }
77 }
78 fn syntax(&self) -> &SyntaxNode { &self.syntax }
79}
80
81{% endif %} 65{% endif %}
82{% if methods.traits -%} 66{% if methods.traits -%}
83 67