diff options
author | Laurențiu Nicola <[email protected]> | 2020-06-23 07:41:43 +0100 |
---|---|---|
committer | Laurențiu Nicola <[email protected]> | 2020-06-23 14:51:07 +0100 |
commit | 76ddface089886c88b8b29e3893119f38ef26aab (patch) | |
tree | 9df8e5f774a385d64669f3883a9fef1b6aebb9a2 /crates | |
parent | 98c3e4e887dcc5a8242c3e67c04a3cedbb1b9c58 (diff) |
Fix panic in split and merge import assists
Diffstat (limited to 'crates')
6 files changed, 47 insertions, 4 deletions
diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index 972d16241..ac0b3035c 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs | |||
@@ -127,7 +127,7 @@ fn first_path(path: &ast::Path) -> ast::Path { | |||
127 | 127 | ||
128 | #[cfg(test)] | 128 | #[cfg(test)] |
129 | mod tests { | 129 | mod tests { |
130 | use crate::tests::check_assist; | 130 | use crate::tests::{check_assist, check_assist_not_applicable}; |
131 | 131 | ||
132 | use super::*; | 132 | use super::*; |
133 | 133 | ||
@@ -276,4 +276,14 @@ bar::baz}; | |||
276 | ", | 276 | ", |
277 | ) | 277 | ) |
278 | } | 278 | } |
279 | |||
280 | #[test] | ||
281 | fn test_empty_use() { | ||
282 | check_assist_not_applicable( | ||
283 | merge_imports, | ||
284 | r" | ||
285 | use std::<|> | ||
286 | fn main() {}", | ||
287 | ); | ||
288 | } | ||
279 | } | 289 | } |
diff --git a/crates/ra_assists/src/handlers/split_import.rs b/crates/ra_assists/src/handlers/split_import.rs index c7a874480..38aa199a0 100644 --- a/crates/ra_assists/src/handlers/split_import.rs +++ b/crates/ra_assists/src/handlers/split_import.rs | |||
@@ -66,4 +66,14 @@ mod tests { | |||
66 | fn issue4044() { | 66 | fn issue4044() { |
67 | check_assist_not_applicable(split_import, "use crate::<|>:::self;") | 67 | check_assist_not_applicable(split_import, "use crate::<|>:::self;") |
68 | } | 68 | } |
69 | |||
70 | #[test] | ||
71 | fn test_empty_use() { | ||
72 | check_assist_not_applicable( | ||
73 | split_import, | ||
74 | r" | ||
75 | use std::<|> | ||
76 | fn main() {}", | ||
77 | ); | ||
78 | } | ||
69 | } | 79 | } |
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index 428aa711e..fd51189d5 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs | |||
@@ -73,8 +73,10 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { | |||
73 | } | 73 | } |
74 | p.expect(T![>]); | 74 | p.expect(T![>]); |
75 | } else { | 75 | } else { |
76 | let mut empty = true; | ||
76 | if first { | 77 | if first { |
77 | p.eat(T![::]); | 78 | p.eat(T![::]); |
79 | empty = false; | ||
78 | } | 80 | } |
79 | match p.current() { | 81 | match p.current() { |
80 | IDENT => { | 82 | IDENT => { |
@@ -86,6 +88,12 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { | |||
86 | T![self] | T![super] | T![crate] => p.bump_any(), | 88 | T![self] | T![super] | T![crate] => p.bump_any(), |
87 | _ => { | 89 | _ => { |
88 | p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); | 90 | p.err_recover("expected identifier", items::ITEM_RECOVERY_SET); |
91 | if empty { | ||
92 | // test_err empty_segment | ||
93 | // use crate::; | ||
94 | m.abandon(p); | ||
95 | return; | ||
96 | } | ||
89 | } | 97 | } |
90 | }; | 98 | }; |
91 | } | 99 | } |
diff --git a/crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast b/crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast index 8c6b89dc2..b3bcf472a 100644 --- a/crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast +++ b/crates/ra_syntax/test_data/parser/err/0004_use_path_bad_segment.rast | |||
@@ -9,8 +9,7 @@ [email protected] | |||
9 | [email protected] | 9 | [email protected] |
10 | [email protected] "foo" | 10 | [email protected] "foo" |
11 | [email protected] "::" | 11 | [email protected] "::" |
12 | [email protected] | 12 | [email protected] |
13 | [email protected] | 13 | [email protected] "92" |
14 | [email protected] "92" | ||
15 | [email protected] ";" | 14 | [email protected] ";" |
16 | error 9..9: expected identifier | 15 | error 9..9: expected identifier |
diff --git a/crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rast b/crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rast new file mode 100644 index 000000000..da8505607 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rast | |||
@@ -0,0 +1,15 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] "use" | ||
4 | [email protected] " " | ||
5 | [email protected] | ||
6 | [email protected] | ||
7 | [email protected] | ||
8 | [email protected] | ||
9 | [email protected] "crate" | ||
10 | [email protected] "::" | ||
11 | [email protected] | ||
12 | [email protected] ";" | ||
13 | [email protected] "\n" | ||
14 | error 11..11: expected identifier | ||
15 | error 12..12: expected SEMICOLON | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rs b/crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rs new file mode 100644 index 000000000..7510664e1 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/err/0015_empty_segment.rs | |||
@@ -0,0 +1 @@ | |||
use crate::; | |||