Closed
Description
If we generate rustdoc JSON for this lib.rs:
#![feature(no_core)]
#![no_core]
#![no_std]
pub trait Trait<'a> {}
pub fn f(_: &dyn for<'a> Trait<'a>) {}
with the command:
rustdoc +nightly-2022-07-10 -Z unstable-options --output-format json lib.rs
we will get this rustdoc JSON in doc/lib.json for the function input parameters:
"inputs": [
[
"_",
{
"kind": "borrowed_ref",
"inner": {
"lifetime": null,
"mutable": false,
"type": {
"kind": "resolved_path",
"inner": {
"name": "Trait",
"id": "0:1:1565",
"args": {
"angle_bracketed": {
"args": [
{
"lifetime": "'a"
}
],
"bindings": []
}
},
"param_names": []
}
}
}
}
]
],
as can be seen, the for<'a>
part is absent. Info about that the dyn
keywoard is used is not present either, unless one looks up 0:1:1565
, in which case I guess it can be deduced that dyn
is used. But it would be nice if that was made clearer.
I think the best way to solve this would be to introduce a DynTrait
object of some kind to rustdoc JSON, as was done for rustdoc HTML in 4ea2748.
@rustbot labels +A-rustdoc-json +T-rustdoc +C-enhancement +requires-nightly
For reference, the full rustdoc JSON output can be seen below.
Click to expand!
% cat doc/lib.json | python3 -m json.tool
{
"root": "0:0:782",
"crate_version": null,
"includes_private": false,
"index": {
"0:3:617": {
"id": "0:3:617",
"crate_id": 0,
"name": "f",
"span": {
"filename": "lib.rs",
"begin": [
5,
0
],
"end": [
5,
38
]
},
"visibility": "public",
"docs": null,
"links": {},
"attrs": [],
"deprecation": null,
"kind": "function",
"inner": {
"decl": {
"inputs": [
[
"_",
{
"kind": "borrowed_ref",
"inner": {
"lifetime": null,
"mutable": false,
"type": {
"kind": "resolved_path",
"inner": {
"name": "Trait",
"id": "0:1:1565",
"args": {
"angle_bracketed": {
"args": [
{
"lifetime": "'a"
}
],
"bindings": []
}
},
"param_names": []
}
}
}
}
]
],
"output": null,
"c_variadic": false
},
"generics": {
"params": [],
"where_predicates": []
},
"header": {
"const": false,
"unsafe": false,
"async": false,
"abi": "Rust"
}
}
},
"0:0:782": {
"id": "0:0:782",
"crate_id": 0,
"name": "lib",
"span": {
"filename": "lib.rs",
"begin": [
1,
0
],
"end": [
5,
38
]
},
"visibility": "public",
"docs": null,
"links": {},
"attrs": [
"#![feature(no_core)]",
"#![no_core]",
"#![no_std]"
],
"deprecation": null,
"kind": "module",
"inner": {
"is_crate": true,
"items": [
"0:1:1565",
"0:3:617"
]
}
},
"0:1:1565": {
"id": "0:1:1565",
"crate_id": 0,
"name": "Trait",
"span": {
"filename": "lib.rs",
"begin": [
4,
0
],
"end": [
4,
22
]
},
"visibility": "public",
"docs": null,
"links": {},
"attrs": [],
"deprecation": null,
"kind": "trait",
"inner": {
"is_auto": false,
"is_unsafe": false,
"items": [],
"generics": {
"params": [
{
"name": "'a",
"kind": {
"lifetime": {
"outlives": []
}
}
}
],
"where_predicates": []
},
"bounds": [],
"implementations": []
}
}
},
"paths": {
"0:3:617": {
"crate_id": 0,
"path": [
"lib",
"f"
],
"kind": "function"
},
"0:1:1565": {
"crate_id": 0,
"path": [
"lib",
"Trait"
],
"kind": "trait"
},
"0:0:782": {
"crate_id": 0,
"path": [
"lib"
],
"kind": "module"
}
},
"external_crates": {},
"format_version": 15
}