Skip to content
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

Rustdoc-Json: Always put enum fields in their own item #100762

Closed

Conversation

aDotInTheVoid
Copy link
Member

Closes #100587
Closes #92945

See those issues for motivation

r? @GuillaumeGomez

@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 19, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 19, 2022
@aDotInTheVoid
Copy link
Member Author

@rustbot modify labels: +A-rustdoc-json

///
/// ```rust
/// pub struct A(i32);
/// pub struct B();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually didn't know it was a thing. :o

@aDotInTheVoid aDotInTheVoid force-pushed the rdj-enum-field-item branch 2 times, most recently from e680554 to ed9b778 Compare August 19, 2022 22:28
fields_stripped: fields.iter().any(|i| i.is_stripped()),
},
Struct(s) => Variant {
kind: StructKind::NamedFields,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thought about it: NamedFields sounds a bit weird. Wouldn't it be better to have something similar to what already exists? For example VariantData.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with that is having struct.kind == StructKind::Struct isn't informative, as all 3 kinds can be "structs".

Another option is to use StructKind::Normal, as most structs use {}, but thats not the "normal" option for enum variants, which are mostly tuple or unit.

While it's not the name used in compiler internals, we haven't done that for other parts of the output (eg using type_ instead of ty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplying the number of terms isn't the best idea either but I'm not great for naming... Does it seem good to you @Manishearth ?

Tuple(fields) => Variant {
kind: StructKind::Tuple,
fields: ids(&fields, tcx),
fields_stripped: fields.iter().any(|i| i.is_stripped()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been experimenting with this code (see cargo-public-api/cargo-public-api#99) and have the following question/concern: What is the value of having a bool to specify if some field is stripped? Wouldn't it be better to remove fields_stripped and instead add info on a per-field level if it is stripped or not? Later today I think I will have time to develop a concrete proposal on how it could look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is to not show stripped fields and just say more fields exist but they're not part of the public API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have higher fidelity than "more fields exist" and also be able to easily say which fields have been stripped. In other words, be on par with rustdoc HTML output, which looks like this:

pub enum EnumWithStrippedTupleVariants {
    Double(bool, bool),
    DoubleFirstHidden(_, bool),
    DoubleSecondHidden(bool, _),
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some options for this:

1: Also give the number of fields. The relative position of fields can be determined by the number in the name for tuple, and not at all for structs.
2: Instead of having a Vec<Id>, have a Vec<Option>, and use None` for stripped fields.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 sounds good! I haven't had time to experiment but that should work well.

Not a fan of 1 because names having special meaning seems too fragile for an API.

@bors
Copy link
Contributor

bors commented Aug 23, 2022

☔ The latest upstream changes (presumably #100678) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot
Copy link
Collaborator

rustbot commented Aug 23, 2022

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @aDotInTheVoid, @Enselic

Tuple(Vec<Type>),
Struct(Vec<Id>),
pub struct Variant {
pub kind: StructKind,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a separate enum for variant kinds and struct kinds, as unit variants may have a discriminant value, which currently we don't document but should. See cargo-public-api/cargo-public-api#121 and zulip discussion

@bors
Copy link
Contributor

bors commented Sep 5, 2022

☔ The latest upstream changes (presumably #101386) made this pull request unmergeable. Please resolve the merge conflicts.

@aDotInTheVoid
Copy link
Member Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 5, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 6, 2022
…GuillaumeGomez

Rustdoc-Json: Store Variant Fields as their own item.

Closes rust-lang#100587
Closes rust-lang#92945

Successor to rust-lang#100762

Unlike that one, we don't have merge `StructType` and `Variant`, as after rust-lang#101386 `Variant` stores enum specific information (discriminant).

Resolves the naming discussion (rust-lang#100762 (comment)) by having seperate enums for struct and enum kinds

Resolves `#[doc(hidden)]` on tuple structs (rust-lang#100762 (comment)) by storing as a `Vec<Option<Id>>`

r? `@GuillaumeGomez`
@Enselic
Copy link
Member

Enselic commented Sep 7, 2022

Since #101462 that succeeded this PR has been merged, I think this PR can be flat-out closed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
6 participants