aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs4
-rw-r--r--crates/ra_hir_def/src/body/lower.rs12
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs8
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs2
-rw-r--r--xtask/src/codegen/rust.ungram28
5 files changed, 37 insertions, 17 deletions
diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs
index 3650289fd..69852b611 100644
--- a/crates/ra_assists/src/handlers/early_return.rs
+++ b/crates/ra_assists/src/handlers/early_return.rs
@@ -51,11 +51,11 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext)
51 // Check if there is an IfLet that we can handle. 51 // Check if there is an IfLet that we can handle.
52 let if_let_pat = match cond.pat() { 52 let if_let_pat = match cond.pat() {
53 None => None, // No IfLet, supported. 53 None => None, // No IfLet, supported.
54 Some(ast::Pat::TupleStructPat(pat)) if pat.args().count() == 1 => { 54 Some(ast::Pat::TupleStructPat(pat)) if pat.fields().count() == 1 => {
55 let path = pat.path()?; 55 let path = pat.path()?;
56 match path.qualifier() { 56 match path.qualifier() {
57 None => { 57 None => {
58 let bound_ident = pat.args().next().unwrap(); 58 let bound_ident = pat.fields().next().unwrap();
59 Some((path, bound_ident)) 59 Some((path, bound_ident))
60 } 60 }
61 Some(_) => return None, 61 Some(_) => return None,
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 0d0365370..f5c37edb3 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -496,7 +496,7 @@ impl ExprCollector<'_> {
496 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr) 496 self.alloc_expr(Expr::BinaryOp { lhs, rhs, op }, syntax_ptr)
497 } 497 }
498 ast::Expr::TupleExpr(e) => { 498 ast::Expr::TupleExpr(e) => {
499 let exprs = e.exprs().map(|expr| self.collect_expr(expr)).collect(); 499 let exprs = e.fields().map(|expr| self.collect_expr(expr)).collect();
500 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr) 500 self.alloc_expr(Expr::Tuple { exprs }, syntax_ptr)
501 } 501 }
502 ast::Expr::BoxExpr(e) => { 502 ast::Expr::BoxExpr(e) => {
@@ -762,7 +762,7 @@ impl ExprCollector<'_> {
762 } 762 }
763 ast::Pat::TupleStructPat(p) => { 763 ast::Pat::TupleStructPat(p) => {
764 let path = p.path().and_then(|path| self.expander.parse_path(path)); 764 let path = p.path().and_then(|path| self.expander.parse_path(path));
765 let (args, ellipsis) = self.collect_tuple_pat(p.args()); 765 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
766 Pat::TupleStruct { path, args, ellipsis } 766 Pat::TupleStruct { path, args, ellipsis }
767 } 767 }
768 ast::Pat::RefPat(p) => { 768 ast::Pat::RefPat(p) => {
@@ -780,7 +780,7 @@ impl ExprCollector<'_> {
780 } 780 }
781 ast::Pat::ParenPat(p) => return self.collect_pat_opt(p.pat()), 781 ast::Pat::ParenPat(p) => return self.collect_pat_opt(p.pat()),
782 ast::Pat::TuplePat(p) => { 782 ast::Pat::TuplePat(p) => {
783 let (args, ellipsis) = self.collect_tuple_pat(p.args()); 783 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
784 Pat::Tuple { args, ellipsis } 784 Pat::Tuple { args, ellipsis }
785 } 785 }
786 ast::Pat::WildcardPat(_) => Pat::Wild, 786 ast::Pat::WildcardPat(_) => Pat::Wild,
@@ -809,7 +809,7 @@ impl ExprCollector<'_> {
809 ast::Pat::SlicePat(p) => { 809 ast::Pat::SlicePat(p) => {
810 let SlicePatComponents { prefix, slice, suffix } = p.components(); 810 let SlicePatComponents { prefix, slice, suffix } = p.components();
811 811
812 // FIXME properly handle `DotDotPat` 812 // FIXME properly handle `RestPat`
813 Pat::Slice { 813 Pat::Slice {
814 prefix: prefix.into_iter().map(|p| self.collect_pat(p)).collect(), 814 prefix: prefix.into_iter().map(|p| self.collect_pat(p)).collect(),
815 slice: slice.map(|p| self.collect_pat(p)), 815 slice: slice.map(|p| self.collect_pat(p)),
@@ -827,9 +827,9 @@ impl ExprCollector<'_> {
827 } 827 }
828 } 828 }
829 ast::Pat::RestPat(_) => { 829 ast::Pat::RestPat(_) => {
830 // `DotDotPat` requires special handling and should not be mapped 830 // `RestPat` requires special handling and should not be mapped
831 // to a Pat. Here we are using `Pat::Missing` as a fallback for 831 // to a Pat. Here we are using `Pat::Missing` as a fallback for
832 // when `DotDotPat` is mapped to `Pat`, which can easily happen 832 // when `RestPat` is mapped to `Pat`, which can easily happen
833 // when the source code being analyzed has a malformed pattern 833 // when the source code being analyzed has a malformed pattern
834 // which includes `..` in a place where it isn't valid. 834 // which includes `..` in a place where it isn't valid.
835 835
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 6cb637b1d..5f51c7536 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -893,7 +893,7 @@ pub struct TupleExpr {
893impl ast::AttrsOwner for TupleExpr {} 893impl ast::AttrsOwner for TupleExpr {}
894impl TupleExpr { 894impl TupleExpr {
895 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 895 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
896 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 896 pub fn fields(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
897 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 897 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
898} 898}
899#[derive(Debug, Clone, PartialEq, Eq, Hash)] 899#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1210,7 +1210,7 @@ pub struct SlicePat {
1210} 1210}
1211impl SlicePat { 1211impl SlicePat {
1212 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 1212 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1213 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1213 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1214 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 1214 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1215} 1215}
1216#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1216#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1219,7 +1219,7 @@ pub struct TuplePat {
1219} 1219}
1220impl TuplePat { 1220impl TuplePat {
1221 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 1221 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1222 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1222 pub fn fields(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1223 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1223 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1224} 1224}
1225#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1225#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -1229,7 +1229,7 @@ pub struct TupleStructPat {
1229impl TupleStructPat { 1229impl TupleStructPat {
1230 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 1230 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1231 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 1231 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1232 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1232 pub fn fields(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1233 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1233 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1234} 1234}
1235#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1235#[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index 2ffb83819..733e97877 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -290,7 +290,7 @@ pub struct SlicePatComponents {
290 290
291impl ast::SlicePat { 291impl ast::SlicePat {
292 pub fn components(&self) -> SlicePatComponents { 292 pub fn components(&self) -> SlicePatComponents {
293 let mut args = self.args().peekable(); 293 let mut args = self.pats().peekable();
294 let prefix = args 294 let prefix = args
295 .peeking_take_while(|p| match p { 295 .peeking_take_while(|p| match p {
296 ast::Pat::RestPat(_) => false, 296 ast::Pat::RestPat(_) => false,
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram
index 02f5aa732..aca23890c 100644
--- a/xtask/src/codegen/rust.ungram
+++ b/xtask/src/codegen/rust.ungram
@@ -1,3 +1,7 @@
1//*************************//
2// Names, Paths and Macros //
3//*************************//
4
1Name = 5Name =
2 'ident' 6 'ident'
3 7
@@ -50,6 +54,10 @@ MacroStmts =
50 statements:Stmt* 54 statements:Stmt*
51 Expr? 55 Expr?
52 56
57//*************************//
58// Items //
59//*************************//
60
53SourceFile = 61SourceFile =
54 'shebang'? 62 'shebang'?
55 Attr* 63 Attr*
@@ -245,6 +253,10 @@ Visibility =
245Attr = 253Attr =
246 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']' 254 '#' '!'? '[' Path ('=' Literal | TokenTree)? ']'
247 255
256//****************************//
257// Statements and Expressions //
258//****************************//
259
248Stmt = 260Stmt =
249 ExprStmt 261 ExprStmt
250| Item 262| Item
@@ -347,7 +359,7 @@ IndexExpr =
347 Attr* base:Expr '[' index:Expr ']' 359 Attr* base:Expr '[' index:Expr ']'
348 360
349TupleExpr = 361TupleExpr =
350 Attr* '(' Attr* (Expr (',' Expr)* ','?)? ')' 362 Attr* '(' Attr* fields:(Expr (',' Expr)* ','?)? ')'
351 363
352RecordExpr = 364RecordExpr =
353 Path RecordExprFieldList 365 Path RecordExprFieldList
@@ -434,6 +446,10 @@ AwaitExpr =
434BoxExpr = 446BoxExpr =
435 Attr* 'box' Expr 447 Attr* 'box' Expr
436 448
449//*************************//
450// Types //
451//*************************//
452
437Type = 453Type =
438 ArrayType 454 ArrayType
439| DynTraitType 455| DynTraitType
@@ -495,6 +511,10 @@ TypeBound =
495 'lifetime' 511 'lifetime'
496| '?'? Type 512| '?'? Type
497 513
514//************************//
515// Patterns //
516//************************//
517
498Pat = 518Pat =
499 IdentPat 519 IdentPat
500| BoxPat 520| BoxPat
@@ -540,16 +560,16 @@ RecordPatField =
540 Attr* (NameRef ':')? Pat 560 Attr* (NameRef ':')? Pat
541 561
542TupleStructPat = 562TupleStructPat =
543 Path '(' args:(Pat (',' Pat)* ','?)? ')' 563 Path '(' fields:(Pat (',' Pat)* ','?)? ')'
544 564
545TuplePat = 565TuplePat =
546 '(' args:(Pat (',' Pat)* ','?)? ')' 566 '(' fields:(Pat (',' Pat)* ','?)? ')'
547 567
548ParenPat = 568ParenPat =
549 '(' Pat ')' 569 '(' Pat ')'
550 570
551SlicePat = 571SlicePat =
552 '[' args:(Pat (',' Pat)* ','?)? ']' 572 '[' (Pat (',' Pat)* ','?)? ']'
553 573
554PathPat = 574PathPat =
555 Path 575 Path