-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give Name
s to positional fields and merge them with named fields
#31937
Conversation
@@ -197,8 +195,8 @@ fn build_struct(cx: &DocContext, tcx: &ty::ctxt, did: DefId) -> clean::Struct { | |||
clean::Struct { | |||
struct_type: match &*variant.fields { | |||
[] => doctree::Unit, | |||
[ref f] if f.name == unnamed_field.name => doctree::Newtype, | |||
[ref f, ..] if f.name == unnamed_field.name => doctree::Tuple, | |||
[_] if variant.kind == ty::VariantKind::Tuple => doctree::Newtype, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this even matters anymore.
LGTM, but maybe @nrc or @Manishearth have more to say? If not, I'll r+ this later. |
I don't think the AST should be touched at all in this case; from a syntax extension perspective having positional fields separated is helpful; and it's not harming much. As far as reusing machinery is concerned, |
actual change lgtm |
Does this fix #27340? |
Indeed, it does. I've added a test for it. |
☔ The latest upstream changes (presumably #32001) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
@bors r+ |
📌 Commit bc93fbc has been approved by |
The names are "0", "1", "2" etc, the same as used in field access. This generally make things simpler and potentially allows to reuse braced struct machinery (struct patterns, struct expressions) for tuple structs. I haven't touched the AST for stability reasons, but I intend to do it later. r? @eddyb
The AST part of rust-lang#31937 Unlike HIR, AST still uses `Option` for field names because parser can't know field indexes reliably due to constructions like ``` struct S(#[cfg(false)] u8, u8); // The index of the second field changes from 1 during parsing to 0 after expansion. ``` and I wouldn't like to put the burden of renaming fields on expansion passes and syntax extensions. plugin-[breaking-change] cc rust-lang#31645 r? @Manishearth
The names are "0", "1", "2" etc, the same as used in field access.
This generally make things simpler and potentially allows to reuse braced struct machinery (struct patterns, struct expressions) for tuple structs.
I haven't touched the AST for stability reasons, but I intend to do it later.
r? @eddyb