syntax: Always parse pub ( path_start
in tuple structs as visibility
#33100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #32409 (comment)
Pros: Visibilities can be applied to tuple struct fields, only two symbols of look-ahead are required.
parses as struct with a
pub(restricted)
field of typeu8
.Cons: Some tuple structs stop parsing
We start parsing
pub (foo::bar
as a visibility and fail somewhere in the middle.Why it is not so bad:
((foo, bar))
.(
isn't a path start token, so((foo, bar))
parses as a type. Alternatively, a type alias can be used for(foo, bar)
.(foo::bar::<u8>, foo::baz)
to it without fear of syntactic conflicts even if it's preceeded bypub
in the macro.Alternatives:
pub (path) TYPE
with hacks. Always parse what goes afterpub
as a type (but not$ty
nonterminal) (unless it's(crate)
or$vis
) and try to reinterpret it as a visibility if it's not followed by,
or)
.Reinterpretation fails if the parsed path is not
TyKind::Path
wrapped intoTyKind::Paren
or contains type parameters.pub(crate)
(and$vis
if Add avis
matcher tomacro_rules!
. rfcs#1575 is accepted) in tuple structs. This is essentially this PR other way round - everything that starts like a type parses as a type. However workarounds are wordy ifpub(restricted)
is actually wanted.pub@path
, but would prefer to keep the current syntax).pub(restricted)
in tuple structs. This just looks like a surrender.[breaking-change], needs a crater run before proceeding.
r? @nikomatsakis