aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/items/use_item.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-05-15 13:45:58 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-05-15 13:45:58 +0100
commitec7d2f64ade9ffa35a64e82ac53e65ad5cbe9efd (patch)
treeb8693ce808a9ca2e7eaae5013644a1082fc7bb17 /crates/ra_parser/src/grammar/items/use_item.rs
parent64ab5ab10d32e7e8ec085af818d3d94211aea39b (diff)
parent993abedd77cf23ce2281b6c8e60cab49ab4fa97e (diff)
Merge #1278
1278: Apply T! macro where posible r=matklad a=pasa apply T! macro implemented in #1248 Co-authored-by: Sergey Parilin <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar/items/use_item.rs')
-rw-r--r--crates/ra_parser/src/grammar/items/use_item.rs30
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 908493789..c3a0b4410 100644
--- a/crates/ra_parser/src/grammar/items/use_item.rs
+++ b/crates/ra_parser/src/grammar/items/use_item.rs
@@ -1,10 +1,10 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn use_item(p: &mut Parser, m: Marker) { 3pub(super) fn use_item(p: &mut Parser, m: Marker) {
4 assert!(p.at(USE_KW)); 4 assert!(p.at(T![use]));
5 p.bump(); 5 p.bump();
6 use_tree(p); 6 use_tree(p);
7 p.expect(SEMI); 7 p.expect(T![;]);
8 m.complete(p, USE_ITEM); 8 m.complete(p, USE_ITEM);
9} 9}
10 10
@@ -28,8 +28,8 @@ fn use_tree(p: &mut Parser) {
28 // use ::*; 28 // use ::*;
29 // use some::path::{*}; 29 // use some::path::{*};
30 // use some::path::{::*}; 30 // use some::path::{::*};
31 (STAR, _) => p.bump(), 31 (T![*], _) => p.bump(),
32 (COLONCOLON, STAR) => { 32 (T![::], T![*]) => {
33 // Parse `use ::*;`, which imports all from the crate root in Rust 2015 33 // 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::{::*}`) 34 // 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') 35 // but still parses and errors later: ('crate root in paths can only be used in start position')
@@ -47,8 +47,8 @@ fn use_tree(p: &mut Parser) {
47 // use {path::from::root}; // Rust 2015 47 // use {path::from::root}; // Rust 2015
48 // use ::{some::arbritrary::path}; // Rust 2015 48 // use ::{some::arbritrary::path}; // Rust 2015
49 // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig 49 // use ::{{{crate::export}}}; // Nonsensical but perfectly legal nestnig
50 (L_CURLY, _) | (COLONCOLON, L_CURLY) => { 50 (T!['{'], _) | (T![::], T!['{']) => {
51 if p.at(COLONCOLON) { 51 if p.at(T![::]) {
52 p.bump(); 52 p.bump();
53 } 53 }
54 use_tree_list(p); 54 use_tree_list(p);
@@ -68,7 +68,7 @@ fn use_tree(p: &mut Parser) {
68 _ if paths::is_path_start(p) => { 68 _ if paths::is_path_start(p) => {
69 paths::use_path(p); 69 paths::use_path(p);
70 match p.current() { 70 match p.current() {
71 AS_KW => { 71 T![as] => {
72 // test use_alias 72 // test use_alias
73 // use some::path as some_name; 73 // use some::path as some_name;
74 // use some::{ 74 // use some::{
@@ -80,16 +80,16 @@ 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 COLONCOLON => { 83 T![::] => {
84 p.bump(); 84 p.bump();
85 match p.current() { 85 match p.current() {
86 STAR => { 86 T![*] => {
87 p.bump(); 87 p.bump();
88 } 88 }
89 // test use_tree_list_after_path 89 // test use_tree_list_after_path
90 // use crate::{Item}; 90 // use crate::{Item};
91 // use self::{Item}; 91 // use self::{Item};
92 L_CURLY => use_tree_list(p), 92 T!['{'] => use_tree_list(p),
93 _ => { 93 _ => {
94 // is this unreachable? 94 // is this unreachable?
95 p.error("expected `{` or `*`"); 95 p.error("expected `{` or `*`");
@@ -109,15 +109,15 @@ fn use_tree(p: &mut Parser) {
109} 109}
110 110
111pub(crate) fn use_tree_list(p: &mut Parser) { 111pub(crate) fn use_tree_list(p: &mut Parser) {
112 assert!(p.at(L_CURLY)); 112 assert!(p.at(T!['{']));
113 let m = p.start(); 113 let m = p.start();
114 p.bump(); 114 p.bump();
115 while !p.at(EOF) && !p.at(R_CURLY) { 115 while !p.at(EOF) && !p.at(T!['}']) {
116 use_tree(p); 116 use_tree(p);
117 if !p.at(R_CURLY) { 117 if !p.at(T!['}']) {
118 p.expect(COMMA); 118 p.expect(T![,]);
119 } 119 }
120 } 120 }
121 p.expect(R_CURLY); 121 p.expect(T!['}']);
122 m.complete(p, USE_TREE_LIST); 122 m.complete(p, USE_TREE_LIST);
123} 123}