aboutsummaryrefslogtreecommitdiff
path: root/crates/parser/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-18 16:13:06 +0000
committerGitHub <[email protected]>2021-01-18 16:13:06 +0000
commit9daba961f236750c3a5d831c9775606271b37eff (patch)
tree6d8c037ea915434701e573bf5eb2eb1f696eef07 /crates/parser/src
parentcc58459ee39db804c0b4a660d1f0bb5c9c0bb648 (diff)
parent98718e0544f42e55642d2838b00d6a7bef1e2414 (diff)
Merge #7291
7291: Wrap remaining self/super/crate in Name{Ref} r=matklad a=Veykril That should be the remaining special casing for `self` 🎉 Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/parser/src')
-rw-r--r--crates/parser/src/grammar.rs12
-rw-r--r--crates/parser/src/grammar/items.rs2
-rw-r--r--crates/parser/src/grammar/params.rs31
3 files changed, 30 insertions, 15 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs
index bb9ffea8b..6913e9ec2 100644
--- a/crates/parser/src/grammar.rs
+++ b/crates/parser/src/grammar.rs
@@ -190,17 +190,25 @@ fn opt_visibility(p: &mut Parser) -> bool {
190 // test crate_visibility 190 // test crate_visibility
191 // pub(crate) struct S; 191 // pub(crate) struct S;
192 // pub(self) struct S; 192 // pub(self) struct S;
193 // pub(self) struct S; 193 // pub(super) struct S;
194 // pub(self) struct S;
195 194
196 // test pub_parens_typepath 195 // test pub_parens_typepath
197 // struct B(pub (super::A)); 196 // struct B(pub (super::A));
198 // struct B(pub (crate::A,)); 197 // struct B(pub (crate::A,));
199 T![crate] | T![self] | T![super] if p.nth(2) != T![:] => { 198 T![crate] | T![self] | T![super] if p.nth(2) != T![:] => {
200 p.bump_any(); 199 p.bump_any();
200 let path_m = p.start();
201 let path_segment_m = p.start();
202 let name_ref_m = p.start();
201 p.bump_any(); 203 p.bump_any();
204 name_ref_m.complete(p, NAME_REF);
205 path_segment_m.complete(p, PATH_SEGMENT);
206 path_m.complete(p, PATH);
202 p.expect(T![')']); 207 p.expect(T![')']);
203 } 208 }
209 // test crate_visibility_in
210 // pub(in super::A) struct S;
211 // pub(in crate) struct S;
204 T![in] => { 212 T![in] => {
205 p.bump_any(); 213 p.bump_any();
206 p.bump_any(); 214 p.bump_any();
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index 2070ce163..1d894e907 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -270,7 +270,9 @@ fn extern_crate(p: &mut Parser, m: Marker) {
270 p.bump(T![crate]); 270 p.bump(T![crate]);
271 271
272 if p.at(T![self]) { 272 if p.at(T![self]) {
273 let m = p.start();
273 p.bump(T![self]); 274 p.bump(T![self]);
275 m.complete(p, NAME_REF);
274 } else { 276 } else {
275 name_ref(p); 277 name_ref(p);
276 } 278 }
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs
index 2d006a1d5..6a98d7368 100644
--- a/crates/parser/src/grammar/params.rs
+++ b/crates/parser/src/grammar/params.rs
@@ -156,7 +156,7 @@ fn variadic_param(p: &mut Parser) -> bool {
156fn opt_self_param(p: &mut Parser, m: Marker) { 156fn opt_self_param(p: &mut Parser, m: Marker) {
157 if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] { 157 if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] {
158 p.eat(T![mut]); 158 p.eat(T![mut]);
159 p.eat(T![self]); 159 self_as_name(p);
160 // test arb_self_types 160 // test arb_self_types
161 // impl S { 161 // impl S {
162 // fn a(self: &Self) {} 162 // fn a(self: &Self) {}
@@ -169,24 +169,29 @@ fn opt_self_param(p: &mut Parser, m: Marker) {
169 let la1 = p.nth(1); 169 let la1 = p.nth(1);
170 let la2 = p.nth(2); 170 let la2 = p.nth(2);
171 let la3 = p.nth(3); 171 let la3 = p.nth(3);
172 let mut n_toks = match (p.current(), la1, la2, la3) { 172 if !matches!((p.current(), la1, la2, la3),
173 (T![&], T![self], _, _) => 2, 173 (T![&], T![self], _, _)
174 (T![&], T![mut], T![self], _) => 3, 174 | (T![&], T![mut], T![self], _)
175 (T![&], LIFETIME_IDENT, T![self], _) => 3, 175 | (T![&], LIFETIME_IDENT, T![self], _)
176 (T![&], LIFETIME_IDENT, T![mut], T![self]) => 4, 176 | (T![&], LIFETIME_IDENT, T![mut], T![self])
177 _ => return m.abandon(p), 177 ) {
178 }; 178 return m.abandon(p);
179 p.bump_any(); 179 }
180 p.bump(T![&]);
180 if p.at(LIFETIME_IDENT) { 181 if p.at(LIFETIME_IDENT) {
181 lifetime(p); 182 lifetime(p);
182 n_toks -= 1;
183 }
184 for _ in 1..n_toks {
185 p.bump_any();
186 } 183 }
184 p.eat(T![mut]);
185 self_as_name(p);
187 } 186 }
188 m.complete(p, SELF_PARAM); 187 m.complete(p, SELF_PARAM);
189 if !p.at(T![')']) { 188 if !p.at(T![')']) {
190 p.expect(T![,]); 189 p.expect(T![,]);
191 } 190 }
192} 191}
192
193fn self_as_name(p: &mut Parser) {
194 let m = p.start();
195 p.bump(T![self]);
196 m.complete(p, NAME);
197}