diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 33 |
3 files changed, 36 insertions, 9 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 56fb7c20c..81c709bfb 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -31,6 +31,12 @@ pub trait AstToken: AstNode { | |||
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | pub trait TypeAscriptionOwner: AstNode { | ||
35 | fn ascribed_type(&self) -> Option<&TypeRef> { | ||
36 | child_opt(self) | ||
37 | } | ||
38 | } | ||
39 | |||
34 | pub trait NameOwner: AstNode { | 40 | pub trait NameOwner: AstNode { |
35 | fn name(&self) -> Option<&Name> { | 41 | fn name(&self) -> Option<&Name> { |
36 | child_opt(self) | 42 | child_opt(self) |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 4e2705d09..6db2f74ef 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -628,6 +628,7 @@ impl ast::NameOwner for ConstDef {} | |||
628 | impl ast::TypeParamsOwner for ConstDef {} | 628 | impl ast::TypeParamsOwner for ConstDef {} |
629 | impl ast::AttrsOwner for ConstDef {} | 629 | impl ast::AttrsOwner for ConstDef {} |
630 | impl ast::DocCommentsOwner for ConstDef {} | 630 | impl ast::DocCommentsOwner for ConstDef {} |
631 | impl ast::TypeAscriptionOwner for ConstDef {} | ||
631 | impl ConstDef { | 632 | impl ConstDef { |
632 | pub fn type_ref(&self) -> Option<&TypeRef> { | 633 | pub fn type_ref(&self) -> Option<&TypeRef> { |
633 | super::child_opt(self) | 634 | super::child_opt(self) |
@@ -1767,6 +1768,7 @@ impl ToOwned for LetStmt { | |||
1767 | } | 1768 | } |
1768 | 1769 | ||
1769 | 1770 | ||
1771 | impl ast::TypeAscriptionOwner for LetStmt {} | ||
1770 | impl LetStmt { | 1772 | impl LetStmt { |
1771 | pub fn pat(&self) -> Option<&Pat> { | 1773 | pub fn pat(&self) -> Option<&Pat> { |
1772 | super::child_opt(self) | 1774 | super::child_opt(self) |
@@ -2592,6 +2594,7 @@ impl ast::VisibilityOwner for NamedFieldDef {} | |||
2592 | impl ast::NameOwner for NamedFieldDef {} | 2594 | impl ast::NameOwner for NamedFieldDef {} |
2593 | impl ast::AttrsOwner for NamedFieldDef {} | 2595 | impl ast::AttrsOwner for NamedFieldDef {} |
2594 | impl ast::DocCommentsOwner for NamedFieldDef {} | 2596 | impl ast::DocCommentsOwner for NamedFieldDef {} |
2597 | impl ast::TypeAscriptionOwner for NamedFieldDef {} | ||
2595 | impl NamedFieldDef { | 2598 | impl NamedFieldDef { |
2596 | pub fn type_ref(&self) -> Option<&TypeRef> { | 2599 | pub fn type_ref(&self) -> Option<&TypeRef> { |
2597 | super::child_opt(self) | 2600 | super::child_opt(self) |
@@ -2774,6 +2777,7 @@ impl ToOwned for Param { | |||
2774 | } | 2777 | } |
2775 | 2778 | ||
2776 | 2779 | ||
2780 | impl ast::TypeAscriptionOwner for Param {} | ||
2777 | impl Param { | 2781 | impl Param { |
2778 | pub fn pat(&self) -> Option<&Pat> { | 2782 | pub fn pat(&self) -> Option<&Pat> { |
2779 | super::child_opt(self) | 2783 | super::child_opt(self) |
@@ -3685,6 +3689,7 @@ impl ToOwned for SelfParam { | |||
3685 | } | 3689 | } |
3686 | 3690 | ||
3687 | 3691 | ||
3692 | impl ast::TypeAscriptionOwner for SelfParam {} | ||
3688 | impl SelfParam { | 3693 | impl SelfParam { |
3689 | pub fn type_ref(&self) -> Option<&TypeRef> { | 3694 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3690 | super::child_opt(self) | 3695 | super::child_opt(self) |
@@ -3820,6 +3825,7 @@ impl ast::NameOwner for StaticDef {} | |||
3820 | impl ast::TypeParamsOwner for StaticDef {} | 3825 | impl ast::TypeParamsOwner for StaticDef {} |
3821 | impl ast::AttrsOwner for StaticDef {} | 3826 | impl ast::AttrsOwner for StaticDef {} |
3822 | impl ast::DocCommentsOwner for StaticDef {} | 3827 | impl ast::DocCommentsOwner for StaticDef {} |
3828 | impl ast::TypeAscriptionOwner for StaticDef {} | ||
3823 | impl StaticDef { | 3829 | impl StaticDef { |
3824 | pub fn type_ref(&self) -> Option<&TypeRef> { | 3830 | pub fn type_ref(&self) -> Option<&TypeRef> { |
3825 | super::child_opt(self) | 3831 | super::child_opt(self) |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index c7acbbd6c..a3bfc74a7 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -271,7 +271,7 @@ Grammar( | |||
271 | ] | 271 | ] |
272 | ), | 272 | ), |
273 | "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]), | 273 | "NamedFieldDefList": (collections: [["fields", "NamedFieldDef"]]), |
274 | "NamedFieldDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner"], options: ["TypeRef"] ), | 274 | "NamedFieldDef": ( traits: ["VisibilityOwner", "NameOwner", "AttrsOwner", "DocCommentsOwner", "TypeAscriptionOwner"], options: ["TypeRef"] ), |
275 | "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]), | 275 | "PosFieldDefList": (collections: [["fields", "PosFieldDef"]]), |
276 | "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]), | 276 | "PosFieldDef": ( traits: ["VisibilityOwner", "AttrsOwner"], options: ["TypeRef"]), |
277 | "EnumDef": ( traits: [ | 277 | "EnumDef": ( traits: [ |
@@ -298,7 +298,8 @@ Grammar( | |||
298 | "NameOwner", | 298 | "NameOwner", |
299 | "TypeParamsOwner", | 299 | "TypeParamsOwner", |
300 | "AttrsOwner", | 300 | "AttrsOwner", |
301 | "DocCommentsOwner" | 301 | "DocCommentsOwner", |
302 | "TypeAscriptionOwner", | ||
302 | ], | 303 | ], |
303 | options: ["TypeRef"] | 304 | options: ["TypeRef"] |
304 | ), | 305 | ), |
@@ -308,7 +309,8 @@ Grammar( | |||
308 | "NameOwner", | 309 | "NameOwner", |
309 | "TypeParamsOwner", | 310 | "TypeParamsOwner", |
310 | "AttrsOwner", | 311 | "AttrsOwner", |
311 | "DocCommentsOwner" | 312 | "DocCommentsOwner", |
313 | "TypeAscriptionOwner", | ||
312 | ], | 314 | ], |
313 | options: ["TypeRef"] | 315 | options: ["TypeRef"] |
314 | ), | 316 | ), |
@@ -569,11 +571,16 @@ Grammar( | |||
569 | "ExprStmt": ( | 571 | "ExprStmt": ( |
570 | options: [ ["expr", "Expr"] ] | 572 | options: [ ["expr", "Expr"] ] |
571 | ), | 573 | ), |
572 | "LetStmt": ( options: [ | 574 | "LetStmt": ( |
573 | ["pat", "Pat"], | 575 | options: [ |
574 | ["type_ref", "TypeRef"], | 576 | ["pat", "Pat"], |
575 | ["initializer", "Expr"], | 577 | ["type_ref", "TypeRef"], |
576 | ]), | 578 | ["initializer", "Expr"], |
579 | ], | ||
580 | traits: [ | ||
581 | "TypeAscriptionOwner", | ||
582 | ] | ||
583 | ), | ||
577 | "Condition": ( | 584 | "Condition": ( |
578 | options: [ "Pat", "Expr" ] | 585 | options: [ "Pat", "Expr" ] |
579 | ), | 586 | ), |
@@ -595,10 +602,18 @@ Grammar( | |||
595 | ["params", "Param"] | 602 | ["params", "Param"] |
596 | ] | 603 | ] |
597 | ), | 604 | ), |
598 | "SelfParam": (options: ["TypeRef", "SelfKw"]), | 605 | "SelfParam": ( |
606 | options: ["TypeRef", "SelfKw"], | ||
607 | traits: [ | ||
608 | "TypeAscriptionOwner", | ||
609 | ] | ||
610 | ), | ||
599 | "SelfKw": (), | 611 | "SelfKw": (), |
600 | "Param": ( | 612 | "Param": ( |
601 | options: [ "Pat", "TypeRef" ], | 613 | options: [ "Pat", "TypeRef" ], |
614 | traits: [ | ||
615 | "TypeAscriptionOwner", | ||
616 | ] | ||
602 | ), | 617 | ), |
603 | "UseItem": ( | 618 | "UseItem": ( |
604 | traits: ["AttrsOwner"], | 619 | traits: ["AttrsOwner"], |