aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/items/traits.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/traits.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/traits.rs')
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs38
1 files changed, 19 insertions, 19 deletions
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs
index d03a6be0d..09ab3bfd4 100644
--- a/crates/ra_parser/src/grammar/items/traits.rs
+++ b/crates/ra_parser/src/grammar/items/traits.rs
@@ -4,15 +4,15 @@ use super::*;
4// trait T<U>: Hash + Clone where U: Copy {} 4// trait T<U>: Hash + Clone where U: Copy {}
5// trait X<U: Debug + Display>: Hash + Clone where U: Copy {} 5// trait X<U: Debug + Display>: Hash + Clone where U: Copy {}
6pub(super) fn trait_def(p: &mut Parser) { 6pub(super) fn trait_def(p: &mut Parser) {
7 assert!(p.at(TRAIT_KW)); 7 assert!(p.at(T![trait]));
8 p.bump(); 8 p.bump();
9 name_r(p, ITEM_RECOVERY_SET); 9 name_r(p, ITEM_RECOVERY_SET);
10 type_params::opt_type_param_list(p); 10 type_params::opt_type_param_list(p);
11 if p.at(COLON) { 11 if p.at(T![:]) {
12 type_params::bounds(p); 12 type_params::bounds(p);
13 } 13 }
14 type_params::opt_where_clause(p); 14 type_params::opt_where_clause(p);
15 if p.at(L_CURLY) { 15 if p.at(T!['{']) {
16 trait_item_list(p); 16 trait_item_list(p);
17 } else { 17 } else {
18 p.error("expected `{`"); 18 p.error("expected `{`");
@@ -27,24 +27,24 @@ pub(super) fn trait_def(p: &mut Parser) {
27// fn bar(&self); 27// fn bar(&self);
28// } 28// }
29pub(crate) fn trait_item_list(p: &mut Parser) { 29pub(crate) fn trait_item_list(p: &mut Parser) {
30 assert!(p.at(L_CURLY)); 30 assert!(p.at(T!['{']));
31 let m = p.start(); 31 let m = p.start();
32 p.bump(); 32 p.bump();
33 while !p.at(EOF) && !p.at(R_CURLY) { 33 while !p.at(EOF) && !p.at(T!['}']) {
34 if p.at(L_CURLY) { 34 if p.at(T!['{']) {
35 error_block(p, "expected an item"); 35 error_block(p, "expected an item");
36 continue; 36 continue;
37 } 37 }
38 item_or_macro(p, true, ItemFlavor::Trait); 38 item_or_macro(p, true, ItemFlavor::Trait);
39 } 39 }
40 p.expect(R_CURLY); 40 p.expect(T!['}']);
41 m.complete(p, ITEM_LIST); 41 m.complete(p, ITEM_LIST);
42} 42}
43 43
44// test impl_block 44// test impl_block
45// impl Foo {} 45// impl Foo {}
46pub(super) fn impl_block(p: &mut Parser) { 46pub(super) fn impl_block(p: &mut Parser) {
47 assert!(p.at(IMPL_KW)); 47 assert!(p.at(T![impl ]));
48 p.bump(); 48 p.bump();
49 if choose_type_params_over_qpath(p) { 49 if choose_type_params_over_qpath(p) {
50 type_params::opt_type_param_list(p); 50 type_params::opt_type_param_list(p);
@@ -55,13 +55,13 @@ pub(super) fn impl_block(p: &mut Parser) {
55 55
56 // test impl_block_neg 56 // test impl_block_neg
57 // impl !Send for X {} 57 // impl !Send for X {}
58 p.eat(EXCL); 58 p.eat(T![!]);
59 impl_type(p); 59 impl_type(p);
60 if p.eat(FOR_KW) { 60 if p.eat(T![for]) {
61 impl_type(p); 61 impl_type(p);
62 } 62 }
63 type_params::opt_where_clause(p); 63 type_params::opt_where_clause(p);
64 if p.at(L_CURLY) { 64 if p.at(T!['{']) {
65 impl_item_list(p); 65 impl_item_list(p);
66 } else { 66 } else {
67 p.error("expected `{`"); 67 p.error("expected `{`");
@@ -76,7 +76,7 @@ pub(super) fn impl_block(p: &mut Parser) {
76// fn bar(&self) {} 76// fn bar(&self) {}
77// } 77// }
78pub(crate) fn impl_item_list(p: &mut Parser) { 78pub(crate) fn impl_item_list(p: &mut Parser) {
79 assert!(p.at(L_CURLY)); 79 assert!(p.at(T!['{']));
80 let m = p.start(); 80 let m = p.start();
81 p.bump(); 81 p.bump();
82 // test impl_inner_attributes 82 // test impl_inner_attributes
@@ -87,14 +87,14 @@ pub(crate) fn impl_item_list(p: &mut Parser) {
87 // } 87 // }
88 attributes::inner_attributes(p); 88 attributes::inner_attributes(p);
89 89
90 while !p.at(EOF) && !p.at(R_CURLY) { 90 while !p.at(EOF) && !p.at(T!['}']) {
91 if p.at(L_CURLY) { 91 if p.at(T!['{']) {
92 error_block(p, "expected an item"); 92 error_block(p, "expected an item");
93 continue; 93 continue;
94 } 94 }
95 item_or_macro(p, true, ItemFlavor::Mod); 95 item_or_macro(p, true, ItemFlavor::Mod);
96 } 96 }
97 p.expect(R_CURLY); 97 p.expect(T!['}']);
98 m.complete(p, ITEM_LIST); 98 m.complete(p, ITEM_LIST);
99} 99}
100 100
@@ -114,14 +114,14 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
114 // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`) 114 // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
115 // because this is what almost always expected in practice, qualified paths in impls 115 // because this is what almost always expected in practice, qualified paths in impls
116 // (`impl <Type>::AssocTy { ... }`) aren't even allowed by type checker at the moment. 116 // (`impl <Type>::AssocTy { ... }`) aren't even allowed by type checker at the moment.
117 if !p.at(L_ANGLE) { 117 if !p.at(T![<]) {
118 return false; 118 return false;
119 } 119 }
120 if p.nth(1) == POUND || p.nth(1) == R_ANGLE { 120 if p.nth(1) == T![#] || p.nth(1) == T![>] {
121 return true; 121 return true;
122 } 122 }
123 (p.nth(1) == LIFETIME || p.nth(1) == IDENT) 123 (p.nth(1) == LIFETIME || p.nth(1) == IDENT)
124 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) 124 && (p.nth(2) == T![>] || p.nth(2) == T![,] || p.nth(2) == T![:] || p.nth(2) == T![=])
125} 125}
126 126
127// test_err impl_type 127// test_err impl_type
@@ -130,7 +130,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
130// impl impl NotType {} 130// impl impl NotType {}
131// impl Trait2 for impl NotType {} 131// impl Trait2 for impl NotType {}
132pub(crate) fn impl_type(p: &mut Parser) { 132pub(crate) fn impl_type(p: &mut Parser) {
133 if p.at(IMPL_KW) { 133 if p.at(T![impl ]) {
134 p.error("expected trait or type"); 134 p.error("expected trait or type");
135 return; 135 return;
136 } 136 }