aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast.rs6
-rw-r--r--crates/ra_syntax/src/ast/generated.rs6
-rw-r--r--crates/ra_syntax/src/grammar.ron33
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
34pub trait TypeAscriptionOwner: AstNode {
35 fn ascribed_type(&self) -> Option<&TypeRef> {
36 child_opt(self)
37 }
38}
39
34pub trait NameOwner: AstNode { 40pub 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 {}
628impl ast::TypeParamsOwner for ConstDef {} 628impl ast::TypeParamsOwner for ConstDef {}
629impl ast::AttrsOwner for ConstDef {} 629impl ast::AttrsOwner for ConstDef {}
630impl ast::DocCommentsOwner for ConstDef {} 630impl ast::DocCommentsOwner for ConstDef {}
631impl ast::TypeAscriptionOwner for ConstDef {}
631impl ConstDef { 632impl 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
1771impl ast::TypeAscriptionOwner for LetStmt {}
1770impl LetStmt { 1772impl 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 {}
2592impl ast::NameOwner for NamedFieldDef {} 2594impl ast::NameOwner for NamedFieldDef {}
2593impl ast::AttrsOwner for NamedFieldDef {} 2595impl ast::AttrsOwner for NamedFieldDef {}
2594impl ast::DocCommentsOwner for NamedFieldDef {} 2596impl ast::DocCommentsOwner for NamedFieldDef {}
2597impl ast::TypeAscriptionOwner for NamedFieldDef {}
2595impl NamedFieldDef { 2598impl 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
2780impl ast::TypeAscriptionOwner for Param {}
2777impl Param { 2781impl 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
3692impl ast::TypeAscriptionOwner for SelfParam {}
3688impl SelfParam { 3693impl 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 {}
3820impl ast::TypeParamsOwner for StaticDef {} 3825impl ast::TypeParamsOwner for StaticDef {}
3821impl ast::AttrsOwner for StaticDef {} 3826impl ast::AttrsOwner for StaticDef {}
3822impl ast::DocCommentsOwner for StaticDef {} 3827impl ast::DocCommentsOwner for StaticDef {}
3828impl ast::TypeAscriptionOwner for StaticDef {}
3823impl StaticDef { 3829impl 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"],