aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/expressions.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-17 10:50:06 +0000
committerGitHub <[email protected]>2020-01-17 10:50:06 +0000
commit07dca1123dfaec527c6ba3164125309f5c4cc3db (patch)
tree36e66272f2da663034059df83f299e20c84d27de /crates/ra_parser/src/grammar/expressions.rs
parent90b8a31b83b1aafc3fb555ba4307527f9258f46d (diff)
parent3a859e587f3bcf9f49293bd1f2b2d19cdfd2be4b (diff)
Merge #2867
2867: Nest attrs into exprs in function args r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar/expressions.rs')
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs25
1 files changed, 21 insertions, 4 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index a31a7a08d..06c92645e 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -19,6 +19,26 @@ pub(super) fn expr(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
19 expr_bp(p, r, 1) 19 expr_bp(p, r, 1)
20} 20}
21 21
22pub(super) fn expr_with_attrs(p: &mut Parser) -> bool {
23 let m = p.start();
24 let has_attrs = p.at(T![#]);
25 attributes::outer_attributes(p);
26
27 let (cm, _block_like) = expr(p);
28 let success = cm.is_some();
29
30 match (has_attrs, cm) {
31 (true, Some(cm)) => {
32 let kind = cm.kind();
33 cm.undo_completion(p).abandon(p);
34 m.complete(p, kind);
35 }
36 _ => m.abandon(p),
37 }
38
39 success
40}
41
22pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) { 42pub(super) fn expr_stmt(p: &mut Parser) -> (Option<CompletedMarker>, BlockLike) {
23 let r = Restrictions { forbid_structs: false, prefer_stmt: true }; 43 let r = Restrictions { forbid_structs: false, prefer_stmt: true };
24 expr_bp(p, r, 1) 44 expr_bp(p, r, 1)
@@ -544,12 +564,9 @@ fn arg_list(p: &mut Parser) {
544 // fn main() { 564 // fn main() {
545 // foo(#[attr] 92) 565 // foo(#[attr] 92)
546 // } 566 // }
547 attributes::outer_attributes(p); 567 if !expr_with_attrs(p) {
548 if !p.at_ts(EXPR_FIRST) {
549 p.error("expected expression");
550 break; 568 break;
551 } 569 }
552 expr(p);
553 if !p.at(T![')']) && !p.expect(T![,]) { 570 if !p.at(T![')']) && !p.expect(T![,]) {
554 break; 571 break;
555 } 572 }