diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 12:41:55 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-12-20 12:41:55 +0000 |
commit | 346456f59ff5eaa653cf8a4b7e0c6672ef1f0566 (patch) | |
tree | 2c6cdaf77d1a64ebf5faa61917dfb8b510f5426a /crates/ra_syntax/src | |
parent | 565a7b07584c16b0113fdf8c6154546546cca900 (diff) | |
parent | 27e814e182b97f8097121aceea8b42a4d4ea31b7 (diff) |
Merge #301
301: Fix break in a condition r=matklad a=DJMcNab
The part of fixing #290.
Co-authored-by: DJMcNab <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions/atom.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index cd7d62aff..3b5749318 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs | |||
@@ -35,11 +35,12 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { | |||
35 | Some(m.complete(p, LITERAL)) | 35 | Some(m.complete(p, LITERAL)) |
36 | } | 36 | } |
37 | 37 | ||
38 | // E.g. for after the break in `if break {}`, this should not match | ||
38 | pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ | 39 | pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ |
39 | LITERAL_FIRST, | 40 | LITERAL_FIRST, |
40 | token_set![ | 41 | token_set![ |
41 | L_CURLY, | ||
42 | L_PAREN, | 42 | L_PAREN, |
43 | L_CURLY, | ||
43 | L_BRACK, | 44 | L_BRACK, |
44 | PIPE, | 45 | PIPE, |
45 | MOVE_KW, | 46 | MOVE_KW, |
@@ -108,7 +109,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
108 | L_CURLY => block_expr(p, None), | 109 | L_CURLY => block_expr(p, None), |
109 | RETURN_KW => return_expr(p), | 110 | RETURN_KW => return_expr(p), |
110 | CONTINUE_KW => continue_expr(p), | 111 | CONTINUE_KW => continue_expr(p), |
111 | BREAK_KW => break_expr(p), | 112 | BREAK_KW => break_expr(p, r), |
112 | _ => { | 113 | _ => { |
113 | p.err_recover("expected expression", EXPR_RECOVERY_SET); | 114 | p.err_recover("expected expression", EXPR_RECOVERY_SET); |
114 | return None; | 115 | return None; |
@@ -427,12 +428,19 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker { | |||
427 | // break 'l 92; | 428 | // break 'l 92; |
428 | // } | 429 | // } |
429 | // } | 430 | // } |
430 | fn break_expr(p: &mut Parser) -> CompletedMarker { | 431 | fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker { |
431 | assert!(p.at(BREAK_KW)); | 432 | assert!(p.at(BREAK_KW)); |
432 | let m = p.start(); | 433 | let m = p.start(); |
433 | p.bump(); | 434 | p.bump(); |
434 | p.eat(LIFETIME); | 435 | p.eat(LIFETIME); |
435 | if p.at_ts(EXPR_FIRST) { | 436 | // test break_ambiguity |
437 | // fn foo(){ | ||
438 | // if break {} | ||
439 | // while break {} | ||
440 | // for i in break {} | ||
441 | // match break {} | ||
442 | // } | ||
443 | if p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(L_CURLY)) { | ||
436 | expr(p); | 444 | expr(p); |
437 | } | 445 | } |
438 | m.complete(p, BREAK_EXPR) | 446 | m.complete(p, BREAK_EXPR) |