Unnamed repository; edit this file 'description' to name the repository.
internal: parser cleanups
17 files changed, 58 insertions, 84 deletions
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index a8577f2acf..dd1ecf97e4 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs @@ -42,24 +42,23 @@ pub(super) fn trait_(p: &mut Parser, m: Marker) { m.complete(p, TRAIT); } -// test impl_def -// impl Foo {} +// test impl_item +// impl S {} pub(super) fn impl_(p: &mut Parser, m: Marker) { - assert!(p.at(T![impl])); p.bump(T![impl]); - if choose_type_params_over_qpath(p) { + if p.at(T![<]) && not_a_qualified_path(p) { type_params::opt_generic_param_list(p); } - // test impl_def_const - // impl const Send for X {} + // test impl_item_const + // impl const Send for S {} p.eat(T![const]); // FIXME: never type // impl ! {} - // test impl_def_neg - // impl !Send for X {} + // test impl_item_neg + // impl !Send for S {} p.eat(T![!]); impl_type(p); if p.eat(T![for]) { @@ -74,7 +73,7 @@ pub(super) fn impl_(p: &mut Parser, m: Marker) { m.complete(p, IMPL); } -// test impl_item_list +// test assoc_item_list // impl F { // type A = i32; // const B: i32 = 92; @@ -83,14 +82,11 @@ pub(super) fn impl_(p: &mut Parser, m: Marker) { // } pub(crate) fn assoc_item_list(p: &mut Parser) { assert!(p.at(T!['{'])); + let m = p.start(); p.bump(T!['{']); - // test impl_inner_attributes - // enum F{} - // impl F { - // //! This is a doc comment - // #![doc("This is also a doc comment")] - // } + // test assoc_item_list_inner_attrs + // impl S { #![attr] } attributes::inner_attrs(p); while !p.at(EOF) && !p.at(T!['}']) { @@ -106,7 +102,7 @@ pub(crate) fn assoc_item_list(p: &mut Parser) { // test impl_type_params // impl<const N: u32> Bar<N> {} -fn choose_type_params_over_qpath(p: &Parser) -> bool { +fn not_a_qualified_path(p: &Parser) -> bool { // There's an ambiguity between generic parameters and qualified paths in impls. // If we see `<` it may start both, so we have to inspect some following tokens. // The following combinations can only start generics, @@ -123,9 +119,6 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { // we disambiguate it in favor of generics (`impl<T> ::absolute::Path<T> { ... }`) // because this is what almost always expected in practice, qualified paths in impls // (`impl <Type>::AssocTy { ... }`) aren't even allowed by type checker at the moment. - if !p.at(T![<]) { - return false; - } if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == T![const] { return true; } diff --git a/crates/syntax/test_data/parser/inline/ok/0021_impl_item_list.rast b/crates/syntax/test_data/parser/inline/ok/0021_assoc_item_list.rast index dc7f6295b2..dc7f6295b2 100644 --- a/crates/syntax/test_data/parser/inline/ok/0021_impl_item_list.rast +++ b/crates/syntax/test_data/parser/inline/ok/0021_assoc_item_list.rast diff --git a/crates/syntax/test_data/parser/inline/ok/0021_impl_item_list.rs b/crates/syntax/test_data/parser/inline/ok/0021_assoc_item_list.rs index f108514879..f108514879 100644 --- a/crates/syntax/test_data/parser/inline/ok/0021_impl_item_list.rs +++ b/crates/syntax/test_data/parser/inline/ok/0021_assoc_item_list.rs diff --git a/crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rs b/crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rs deleted file mode 100644 index b7527c8705..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rs +++ /dev/null @@ -1 +0,0 @@ -impl !Send for X {} diff --git a/crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast b/crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rast index 4368930cc9..4ab352223b 100644 --- a/crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast +++ b/crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rast @@ -15,7 +15,7 @@ [email protected] - [email protected] "X" + [email protected] "S" diff --git a/crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rs b/crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rs new file mode 100644 index 0000000000..a7bd4b048d --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rs @@ -0,0 +1 @@ +impl !Send for S {} diff --git a/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rast b/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rast deleted file mode 100644 index 209711fc49..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rast +++ /dev/null @@ -1,14 +0,0 @@ - [email protected] "impl" - [email protected] " " - [email protected] "Foo" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rs b/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rs deleted file mode 100644 index d6337f6b3a..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rs +++ /dev/null @@ -1 +0,0 @@ -impl Foo {} diff --git a/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rast b/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rast new file mode 100644 index 0000000000..6516a78f83 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rast @@ -0,0 +1,14 @@ + [email protected] "impl" + [email protected] " " + [email protected] "S" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rs b/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rs new file mode 100644 index 0000000000..647799d7c1 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rs @@ -0,0 +1 @@ +impl S {} diff --git a/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast b/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast deleted file mode 100644 index 24ac1d66a4..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast +++ /dev/null @@ -1,41 +0,0 @@ - [email protected] "enum" - [email protected] " " - [email protected] "F" - [email protected] "{" - [email protected] "}" - [email protected] "\n" - [email protected] "impl" - [email protected] " " - [email protected] "F" - [email protected] " " - [email protected] "{" - [email protected] "\n " - [email protected] "//! This is a doc com ..." - [email protected] "\n " - [email protected] "#" - [email protected] "!" - [email protected] "[" - [email protected] "doc" - [email protected] "(" - [email protected] "\"This is also a doc c ..." - [email protected] ")" - [email protected] "]" - [email protected] "\n" - [email protected] "}" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rs b/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rs deleted file mode 100644 index 4d68cceb71..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rs +++ /dev/null @@ -1,5 +0,0 @@ -enum F{} -impl F { - //! This is a doc comment - #![doc("This is also a doc comment")] -} diff --git a/crates/syntax/test_data/parser/inline/ok/0161_impl_def_const.rs b/crates/syntax/test_data/parser/inline/ok/0161_impl_def_const.rs deleted file mode 100644 index 8d68864693..0000000000 --- a/crates/syntax/test_data/parser/inline/ok/0161_impl_def_const.rs +++ /dev/null @@ -1 +0,0 @@ -impl const Send for X {} diff --git a/crates/syntax/test_data/parser/inline/ok/0161_impl_def_const.rast b/crates/syntax/test_data/parser/inline/ok/0161_impl_item_const.rast index dcd39535b4..925dfa2f11 100644 --- a/crates/syntax/test_data/parser/inline/ok/0161_impl_def_const.rast +++ b/crates/syntax/test_data/parser/inline/ok/0161_impl_item_const.rast @@ -16,7 +16,7 @@ [email protected] - [email protected] "X" + [email protected] "S" diff --git a/crates/syntax/test_data/parser/inline/ok/0161_impl_item_const.rs b/crates/syntax/test_data/parser/inline/ok/0161_impl_item_const.rs new file mode 100644 index 0000000000..3252d6f362 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0161_impl_item_const.rs @@ -0,0 +1 @@ +impl const Send for S {} diff --git a/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rast b/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rast new file mode 100644 index 0000000000..65b4743d14 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rast @@ -0,0 +1,26 @@ + [email protected] "impl" + [email protected] " " + [email protected] "S" + [email protected] " " + [email protected] "{" + [email protected] " " + [email protected] "#" + [email protected] "!" + [email protected] "[" + [email protected] "attr" + [email protected] "]" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rs b/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rs new file mode 100644 index 0000000000..915e2c9327 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rs @@ -0,0 +1 @@ +impl S { #![attr] } |