From e8d50578ab2702ff5f0955285c979c6923f14f80 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Jun 2020 13:45:18 +0200 Subject: Correctly parse <_> paths in patterns closes #3659 --- crates/ra_parser/src/grammar/patterns.rs | 6 +- .../parser/err/0024_many_type_parens.rast | 74 +++++++++++----------- .../inline/ok/0164_type_path_in_pattern.rast | 38 +++++++++++ .../parser/inline/ok/0164_type_path_in_pattern.rs | 1 + 4 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rast create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rs diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 264cf262e..427c0eb49 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs @@ -88,7 +88,9 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { _ => bind_pat(p, true), }, - _ if paths::is_use_path_start(p) => path_or_macro_pat(p), + // test type_path_in_pattern + // fn main() { let <_>::Foo = (); } + _ if paths::is_path_start(p) => path_or_macro_pat(p), _ if is_literal_pat_start(p) => literal_pat(p), T![.] if p.at(T![..]) => dot_dot_pat(p), @@ -138,7 +140,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker { // let Bar(..) = (); // } fn path_or_macro_pat(p: &mut Parser) -> CompletedMarker { - assert!(paths::is_use_path_start(p)); + assert!(paths::is_path_start(p)); let m = p.start(); paths::expr_path(p); let kind = match p.current() { diff --git a/crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast b/crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast index 7c957fdde..48610a5eb 100644 --- a/crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast +++ b/crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast @@ -180,44 +180,45 @@ SOURCE_FILE@0..240 EXPR_STMT@150..180 TUPLE_EXPR@150..180 L_PAREN@150..151 "(" - BIN_EXPR@151..180 - BIN_EXPR@151..178 - BIN_EXPR@151..169 - BIN_EXPR@151..167 - BIN_EXPR@151..164 - FOR_EXPR@151..157 - FOR_KW@151..154 "for" - ERROR@154..155 - L_ANGLE@154..155 "<" - ERROR@155..157 - LIFETIME@155..157 "\'a" - R_ANGLE@157..158 ">" - WHITESPACE@158..159 " " + FOR_EXPR@151..180 + FOR_KW@151..154 "for" + PATH_PAT@154..158 + PATH@154..158 + PATH_SEGMENT@154..158 + L_ANGLE@154..155 "<" + ERROR@155..157 + LIFETIME@155..157 "\'a" + R_ANGLE@157..158 ">" + WHITESPACE@158..159 " " + BIN_EXPR@159..180 + BIN_EXPR@159..178 + BIN_EXPR@159..169 + BIN_EXPR@159..167 PATH_EXPR@159..164 PATH@159..164 PATH_SEGMENT@159..164 NAME_REF@159..164 IDENT@159..164 "Trait" - L_ANGLE@164..165 "<" - ERROR@165..167 - LIFETIME@165..167 "\'a" - R_ANGLE@167..168 ">" - ERROR@168..169 - R_PAREN@168..169 ")" - WHITESPACE@169..170 " " - PLUS@170..171 "+" - WHITESPACE@171..172 " " - PAREN_EXPR@172..178 - L_PAREN@172..173 "(" - PATH_EXPR@173..177 - PATH@173..177 - PATH_SEGMENT@173..177 - NAME_REF@173..177 - IDENT@173..177 "Copy" - R_PAREN@177..178 ")" - R_ANGLE@178..179 ">" - ERROR@179..180 - SEMICOLON@179..180 ";" + L_ANGLE@164..165 "<" + ERROR@165..167 + LIFETIME@165..167 "\'a" + R_ANGLE@167..168 ">" + ERROR@168..169 + R_PAREN@168..169 ")" + WHITESPACE@169..170 " " + PLUS@170..171 "+" + WHITESPACE@171..172 " " + PAREN_EXPR@172..178 + L_PAREN@172..173 "(" + PATH_EXPR@173..177 + PATH@173..177 + PATH_SEGMENT@173..177 + NAME_REF@173..177 + IDENT@173..177 "Copy" + R_PAREN@177..178 ")" + R_ANGLE@178..179 ">" + ERROR@179..180 + SEMICOLON@179..180 ";" WHITESPACE@180..185 "\n " LET_STMT@185..235 LET_KW@185..188 "let" @@ -302,13 +303,12 @@ error 146..146: expected expression error 147..147: expected SEMICOLON error 148..148: expected expression error 149..149: expected SEMICOLON -error 154..154: expected pattern -error 155..155: expected IN_KW -error 155..155: expected expression -error 157..157: expected a block +error 155..155: expected type +error 158..158: expected IN_KW error 165..165: expected expression error 168..168: expected expression error 179..179: expected expression +error 180..180: expected a block error 180..180: expected COMMA error 180..180: expected expression error 180..180: expected R_PAREN diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rast b/crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rast new file mode 100644 index 000000000..868899275 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rast @@ -0,0 +1,38 @@ +SOURCE_FILE@0..33 + FN_DEF@0..32 + FN_KW@0..2 "fn" + WHITESPACE@2..3 " " + NAME@3..7 + IDENT@3..7 "main" + PARAM_LIST@7..9 + L_PAREN@7..8 "(" + R_PAREN@8..9 ")" + WHITESPACE@9..10 " " + BLOCK_EXPR@10..32 + L_CURLY@10..11 "{" + WHITESPACE@11..12 " " + LET_STMT@12..30 + LET_KW@12..15 "let" + WHITESPACE@15..16 " " + PATH_PAT@16..24 + PATH@16..24 + PATH@16..19 + PATH_SEGMENT@16..19 + L_ANGLE@16..17 "<" + PLACEHOLDER_TYPE@17..18 + UNDERSCORE@17..18 "_" + R_ANGLE@18..19 ">" + COLON2@19..21 "::" + PATH_SEGMENT@21..24 + NAME_REF@21..24 + IDENT@21..24 "Foo" + WHITESPACE@24..25 " " + EQ@25..26 "=" + WHITESPACE@26..27 " " + TUPLE_EXPR@27..29 + L_PAREN@27..28 "(" + R_PAREN@28..29 ")" + SEMICOLON@29..30 ";" + WHITESPACE@30..31 " " + R_CURLY@31..32 "}" + WHITESPACE@32..33 "\n" diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rs b/crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rs new file mode 100644 index 000000000..ebe26834d --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0164_type_path_in_pattern.rs @@ -0,0 +1 @@ +fn main() { let <_>::Foo = (); } -- cgit v1.2.3