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: Dangling ID for trait impl with pub struct in #[doc(hidden)] mod #112852

Open
Tracked by #106435
aDotInTheVoid opened this issue Jun 20, 2023 · 0 comments
Open
Tracked by #106435
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Jun 20, 2023

#![feature(no_core)]
#![no_core]

pub trait PubTrait {}

#[doc(hidden)]
pub mod hidden {
    pub struct HiddenPubStruct;

    impl crate::PubTrait for HiddenPubStruct {}
}
---- [rustdoc-json] tests/rustdoc-json/impls/impl_for_hidden_mod.rs stdout ----

error: jsondoclint failed!
status: exit status: 1
command: "/home/gh-aDotInTheVoid/rust/build/aarch64-unknown-linux-gnu/stage0-tools-bin/jsondoclint" "/home/gh-aDotInTheVoid/rust/build/aarch64-unknown-linux-gnu/test/rustdoc-json/impls/impl_for_hidden_mod/impl_for_hidden_mod.json"
stdout: none
--- stderr -------------------------------
0:3:1629 not in index or paths, but referred to at '$.index["0:5"].inner.impl.for.resolved_path.id'
Error: Errors validating json /home/gh-aDotInTheVoid/rust/build/aarch64-unknown-linux-gnu/test/rustdoc-json/impls/impl_for_hidden_mod/impl_for_hidden_mod.json
------------------------------------------
{
  "crate_version": null,
  "external_crates": {},
  "format_version": 26,
  "includes_private": false,
  "index": {
    "0:0:1630": {
      "inner": {"module": {"is_crate": true, "is_stripped": false, "items": ["0:1:1628"]}},
      "name": "impl_for_hidden_mod"
    },
    "0:1:1628": {
      "inner": {
        "trait": {
          "bounds": [],
          "generics": {"params": [], "where_predicates": []},
          "implementations": ["0:5"],
          "is_auto": false,
          "is_unsafe": false,
          "items": []
        }
      },
      "name": "PubTrait"
    },
    "0:5": {
      "inner": {
        "impl": {
          "blanket_impl": null,
          "for": {
            "resolved_path": {
              "args": {"angle_bracketed": {"args": [], "bindings": []}},
              "id": "0:3:1629",
              "name": "HiddenPubStruct"
            }
          },
          "generics": {"params": [], "where_predicates": []},
          "is_unsafe": false,
          "items": [],
          "negative": false,
          "provided_trait_methods": [],
          "synthetic": false,
          "trait": {
            "args": {"angle_bracketed": {"args": [], "bindings": []}},
            "id": "0:1:1628",
            "name": "PubTrait"
          }
        }
      },
      "name": null
    }
  },
  "paths": {
    "0:0:1630": {"crate_id": 0, "kind": "module", "path": ["impl_for_hidden_mod"]},
    "0:1:1628": {"crate_id": 0, "kind": "trait", "path": ["impl_for_hidden_mod", "PubTrait"]}
  },
  "root": "0:0:1630"
}

The right thing to do would be to strip the impl, as the struct isn't reachable. We do this correctly if the #[doc(hidden)] is on the struct

#![feature(no_core)]
#![no_core]

pub trait PubTrait {}

#[doc(hidden)]
pub struct HiddenPubStruct;

impl PubTrait for HiddenPubStruct {}
{
  "crate_version": null,
  "external_crates": {},
  "format_version": 26,
  "includes_private": false,
  "index": {
    "0:0:1630": {
      "inner": {"module": {"is_crate": true, "is_stripped": false, "items": ["0:1:1628"]}},
      "name": "impl_for_hidden_struct"
    },
    "0:1:1628": {
      "inner": {
        "trait": {
          "bounds": [],
          "generics": {"params": [], "where_predicates": []},
          "implementations": [],
          "is_auto": false,
          "is_unsafe": false,
          "items": []
        }
      },
      "name": "PubTrait"
    }
  },
  "paths": {
    "0:0:1630": {"crate_id": 0, "kind": "module", "path": ["impl_for_hidden_struct"]},
    "0:1:1628": {"crate_id": 0, "kind": "trait", "path": ["impl_for_hidden_struct", "PubTrait"]}
  },
  "root": "0:0:1630"
}

When this is fixed, we should add tests for these 2 cases, them with a pub use of the struct, them with --document-hidden-items, and them with --document-hidden-items and a pub use.

@aDotInTheVoid aDotInTheVoid 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 Jun 20, 2023
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 14, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 18, 2023
…dden-impl, r=aDotInTheVoid,notriddle

Strip impl if not re-exported and is doc(hidden)

Part of rust-lang#112852.

r? `@aDotInTheVoid`
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 T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant