Skip to content

Commit 770b56c

Browse files
bors[bot]matklad
andauthored
Merge #4221
4221: Special-case try macro to better support 2015 edition r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 36775ef + c51c8bf commit 770b56c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

crates/ra_parser/src/grammar/expressions/atom.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,22 @@ fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
535535
fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
536536
assert!(p.at(T![try]));
537537
let m = m.unwrap_or_else(|| p.start());
538+
// Special-case `try!` as macro.
539+
// This is a hack until we do proper edition support
540+
if p.nth_at(1, T![!]) {
541+
// test try_macro_fallback
542+
// fn foo() { try!(Ok(())); }
543+
let path = p.start();
544+
let path_segment = p.start();
545+
let name_ref = p.start();
546+
p.bump_remap(IDENT);
547+
name_ref.complete(p, NAME_REF);
548+
path_segment.complete(p, PATH_SEGMENT);
549+
path.complete(p, PATH);
550+
let _block_like = items::macro_call_after_excl(p);
551+
return m.complete(p, MACRO_CALL);
552+
}
553+
538554
p.bump(T![try]);
539555
block(p);
540556
m.complete(p, TRY_EXPR)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
SOURCE_FILE@0..27
2+
FN_DEF@0..26
3+
FN_KW@0..2 "fn"
4+
WHITESPACE@2..3 " "
5+
NAME@3..6
6+
IDENT@3..6 "foo"
7+
PARAM_LIST@6..8
8+
L_PAREN@6..7 "("
9+
R_PAREN@7..8 ")"
10+
WHITESPACE@8..9 " "
11+
BLOCK_EXPR@9..26
12+
BLOCK@9..26
13+
L_CURLY@9..10 "{"
14+
WHITESPACE@10..11 " "
15+
EXPR_STMT@11..24
16+
MACRO_CALL@11..23
17+
PATH@11..14
18+
PATH_SEGMENT@11..14
19+
NAME_REF@11..14
20+
IDENT@11..14 "try"
21+
BANG@14..15 "!"
22+
TOKEN_TREE@15..23
23+
L_PAREN@15..16 "("
24+
IDENT@16..18 "Ok"
25+
TOKEN_TREE@18..22
26+
L_PAREN@18..19 "("
27+
TOKEN_TREE@19..21
28+
L_PAREN@19..20 "("
29+
R_PAREN@20..21 ")"
30+
R_PAREN@21..22 ")"
31+
R_PAREN@22..23 ")"
32+
SEMICOLON@23..24 ";"
33+
WHITESPACE@24..25 " "
34+
R_CURLY@25..26 "}"
35+
WHITESPACE@26..27 "\n"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn foo() { try!(Ok(())); }

0 commit comments

Comments
 (0)