Description
The blanket_impl
field on Impl
is currently undocumented, and has strange & possibly-buggy behavior.
Consider the following code:
#![feature(no_core)]
#![no_core]
pub trait Example {}
impl<T> Example for T {}
Generating rustdoc JSON for it produces the following entry for the impl
item:
{
"id": 1,
"crate_id": 0,
"name": null,
"span": {
"filename": "src/lib.rs",
"begin": [
6,
0
],
"end": [
6,
24
]
},
"visibility": "default",
"docs": null,
"links": {},
"attrs": [],
"deprecation": null,
"inner": {
"impl": {
"is_unsafe": false,
"generics": {
"params": [
{
"name": "T",
"kind": {
"type": {
"bounds": [],
"default": null,
"is_synthetic": false
}
}
}
],
"where_predicates": []
},
"provided_trait_methods": [],
"trait": {
"path": "Example",
"id": 0,
"args": {
"angle_bracketed": {
"args": [],
"constraints": []
}
}
},
"for": {
"generic": "T"
},
"items": [],
"is_negative": false,
"is_synthetic": false,
"blanket_impl": null
}
}
}
Unless I've drastically misunderstood some terminology, this impl
is a blanket impl, and yet blanket_impl
is empty.
I find this surprising. I would have expected
"blanket_impl": {
"generic": "T"
}
since that's the type over which the blanket impl applies.
Hypothetically if the impl were instead impl<T> Example for Vec<T>
, I'm not sure whether blanket_impl
should then be None
or correspond to Vec<T>
. It would be great to document this choice explicitly.
This isn't high priority for me — I have a workaround. Just flagging it for completeness and on the off chance that I might be misunderstanding what that field is meant to do.
Meta
rustc --version --verbose
:
rustc 1.86.0-nightly (f027438f8 2025-02-03)
binary: rustc
commit-hash: f027438f8bc6b747528dca8b8de13043544d7238
commit-date: 2025-02-03
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7