Skip to content

rustdoc-json: Dangling ID for trait impl with pub struct in #[doc(hidden)] mod #112852

Open
@aDotInTheVoid

Description

@aDotInTheVoid
#![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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-jsonArea: Rustdoc JSON backendT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions