Correctly parse <_> paths in patterns

closes #3659
This commit is contained in:
Aleksey Kladov 2020-06-09 13:45:18 +02:00
parent 16943e533c
commit e8d50578ab
4 changed files with 80 additions and 39 deletions

View file

@ -88,7 +88,9 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
_ => bind_pat(p, true), _ => 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), _ if is_literal_pat_start(p) => literal_pat(p),
T![.] if p.at(T![..]) => dot_dot_pat(p), T![.] if p.at(T![..]) => dot_dot_pat(p),
@ -138,7 +140,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker {
// let Bar(..) = (); // let Bar(..) = ();
// } // }
fn path_or_macro_pat(p: &mut Parser) -> CompletedMarker { 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(); let m = p.start();
paths::expr_path(p); paths::expr_path(p);
let kind = match p.current() { let kind = match p.current() {

View file

@ -180,19 +180,20 @@ SOURCE_FILE@0..240
EXPR_STMT@150..180 EXPR_STMT@150..180
TUPLE_EXPR@150..180 TUPLE_EXPR@150..180
L_PAREN@150..151 "(" L_PAREN@150..151 "("
BIN_EXPR@151..180 FOR_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" FOR_KW@151..154 "for"
ERROR@154..155 PATH_PAT@154..158
PATH@154..158
PATH_SEGMENT@154..158
L_ANGLE@154..155 "<" L_ANGLE@154..155 "<"
ERROR@155..157 ERROR@155..157
LIFETIME@155..157 "\'a" LIFETIME@155..157 "\'a"
R_ANGLE@157..158 ">" R_ANGLE@157..158 ">"
WHITESPACE@158..159 " " WHITESPACE@158..159 " "
BIN_EXPR@159..180
BIN_EXPR@159..178
BIN_EXPR@159..169
BIN_EXPR@159..167
PATH_EXPR@159..164 PATH_EXPR@159..164
PATH@159..164 PATH@159..164
PATH_SEGMENT@159..164 PATH_SEGMENT@159..164
@ -302,13 +303,12 @@ error 146..146: expected expression
error 147..147: expected SEMICOLON error 147..147: expected SEMICOLON
error 148..148: expected expression error 148..148: expected expression
error 149..149: expected SEMICOLON error 149..149: expected SEMICOLON
error 154..154: expected pattern error 155..155: expected type
error 155..155: expected IN_KW error 158..158: expected IN_KW
error 155..155: expected expression
error 157..157: expected a block
error 165..165: expected expression error 165..165: expected expression
error 168..168: expected expression error 168..168: expected expression
error 179..179: expected expression error 179..179: expected expression
error 180..180: expected a block
error 180..180: expected COMMA error 180..180: expected COMMA
error 180..180: expected expression error 180..180: expected expression
error 180..180: expected R_PAREN error 180..180: expected R_PAREN

View file

@ -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"

View file

@ -0,0 +1 @@
fn main() { let <_>::Foo = (); }