aboutsummaryrefslogtreecommitdiff
path: root/crates/parser/src/grammar
diff options
context:
space:
mode:
Diffstat (limited to 'crates/parser/src/grammar')
-rw-r--r--crates/parser/src/grammar/items.rs2
-rw-r--r--crates/parser/src/grammar/params.rs31
2 files changed, 20 insertions, 13 deletions
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}