Handle pub tuple fields in tuple structs

The current implementation will throw a parser error for tuple structs
that contain a pub tuple field. For example,
```rust
struct Foo(pub (u32, u32));
```
is valid Rust, but rust-analyzer will throw a parser error.  This is
because the parens after `pub` is treated as a visibility context.
Allowing a tuple type to follow `pub` in the special case when we are
defining fields in a tuple struct can fix the issue.
This commit is contained in:
Adam Bratschi-Kaye 2021-11-03 23:57:46 +01:00
parent 04f03a360a
commit 0d54754ca7
5 changed files with 47 additions and 8 deletions

View file

@ -87,7 +87,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) {
pub(super) fn opt_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
// test_err pub_expr
// fn foo() { pub 92; }
let has_visibility = opt_visibility(p);
let has_visibility = opt_visibility(p, false);
let m = match opt_item_without_modifiers(p, m) {
Ok(()) => return Ok(()),

View file

@ -128,7 +128,7 @@ pub(crate) fn record_field_list(p: &mut Parser) {
// test record_field_attrs
// struct S { #[attr] f: f32 }
attributes::outer_attrs(p);
opt_visibility(p);
opt_visibility(p, false);
if p.at(IDENT) {
name(p);
p.expect(T![:]);
@ -150,7 +150,7 @@ fn tuple_field_list(p: &mut Parser) {
// test tuple_field_attrs
// struct S (#[attr] f32);
attributes::outer_attrs(p);
opt_visibility(p);
opt_visibility(p, true);
if !p.at_ts(types::TYPE_FIRST) {
p.error("expected a type");
m.complete(p, ERROR);