rustdoc-json: Dangling ID when private trait used in `dyn Trait` argument in pub fn
Open
Nobody has claimed this yet.
A-rustdoc-json
T-rustdoc
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/rustdoc-json/traits/private_dyn.rs and reproduce the failure using jsondoclint on its generated private_dyn.json. Trace why the private trait is referenced in the public function's dyn_trait data but omitted from the index; done means jsondoclint validates this case without a dangling ID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100