diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index a8577f2acf7..dd1ecf97e44 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 Bar {} -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 ::absolute::Path { ... }`) // because this is what almost always expected in practice, qualified paths in impls // (`impl ::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 similarity index 100% rename from crates/syntax/test_data/parser/inline/ok/0021_impl_item_list.rast rename to 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 similarity index 100% rename from crates/syntax/test_data/parser/inline/ok/0021_impl_item_list.rs rename to 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 b7527c8705a..00000000000 --- 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 similarity index 94% rename from crates/syntax/test_data/parser/inline/ok/0063_impl_def_neg.rast rename to crates/syntax/test_data/parser/inline/ok/0063_impl_item_neg.rast index 4368930cc91..4ab352223b4 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 @@ SOURCE_FILE@0..20 PATH@15..16 PATH_SEGMENT@15..16 NAME_REF@15..16 - IDENT@15..16 "X" + IDENT@15..16 "S" WHITESPACE@16..17 " " ASSOC_ITEM_LIST@17..19 L_CURLY@17..18 "{" 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 00000000000..a7bd4b048d6 --- /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 209711fc496..00000000000 --- a/crates/syntax/test_data/parser/inline/ok/0079_impl_def.rast +++ /dev/null @@ -1,14 +0,0 @@ -SOURCE_FILE@0..12 - IMPL@0..11 - IMPL_KW@0..4 "impl" - WHITESPACE@4..5 " " - PATH_TYPE@5..8 - PATH@5..8 - PATH_SEGMENT@5..8 - NAME_REF@5..8 - IDENT@5..8 "Foo" - WHITESPACE@8..9 " " - ASSOC_ITEM_LIST@9..11 - L_CURLY@9..10 "{" - R_CURLY@10..11 "}" - WHITESPACE@11..12 "\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 d6337f6b3a7..00000000000 --- 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 00000000000..6516a78f831 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0079_impl_item.rast @@ -0,0 +1,14 @@ +SOURCE_FILE@0..10 + IMPL@0..9 + IMPL_KW@0..4 "impl" + WHITESPACE@4..5 " " + PATH_TYPE@5..6 + PATH@5..6 + PATH_SEGMENT@5..6 + NAME_REF@5..6 + IDENT@5..6 "S" + WHITESPACE@6..7 " " + ASSOC_ITEM_LIST@7..9 + L_CURLY@7..8 "{" + R_CURLY@8..9 "}" + WHITESPACE@9..10 "\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 00000000000..647799d7c14 --- /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 24ac1d66a4f..00000000000 --- a/crates/syntax/test_data/parser/inline/ok/0118_impl_inner_attributes.rast +++ /dev/null @@ -1,41 +0,0 @@ -SOURCE_FILE@0..94 - ENUM@0..8 - ENUM_KW@0..4 "enum" - WHITESPACE@4..5 " " - NAME@5..6 - IDENT@5..6 "F" - VARIANT_LIST@6..8 - L_CURLY@6..7 "{" - R_CURLY@7..8 "}" - WHITESPACE@8..9 "\n" - IMPL@9..93 - IMPL_KW@9..13 "impl" - WHITESPACE@13..14 " " - PATH_TYPE@14..15 - PATH@14..15 - PATH_SEGMENT@14..15 - NAME_REF@14..15 - IDENT@14..15 "F" - WHITESPACE@15..16 " " - ASSOC_ITEM_LIST@16..93 - L_CURLY@16..17 "{" - WHITESPACE@17..23 "\n " - COMMENT@23..48 "//! This is a doc com ..." - WHITESPACE@48..54 "\n " - ATTR@54..91 - POUND@54..55 "#" - BANG@55..56 "!" - L_BRACK@56..57 "[" - META@57..90 - PATH@57..60 - PATH_SEGMENT@57..60 - NAME_REF@57..60 - IDENT@57..60 "doc" - TOKEN_TREE@60..90 - L_PAREN@60..61 "(" - STRING@61..89 "\"This is also a doc c ..." - R_PAREN@89..90 ")" - R_BRACK@90..91 "]" - WHITESPACE@91..92 "\n" - R_CURLY@92..93 "}" - WHITESPACE@93..94 "\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 4d68cceb710..00000000000 --- 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 8d68864693b..00000000000 --- 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 similarity index 95% rename from crates/syntax/test_data/parser/inline/ok/0161_impl_def_const.rast rename to crates/syntax/test_data/parser/inline/ok/0161_impl_item_const.rast index dcd39535b4c..925dfa2f113 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 @@ SOURCE_FILE@0..25 PATH@20..21 PATH_SEGMENT@20..21 NAME_REF@20..21 - IDENT@20..21 "X" + IDENT@20..21 "S" WHITESPACE@21..22 " " ASSOC_ITEM_LIST@22..24 L_CURLY@22..23 "{" 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 00000000000..3252d6f362a --- /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 00000000000..65b4743d141 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rast @@ -0,0 +1,26 @@ +SOURCE_FILE@0..20 + IMPL@0..19 + IMPL_KW@0..4 "impl" + WHITESPACE@4..5 " " + PATH_TYPE@5..6 + PATH@5..6 + PATH_SEGMENT@5..6 + NAME_REF@5..6 + IDENT@5..6 "S" + WHITESPACE@6..7 " " + ASSOC_ITEM_LIST@7..19 + L_CURLY@7..8 "{" + WHITESPACE@8..9 " " + ATTR@9..17 + POUND@9..10 "#" + BANG@10..11 "!" + L_BRACK@11..12 "[" + META@12..16 + PATH@12..16 + PATH_SEGMENT@12..16 + NAME_REF@12..16 + IDENT@12..16 "attr" + R_BRACK@16..17 "]" + WHITESPACE@17..18 " " + R_CURLY@18..19 "}" + WHITESPACE@19..20 "\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 00000000000..915e2c93272 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_assoc_item_list_inner_attrs.rs @@ -0,0 +1 @@ +impl S { #![attr] }