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: Precise capturing JSON is untyped #137616

Closed
Enselic opened this issue Feb 25, 2025 · 2 comments · Fixed by #138109
Closed

rustdoc-json: Precise capturing JSON is untyped #137616

Enselic opened this issue Feb 25, 2025 · 2 comments · Fixed by #138109
Assignees
Labels
A-rustdoc-json Area: Rustdoc JSON backend C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-precise_capturing `#![feature(precise_capturing)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Enselic
Copy link
Member

Enselic commented Feb 25, 2025

Given this function:

pub fn capture<'a, T>(x: &'a (), y: T) -> impl Sized + use<'a, T> {
    (x, y)
}

we can see this rustdoc JSON for the function output type:

rustdoc +nightly -Zunstable-options --output-format json src/lib.rs
  "output": {
      "impl_trait": [
          {
              "trait_bound": {
                  "trait": {
                      "path": "Sized",
                      "id": 1,
                      "args": {
                          "angle_bracketed": {
                              "args": [],
                              "constraints": []
                          }
                      }
                  },
                  "generic_params": [],
                  "modifier": "none"
              }
          },
          {
              "use": [
                  "'a",
                  "T"
              ]
          }
      ]
  },

Note that the use data is completely untyped and just raw strings:

          {
              "use": [
                  "'a",
                  "T"
              ]
          }

We probably want to use different JSON types at least for generic args and lifetimes before we stabilize the format.

Right now cargo-public-api resorts to a "if string begins with ' " hack.

@Enselic Enselic added A-rustdoc-json Area: Rustdoc JSON backend C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 25, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2025
@Enselic Enselic removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2025
@fmease fmease added the F-precise_capturing `#![feature(precise_capturing)]` label Feb 25, 2025
@aDotInTheVoid
Copy link
Member

By the time it's in clean, it's already a Vec<Symbol>: https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/enum.GenericBound.html#variant.Use

But the distinction does exist in Hir: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.GenericBound.html

So a fix to this would need to:

  1. Change rustdoc::clean::types::GenericBound::Use to use PreciseCapturingArg (either the HIR one, or a new one that's just in clean)
    1.1. Fix fallout from this in rustdoc::html
  2. Change rustdoc_json_types::GenericBound::Use to use PreciseCapturingArg (which must be a new enum in rustdoc_json_types)
  3. Update tests/rustdoc-json (and potentially add new ones if there's not enough coverage).
  4. Bump rustdoc_json_types::FORMAT_VERSION

@aDotInTheVoid aDotInTheVoid added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Feb 26, 2025
@Kohei316
Copy link
Contributor

@rustbot claim

jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 10, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 10, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 11, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 11, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 12, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 12, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 13, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 13, 2025
…turing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
@bors bors closed this as completed in 1a7d2b9 Mar 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 13, 2025
Rollup merge of rust-lang#138109 - Kohei316:feat/rust-doc-precise-capturing-arg, r=aDotInTheVoid,compiler-errors

make precise capturing args in rustdoc Json typed

close rust-lang#137616

This PR includes below changes.

- Add `rustc_hir::PreciseCapturingArgKind` which allows the query system to return a arg's data.
- Add `rustdoc::clean::types::PreciseCapturingArg` and change to use it.
- Add `rustdoc-json-types::PreciseCapturingArg` and change to use it.
- Update `tests/rustdoc-json/impl-trait-precise-capturing.rs`.
- Bump `rustdoc_json_types::FORMAT_VERSION`.
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-precise_capturing `#![feature(precise_capturing)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants