Skip to content

rustdoc-json: Dangling ID when private trait used in dyn Trait argument in pub fn #119626

Open
@aDotInTheVoid

Description

@aDotInTheVoid

This code:

trait Private{}
pub fn takes_dyn_private(_: &dyn Private) {}

Fails to validate with jsondoclint

failures:

---- [rustdoc-json] tests/rustdoc-json/traits/private_dyn.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/traits/private_dyn/private_dyn.json"
stdout: none
--- stderr -------------------------------
0:3:1771 not in index or paths, but referred to at '$.index["0:4:1772"].inner.function.decl.inputs[0][1].borrowed_ref.type.dyn_trait.traits[0].trait.id'
Error: Errors validating json /home/gh-aDotInTheVoid/rust/build/aarch64-unknown-linux-gnu/test/rustdoc-json/traits/private_dyn/private_dyn.json
------------------------------------------

The function's JSON is right:

  "0:4:1772": {
      "inner": {
        "function": {
          "decl": {
            "c_variadic": false,
            "inputs": [
              [
                "_",
                {
                  "borrowed_ref": {
                    "lifetime": null,
                    "mutable": false,
                    "type": {
                      "dyn_trait": {
                        "lifetime": null,
                        "traits": [{"trait": {"id": "0:3:1771", "name": "Private"}}]
                      }
                    }
                  }
                }
              ]
            ],
            "output": null
          },
          "generics": {"where_predicates": []},
          "has_body": true,
          "header": {"abi": "Rust", "async": false, "const": false, "unsafe": false}
        }
      },
      "name": "takes_dyn_private"
    },

but we don't include the trait as it's private.

This is a similar to #113674, where a private (not just unreachable, but private at definition site) item is in the public API.

This does trigger a warning, but is accepted

warning: trait `Private` is more private than the item `takes_dyn_private`
 --> src/lib.rs:4:1
  |
4 | pub fn takes_dyn_private(_: &dyn Private) {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `takes_dyn_private` is reachable at visibility `pub`
  |
note: but trait `Private` is only usable at visibility `pub(crate)`
 --> src/lib.rs:3:1
  |
3 | trait Private{}
  | ^^^^^^^^^^^^^
  = note: `#[warn(private_interfaces)]` on by default

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