aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-16 23:08:10 +0000
committerAleksey Kladov <[email protected]>2019-01-19 12:37:25 +0000
commitac216880f5d1a3e5727b96d7b22433beec10382b (patch)
treef9d87289f7d870e5346ecb5c007a9ea43e63651b /crates/ra_syntax/src
parent3340807bd24f398dca158e85eebae74012d8ef4b (diff)
Implement unlabeled struct field pattern inference
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs42
1 files changed, 11 insertions, 31 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 3df23b16f..4b7edbbe7 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -664,36 +664,11 @@ impl LiteralExpr {
664 } 664 }
665} 665}
666 666
667// STRUCT_PAT@[20; 42)
668// PATH@[20; 26)
669// PATH_SEGMENT@[20; 26)
670// NAME_REF@[20; 26)
671// IDENT@[20; 26) "Strukt"
672// WHITESPACE@[26; 27)
673// FIELD_PAT_LIST@[27; 42)
674// L_CURLY@[27; 28)
675// WHITESPACE@[28; 29)
676// IDENT@[29; 30) "x"
677// COLON@[30; 31)
678// WHITESPACE@[31; 32)
679// BIND_PAT@[32; 33)
680// NAME@[32; 33)
681// IDENT@[32; 33) "x"
682// COMMA@[33; 34)
683// WHITESPACE@[34; 35)
684// BIND_PAT@[35; 36)
685// NAME@[35; 36)
686// IDENT@[35; 36) "y"
687// COMMA@[36; 37)
688// WHITESPACE@[37; 38)
689// DOTDOT@[38; 40)
690// WHITESPACE@[40; 41)
691// R_CURLY@[41; 42)
692
693#[derive(Clone, Debug, PartialEq, Eq, Hash)] 667#[derive(Clone, Debug, PartialEq, Eq, Hash)]
694pub struct FieldPat { 668pub struct FieldPat {
695 pub ident: SmolStr, 669 pub ident: SmolStr,
696 pub pat: Option<TreeArc<Pat>>, 670 // FIXME: could we use a regular reference?
671 pub pat: TreeArc<Pat>,
697} 672}
698 673
699impl FieldPatList { 674impl FieldPatList {
@@ -704,12 +679,17 @@ impl FieldPatList {
704 let mut pats = Vec::new(); 679 let mut pats = Vec::new();
705 680
706 while let Some(node) = child_iter.next() { 681 while let Some(node) = child_iter.next() {
707 if node.kind() != IDENT { 682 let kind = node.kind();
683 if kind != IDENT && kind != BIND_PAT {
708 continue; 684 continue;
709 } 685 }
710 686
711 let ident = node.leaf_text().unwrap().clone(); 687 let ident = if let Some(text) = node.leaf_text() {
712 let mut pat = None; 688 text.clone()
689 } else {
690 SmolStr::new(node.text().to_string())
691 };
692 let mut pat = Pat::cast(node).map(AstNode::to_owned);
713 693
714 // get pat 694 // get pat
715 while let Some(node) = child_iter.next() { 695 while let Some(node) = child_iter.next() {
@@ -724,7 +704,7 @@ impl FieldPatList {
724 704
725 let field_pat = FieldPat { 705 let field_pat = FieldPat {
726 ident: ident, 706 ident: ident,
727 pat: pat, 707 pat: pat.unwrap(),
728 }; 708 };
729 pats.push(field_pat); 709 pats.push(field_pat);
730 } 710 }