diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-09-05 17:53:47 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-09-05 17:53:47 +0100 |
commit | 86f5fd602b20f8ba52c1ba27daa63fedf39ebeb0 (patch) | |
tree | c9221ae272d625fce3751e86afe21e6a623e3b71 | |
parent | edc2016f8b49964fa5b179c1ed8e12e4e0a39702 (diff) | |
parent | b2be998b7b0beb48806cd3a1552e44100b12ddb6 (diff) |
Merge #1767
1767: better error recovery for use trees r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
5 files changed, 65 insertions, 3 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 6d426206e..b4327b78f 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -31,7 +31,7 @@ pub(super) enum ItemFlavor { | |||
31 | 31 | ||
32 | pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ | 32 | pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ |
33 | FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, | 33 | FN_KW, STRUCT_KW, ENUM_KW, IMPL_KW, TRAIT_KW, CONST_KW, STATIC_KW, LET_KW, MOD_KW, PUB_KW, |
34 | CRATE_KW | 34 | CRATE_KW, USE_KW |
35 | ]; | 35 | ]; |
36 | 36 | ||
37 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { | 37 | pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { |
diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index c0c7d0ec6..83a65e226 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs | |||
@@ -101,7 +101,10 @@ fn use_tree(p: &mut Parser) { | |||
101 | } | 101 | } |
102 | _ => { | 102 | _ => { |
103 | m.abandon(p); | 103 | m.abandon(p); |
104 | p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super` or an indentifier"); | 104 | p.err_recover( |
105 | "expected one of `*`, `::`, `{`, `self`, `super` or an identifier", | ||
106 | ITEM_RECOVERY_SET, | ||
107 | ); | ||
105 | return; | 108 | return; |
106 | } | 109 | } |
107 | } | 110 | } |
diff --git a/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt b/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt index 84867026f..bdb5fa6c5 100644 --- a/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt +++ b/crates/ra_syntax/test_data/parser/err/0002_duplicate_shebang.txt | |||
@@ -28,7 +28,7 @@ SOURCE_FILE@[0; 42) | |||
28 | WHITESPACE@[41; 42) "\n" | 28 | WHITESPACE@[41; 42) "\n" |
29 | error 23: expected `[` | 29 | error 23: expected `[` |
30 | error 23: expected an item | 30 | error 23: expected an item |
31 | error 27: expected one of `*`, `::`, `{`, `self`, `super` or an indentifier | 31 | error 27: expected one of `*`, `::`, `{`, `self`, `super` or an identifier |
32 | error 28: expected SEMI | 32 | error 28: expected SEMI |
33 | error 31: expected EXCL | 33 | error 31: expected EXCL |
34 | error 31: expected `{`, `[`, `(` | 34 | error 31: expected `{`, `[`, `(` |
diff --git a/crates/ra_syntax/test_data/parser/err/0035_use_recover.rs b/crates/ra_syntax/test_data/parser/err/0035_use_recover.rs new file mode 100644 index 000000000..4a2668126 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0035_use_recover.rs | |||
@@ -0,0 +1,5 @@ | |||
1 | use foo::bar; | ||
2 | use | ||
3 | use crate::baz; | ||
4 | use | ||
5 | fn f() {} | ||
diff --git a/crates/ra_syntax/test_data/parser/err/0035_use_recover.txt b/crates/ra_syntax/test_data/parser/err/0035_use_recover.txt new file mode 100644 index 000000000..636840828 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0035_use_recover.txt | |||
@@ -0,0 +1,54 @@ | |||
1 | SOURCE_FILE@[0; 48) | ||
2 | USE_ITEM@[0; 13) | ||
3 | USE_KW@[0; 3) "use" | ||
4 | WHITESPACE@[3; 4) " " | ||
5 | USE_TREE@[4; 12) | ||
6 | PATH@[4; 12) | ||
7 | PATH@[4; 7) | ||
8 | PATH_SEGMENT@[4; 7) | ||
9 | NAME_REF@[4; 7) | ||
10 | IDENT@[4; 7) "foo" | ||
11 | COLONCOLON@[7; 9) "::" | ||
12 | PATH_SEGMENT@[9; 12) | ||
13 | NAME_REF@[9; 12) | ||
14 | IDENT@[9; 12) "bar" | ||
15 | SEMI@[12; 13) ";" | ||
16 | WHITESPACE@[13; 14) "\n" | ||
17 | USE_ITEM@[14; 17) | ||
18 | USE_KW@[14; 17) "use" | ||
19 | WHITESPACE@[17; 18) "\n" | ||
20 | USE_ITEM@[18; 33) | ||
21 | USE_KW@[18; 21) "use" | ||
22 | WHITESPACE@[21; 22) " " | ||
23 | USE_TREE@[22; 32) | ||
24 | PATH@[22; 32) | ||
25 | PATH@[22; 27) | ||
26 | PATH_SEGMENT@[22; 27) | ||
27 | CRATE_KW@[22; 27) "crate" | ||
28 | COLONCOLON@[27; 29) "::" | ||
29 | PATH_SEGMENT@[29; 32) | ||
30 | NAME_REF@[29; 32) | ||
31 | IDENT@[29; 32) "baz" | ||
32 | SEMI@[32; 33) ";" | ||
33 | WHITESPACE@[33; 34) "\n" | ||
34 | USE_ITEM@[34; 37) | ||
35 | USE_KW@[34; 37) "use" | ||
36 | WHITESPACE@[37; 38) "\n" | ||
37 | FN_DEF@[38; 47) | ||
38 | FN_KW@[38; 40) "fn" | ||
39 | WHITESPACE@[40; 41) " " | ||
40 | NAME@[41; 42) | ||
41 | IDENT@[41; 42) "f" | ||
42 | PARAM_LIST@[42; 44) | ||
43 | L_PAREN@[42; 43) "(" | ||
44 | R_PAREN@[43; 44) ")" | ||
45 | WHITESPACE@[44; 45) " " | ||
46 | BLOCK_EXPR@[45; 47) | ||
47 | BLOCK@[45; 47) | ||
48 | L_CURLY@[45; 46) "{" | ||
49 | R_CURLY@[46; 47) "}" | ||
50 | WHITESPACE@[47; 48) "\n" | ||
51 | error 17: expected one of `*`, `::`, `{`, `self`, `super` or an identifier | ||
52 | error 17: expected SEMI | ||
53 | error 37: expected one of `*`, `::`, `{`, `self`, `super` or an identifier | ||
54 | error 37: expected SEMI | ||