mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-31 23:38:45 +00:00
Auto merge of #14449 - Veykril:parser-vis-recov, r=Veykril
fix: Recover from `pub()` visibility modifier
This commit is contained in:
commit
5c6a38abde
5 changed files with 68 additions and 3 deletions
|
@ -218,17 +218,22 @@ fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
|
||||||
// pub(self) struct S;
|
// pub(self) struct S;
|
||||||
// pub(super) struct S;
|
// pub(super) struct S;
|
||||||
|
|
||||||
|
// test_err crate_visibility_empty_recover
|
||||||
|
// pub() struct S;
|
||||||
|
|
||||||
// test pub_parens_typepath
|
// test pub_parens_typepath
|
||||||
// struct B(pub (super::A));
|
// struct B(pub (super::A));
|
||||||
// struct B(pub (crate::A,));
|
// struct B(pub (crate::A,));
|
||||||
T![crate] | T![self] | T![super] | T![ident] if p.nth(2) != T![:] => {
|
T![crate] | T![self] | T![super] | T![ident] | T![')'] if p.nth(2) != T![:] => {
|
||||||
// If we are in a tuple struct, then the parens following `pub`
|
// If we are in a tuple struct, then the parens following `pub`
|
||||||
// might be an tuple field, not part of the visibility. So in that
|
// might be an tuple field, not part of the visibility. So in that
|
||||||
// case we don't want to consume an identifier.
|
// case we don't want to consume an identifier.
|
||||||
|
|
||||||
// test pub_tuple_field
|
// test pub_tuple_field
|
||||||
// struct MyStruct(pub (u32, u32));
|
// struct MyStruct(pub (u32, u32));
|
||||||
if !(in_tuple_field && matches!(p.nth(1), T![ident])) {
|
// struct MyStruct(pub (u32));
|
||||||
|
// struct MyStruct(pub ());
|
||||||
|
if !(in_tuple_field && matches!(p.nth(1), T![ident] | T![')'])) {
|
||||||
p.bump(T!['(']);
|
p.bump(T!['(']);
|
||||||
paths::use_path(p);
|
paths::use_path(p);
|
||||||
p.expect(T![')']);
|
p.expect(T![')']);
|
||||||
|
@ -243,7 +248,7 @@ fn opt_visibility(p: &mut Parser<'_>, in_tuple_field: bool) -> bool {
|
||||||
paths::use_path(p);
|
paths::use_path(p);
|
||||||
p.expect(T![')']);
|
p.expect(T![')']);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.complete(p, VISIBILITY);
|
m.complete(p, VISIBILITY);
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
SOURCE_FILE
|
||||||
|
STRUCT
|
||||||
|
VISIBILITY
|
||||||
|
PUB_KW "pub"
|
||||||
|
L_PAREN "("
|
||||||
|
PATH
|
||||||
|
PATH_SEGMENT
|
||||||
|
ERROR
|
||||||
|
R_PAREN ")"
|
||||||
|
WHITESPACE " "
|
||||||
|
STRUCT_KW "struct"
|
||||||
|
WHITESPACE " "
|
||||||
|
NAME
|
||||||
|
IDENT "S"
|
||||||
|
SEMICOLON ";"
|
||||||
|
WHITESPACE "\n"
|
||||||
|
error 4: expected identifier
|
||||||
|
error 5: expected R_PAREN
|
|
@ -0,0 +1 @@
|
||||||
|
pub() struct S;
|
|
@ -28,3 +28,42 @@ SOURCE_FILE
|
||||||
R_PAREN ")"
|
R_PAREN ")"
|
||||||
SEMICOLON ";"
|
SEMICOLON ";"
|
||||||
WHITESPACE "\n"
|
WHITESPACE "\n"
|
||||||
|
STRUCT
|
||||||
|
STRUCT_KW "struct"
|
||||||
|
WHITESPACE " "
|
||||||
|
NAME
|
||||||
|
IDENT "MyStruct"
|
||||||
|
TUPLE_FIELD_LIST
|
||||||
|
L_PAREN "("
|
||||||
|
TUPLE_FIELD
|
||||||
|
VISIBILITY
|
||||||
|
PUB_KW "pub"
|
||||||
|
WHITESPACE " "
|
||||||
|
PAREN_TYPE
|
||||||
|
L_PAREN "("
|
||||||
|
PATH_TYPE
|
||||||
|
PATH
|
||||||
|
PATH_SEGMENT
|
||||||
|
NAME_REF
|
||||||
|
IDENT "u32"
|
||||||
|
R_PAREN ")"
|
||||||
|
R_PAREN ")"
|
||||||
|
SEMICOLON ";"
|
||||||
|
WHITESPACE "\n"
|
||||||
|
STRUCT
|
||||||
|
STRUCT_KW "struct"
|
||||||
|
WHITESPACE " "
|
||||||
|
NAME
|
||||||
|
IDENT "MyStruct"
|
||||||
|
TUPLE_FIELD_LIST
|
||||||
|
L_PAREN "("
|
||||||
|
TUPLE_FIELD
|
||||||
|
VISIBILITY
|
||||||
|
PUB_KW "pub"
|
||||||
|
WHITESPACE " "
|
||||||
|
TUPLE_TYPE
|
||||||
|
L_PAREN "("
|
||||||
|
R_PAREN ")"
|
||||||
|
R_PAREN ")"
|
||||||
|
SEMICOLON ";"
|
||||||
|
WHITESPACE "\n"
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
struct MyStruct(pub (u32, u32));
|
struct MyStruct(pub (u32, u32));
|
||||||
|
struct MyStruct(pub (u32));
|
||||||
|
struct MyStruct(pub ());
|
||||||
|
|
Loading…
Reference in a new issue