mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 04:26:48 +00:00
internal: parser cleanups
This commit is contained in:
parent
aaadaa40bd
commit
1d2e9818d6
@ -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;
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
impl !Send for X {}
|
@ -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 "{"
|
@ -0,0 +1 @@
|
||||
impl !Send for S {}
|
@ -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"
|
@ -1 +0,0 @@
|
||||
impl Foo {}
|
14
crates/syntax/test_data/parser/inline/ok/0079_impl_item.rast
Normal file
14
crates/syntax/test_data/parser/inline/ok/0079_impl_item.rast
Normal file
@ -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"
|
@ -0,0 +1 @@
|
||||
impl S {}
|
@ -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"
|
@ -1,5 +0,0 @@
|
||||
enum F{}
|
||||
impl F {
|
||||
//! This is a doc comment
|
||||
#![doc("This is also a doc comment")]
|
||||
}
|
@ -1 +0,0 @@
|
||||
impl const Send for X {}
|
@ -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 "{"
|
@ -0,0 +1 @@
|
||||
impl const Send for S {}
|
@ -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"
|
@ -0,0 +1 @@
|
||||
impl S { #![attr] }
|
Loading…
Reference in New Issue
Block a user