syntax: Always parse pub ( path_start in tuple structs as visibility#33100
syntax: Always parse pub ( path_start in tuple structs as visibility#33100petrochenkov wants to merge 1 commit intorust-lang:masterfrom
pub ( path_start in tuple structs as visibility#33100Conversation
|
Nominating for discussion at lang-team meeting. Just for add'l info, I'll kick off a crater run. |
|
Result of crater run:
|
|
So we discussed this in the @rust-lang/lang meeting yesterday. The conclusion was that, even though there are no regressions observed on crates.io, we don't feel we can make this change. It is too much of a breaking change, in that it effectively breaks "newtype'd tuples". Moreover, it still introduces irregularities in the grammar where extra parens are required. It just seems to be preferring the newer syntax over the old, which is probably the opposite of how we ought to do things. We also discussed the problem more generally. The feeling was that just permitted Therefore I'm going to close the PR. Thanks @petrochenkov in any case! |
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::baras 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 bypubin the macro.Alternatives:
pub (path) TYPEwith hacks. Always parse what goes afterpubas a type (but not$tynonterminal) (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::Pathwrapped intoTyKind::Parenor contains type parameters.pub(crate)(and$visif Add avismatcher 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