Skip to content

Commit 1d2e981

Browse files
committed
internal: parser cleanups
1 parent aaadaa4 commit 1d2e981

17 files changed

+58
-84
lines changed

crates/parser/src/grammar/items/traits.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,23 @@ pub(super) fn trait_(p: &mut Parser, m: Marker) {
4242
m.complete(p, TRAIT);
4343
}
4444

45-
// test impl_def
46-
// impl Foo {}
45+
// test impl_item
46+
// impl S {}
4747
pub(super) fn impl_(p: &mut Parser, m: Marker) {
48-
assert!(p.at(T![impl]));
4948
p.bump(T![impl]);
50-
if choose_type_params_over_qpath(p) {
49+
if p.at(T![<]) && not_a_qualified_path(p) {
5150
type_params::opt_generic_param_list(p);
5251
}
5352

54-
// test impl_def_const
55-
// impl const Send for X {}
53+
// test impl_item_const
54+
// impl const Send for S {}
5655
p.eat(T![const]);
5756

5857
// FIXME: never type
5958
// impl ! {}
6059

61-
// test impl_def_neg
62-
// impl !Send for X {}
60+
// test impl_item_neg
61+
// impl !Send for S {}
6362
p.eat(T![!]);
6463
impl_type(p);
6564
if p.eat(T![for]) {
@@ -74,7 +73,7 @@ pub(super) fn impl_(p: &mut Parser, m: Marker) {
7473
m.complete(p, IMPL);
7574
}
7675

77-
// test impl_item_list
76+
// test assoc_item_list
7877
// impl F {
7978
// type A = i32;
8079
// const B: i32 = 92;
@@ -83,14 +82,11 @@ pub(super) fn impl_(p: &mut Parser, m: Marker) {
8382
// }
8483
pub(crate) fn assoc_item_list(p: &mut Parser) {
8584
assert!(p.at(T!['{']));
85+
8686
let m = p.start();
8787
p.bump(T!['{']);
88-
// test impl_inner_attributes
89-
// enum F{}
90-
// impl F {
91-
// //! This is a doc comment
92-
// #![doc("This is also a doc comment")]
93-
// }
88+
// test assoc_item_list_inner_attrs
89+
// impl S { #![attr] }
9490
attributes::inner_attrs(p);
9591

9692
while !p.at(EOF) && !p.at(T!['}']) {
@@ -106,7 +102,7 @@ pub(crate) fn assoc_item_list(p: &mut Parser) {
106102

107103
// test impl_type_params
108104
// impl<const N: u32> Bar<N> {}
109-
fn choose_type_params_over_qpath(p: &Parser) -> bool {
105+
fn not_a_qualified_path(p: &Parser) -> bool {
110106
// There's an ambiguity between generic parameters and qualified paths in impls.
111107
// If we see `<` it may start both, so we have to inspect some following tokens.
112108
// The following combinations can only start generics,
@@ -123,9 +119,6 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
123119
// we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`)
124120
// because this is what almost always expected in practice, qualified paths in impls
125121
// (`impl <Type>::AssocTy { ... }`) aren't even allowed by type checker at the moment.
126-
if !p.at(T![<]) {
127-
return false;
128-
}
129122
if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == T![const] {
130123
return true;
131124
}

crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast renamed to crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ [email protected]
1515
1616
1717
18-
18+
1919
2020
2121
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
impl !Send for S {}

crates/syntax/test_data/parser/inline/ok/0079_impl_def.rast

Lines changed: 0 additions & 14 deletions
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0079_impl_def.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 14 additions & 0 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
impl S {}

0 commit comments

Comments
 (0)