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] Fix handling of stripped enum variant in JSON output format #100582

Merged

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-json Area: Rustdoc JSON backend labels Aug 15, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 15, 2022
@rust-log-analyzer

This comment has been minimized.


// @has enum_variant_hidden.json "$.index[*][?(@.name=='ParseError')]"
// @has enum_variant_hidden.json "$.index[*][?(@.name=='UnexpectedEndTag')]"
// @!has enum_variant_hidden.json "$.index[*][?(@.name=='u32')]"
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't test that the field was hidden, as

// @has enum_variant_hidden.json "$.index[*][?(@.name=='ParseError')]"
// @has enum_variant_hidden.json "$.index[*][?(@.name=='UnexpectedEndTag')]"
// @!has enum_variant_hidden.json "$.index[*][?(@.name=='u32')]"

pub enum ParseError {
    UnexpectedEndTag(u32),
}

will also pass the test.

Primitives arn't stored in the index, but in a varient of Type, so the output of the above is

    "inner": {
        "variant_inner": [
          {"inner": "u32", "kind": "primitive"}
        ],
        "variant_kind": "tuple"
      },

Instead, just directly check that the variant doesn't list having any fields.

Suggested change
// @!has enum_variant_hidden.json "$.index[*][?(@.name=='u32')]"
// @is - "$.index[*][?(@.name=='UnexpectedEndTag')].inner.variant_kind" '"tuple"'
// @is - "$.index[*][?(@.name=='UnexpectedEndTag')].inner.variant_inner" []

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion!

@aDotInTheVoid
Copy link
Member

At some point their should also be a has_striped_fields for Variant, and probably a way to tell what position each of the non stripped items are, as currently each of these 3 variants are documented with the same inner.

enum Foo {
  A(i32)
  B(i32, #[doc(hidden)] i32)
  C(#[doc(hidden)] i32, i32)
}

but HTML gets a good representation:

The solution is probably to do what we do for structs, and store the StructType, and a Vec<Id>, such that each field of a varient gets an Item to hold the name. We also should have a num_fields, as even in that schema, you can't tell the difference between

enum Foo {
  A(#[doc(hidden)] i32),
  B(#[doc(hidden)]i32, #[doc(hidden)]i32)
}

This also effects struct AFAIKT.

I don't think this needs to be done now. I'll file an issue for it.

@GuillaumeGomez
Copy link
Member Author

It makes sense. Let's do it in another PR as you suggested then (and thanks for opening the issue!).

@@ -0,0 +1,10 @@
#![no_std]
Copy link
Member

Choose a reason for hiding this comment

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

Some stylistic nitpicks (feel free to ignore)

  • I don't find it's worth using #![no_std], as it doesnt remove enought to make inspecing the output plesent. (wc -c for empty rust file: 371,664 for nothing, 97,448 for #[no_std], 478 for #![no_core]`
  • For json, only the first selection needs to use a the path to a json file, the rest can just use - (Also, we should change jsondocck to know the name of the json file)
  • A link to the issue would be convenient for future reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

All very good points. I'll apply them all. Can you open an issue for jsondocck improvement idea please?

@GuillaumeGomez
Copy link
Member Author

Applied your comments. :)

@notriddle
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 15, 2022

📌 Commit 36758a2 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 15, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 15, 2022
…ed-enum-variant, r=notriddle

[rustdoc] Fix handling of stripped enum variant in JSON output format

Fixes rust-lang#100529.

cc `@aDotInTheVoid` `@Enselic`
r? `@notriddle`
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 15, 2022
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#100031 (improve "try ignoring the field" diagnostic)
 - rust-lang#100325 (Rustdoc-Json: Don't remove impls for items imported from private modules)
 - rust-lang#100377 (Replace - with _ in fluent slugs to improve developer workflows)
 - rust-lang#100458 (Adjust span of fn argument declaration)
 - rust-lang#100514 (Delay span bug when failing to normalize negative coherence impl subject due to other malformed impls)
 - rust-lang#100528 (Support 1st group of RISC-V Bitmanip backend target features)
 - rust-lang#100559 (Parser simplifications)
 - rust-lang#100568 (Fix STD build for ESP-IDF)
 - rust-lang#100582 ([rustdoc] Fix handling of stripped enum variant in JSON output format)
 - rust-lang#100586 (Reland changes replacing num_cpus with available_parallelism )

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@GuillaumeGomez
Copy link
Member Author

@bors r=aDotInTheVoid

@bors
Copy link
Contributor

bors commented Aug 15, 2022

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Aug 15, 2022

📌 Commit 36758a2 has been approved by aDotInTheVoid

It is now in the queue for this repository.

@GuillaumeGomez
Copy link
Member Author

Woups, the update didn't appear until I commented. Sorry.

@bors bors merged commit fba3004 into rust-lang:master Aug 15, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 15, 2022
@GuillaumeGomez GuillaumeGomez deleted the rustdoc-json-stripped-enum-variant branch August 16, 2022 08:56
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc JSON ICE with #[doc(hidden)] on enum tuple field
7 participants