diff options
Diffstat (limited to 'crates/ra_parser/src/grammar/items/use_item.rs')
-rw-r--r-- | crates/ra_parser/src/grammar/items/use_item.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index 83a65e226..f28f522b8 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs | |||
@@ -2,7 +2,7 @@ use super::*; | |||
2 | 2 | ||
3 | pub(super) fn use_item(p: &mut Parser, m: Marker) { | 3 | pub(super) fn use_item(p: &mut Parser, m: Marker) { |
4 | assert!(p.at(T![use])); | 4 | assert!(p.at(T![use])); |
5 | p.bump(); | 5 | p.bump_any(); |
6 | use_tree(p); | 6 | use_tree(p); |
7 | p.expect(T![;]); | 7 | p.expect(T![;]); |
8 | m.complete(p, USE_ITEM); | 8 | m.complete(p, USE_ITEM); |
@@ -13,9 +13,8 @@ pub(super) fn use_item(p: &mut Parser, m: Marker) { | |||
13 | /// so handles both `some::path::{inner::path}` and `inner::path` in | 13 | /// so handles both `some::path::{inner::path}` and `inner::path` in |
14 | /// `use some::path::{inner::path};` | 14 | /// `use some::path::{inner::path};` |
15 | fn use_tree(p: &mut Parser) { | 15 | fn use_tree(p: &mut Parser) { |
16 | let la = p.nth(1); | ||
17 | let m = p.start(); | 16 | let m = p.start(); |
18 | match (p.current(), la) { | 17 | match p.current() { |
19 | // Finish the use_tree for cases of e.g. | 18 | // Finish the use_tree for cases of e.g. |
20 | // `use some::path::{self, *};` or `use *;` | 19 | // `use some::path::{self, *};` or `use *;` |
21 | // This does not handle cases such as `use some::path::*` | 20 | // This does not handle cases such as `use some::path::*` |
@@ -28,15 +27,15 @@ fn use_tree(p: &mut Parser) { | |||
28 | // use ::*; | 27 | // use ::*; |
29 | // use some::path::{*}; | 28 | // use some::path::{*}; |
30 | // use some::path::{::*}; | 29 | // use some::path::{::*}; |
31 | (T![*], _) => p.bump(), | 30 | T![*] => p.bump(T![*]), |
32 | (T![::], T![*]) => { | 31 | T![:] if p.at(T![::]) && p.nth(2) == T![*] => { |
33 | // Parse `use ::*;`, which imports all from the crate root in Rust 2015 | 32 | // Parse `use ::*;`, which imports all from the crate root in Rust 2015 |
34 | // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`) | 33 | // This is invalid inside a use_tree_list, (e.g. `use some::path::{::*}`) |
35 | // but still parses and errors later: ('crate root in paths can only be used in start position') | 34 | // but still parses and errors later: ('crate root in paths can only be used in start position') |
36 | // FIXME: Add this error (if not out of scope) | 35 | // FIXME: Add this error (if not out of scope) |
37 | // In Rust 2018, it is always invalid (see above) | 36 | // In Rust 2018, it is always invalid (see above) |
38 | p.bump(); | 37 | p.bump(T![::]); |
39 | p.bump(); | 38 | p.bump(T![*]); |
40 | } | 39 | } |
41 | // Open a use tree list | 40 | // Open a use tree list |
42 | // Handles cases such as `use {some::path};` or `{inner::path}` in | 41 | // Handles cases such as `use {some::path};` or `{inner::path}` in |
@@ -47,10 +46,11 @@ fn use_tree(p: &mut Parser) { | |||
47 | // use {path::from::root}; // Rust 2015 | 46 | // use {path::from::root}; // Rust 2015 |
48 | // use ::{some::arbritrary::path}; // Rust 2015 | 47 | // use ::{some::arbritrary::path}; // Rust 2015 |
49 | // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig | 48 | // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig |
50 | (T!['{'], _) | (T![::], T!['{']) => { | 49 | T!['{'] => { |
51 | if p.at(T![::]) { | 50 | use_tree_list(p); |
52 | p.bump(); | 51 | } |
53 | } | 52 | T![:] if p.at(T![::]) && p.nth(2) == T!['{'] => { |
53 | p.bump(T![::]); | ||
54 | use_tree_list(p); | 54 | use_tree_list(p); |
55 | } | 55 | } |
56 | // Parse a 'standard' path. | 56 | // Parse a 'standard' path. |
@@ -80,11 +80,11 @@ fn use_tree(p: &mut Parser) { | |||
80 | // use Trait as _; | 80 | // use Trait as _; |
81 | opt_alias(p); | 81 | opt_alias(p); |
82 | } | 82 | } |
83 | T![::] => { | 83 | T![:] if p.at(T![::]) => { |
84 | p.bump(); | 84 | p.bump(T![::]); |
85 | match p.current() { | 85 | match p.current() { |
86 | T![*] => { | 86 | T![*] => { |
87 | p.bump(); | 87 | p.bump_any(); |
88 | } | 88 | } |
89 | // test use_tree_list_after_path | 89 | // test use_tree_list_after_path |
90 | // use crate::{Item}; | 90 | // use crate::{Item}; |
@@ -114,7 +114,7 @@ fn use_tree(p: &mut Parser) { | |||
114 | pub(crate) fn use_tree_list(p: &mut Parser) { | 114 | pub(crate) fn use_tree_list(p: &mut Parser) { |
115 | assert!(p.at(T!['{'])); | 115 | assert!(p.at(T!['{'])); |
116 | let m = p.start(); | 116 | let m = p.start(); |
117 | p.bump(); | 117 | p.bump_any(); |
118 | while !p.at(EOF) && !p.at(T!['}']) { | 118 | while !p.at(EOF) && !p.at(T!['}']) { |
119 | use_tree(p); | 119 | use_tree(p); |
120 | if !p.at(T!['}']) { | 120 | if !p.at(T!['}']) { |