rust-lang / rust-lang/rust

rustdoc-json: Decide on the future of the `blanket_impl` field

Open
#136,557 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-rustdoc-json C-discussion T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the rustdoc JSON Impl entry and the generated src/lib.rs example, comparing the for and blanket_impl values for the shown generic impl and the proposed Vec<T> case. Done means the field's intended semantics are decided, documented, and reflected consistently in generated JSON; verify with a rustdoc JSON run using the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.