Repository: rust
Issue: rustdoc-json: Dangling ID for trait impl with pub struct in `#[doc(hidden)]` mod
Labels: T-rustdoc,A-rustdoc-json

```rust
#![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
------------------------------------------
```

```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

<details>

```rust
#![feature(no_core)]
#![no_core]

pub trait PubTrait {}

#[doc(hidden)]
pub struct HiddenPubStruct;

impl PubTrait for HiddenPubStruct {}
```

```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_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"
}
```

</details>

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.