Skip to content

Rustdoc-Json: Synthesized foreign traits don't have docs #105022

Closed
@aDotInTheVoid

Description

@aDotInTheVoid

When synthesizing foreign traits, we don't recover the docs (among other things)

types::Item {
id: item_id,
crate_id: id.krate.as_u32(),
name: self
.cache
.paths
.get(&id)
.unwrap_or_else(|| {
self.cache
.external_paths
.get(&id)
.expect("Trait should either be in local or external paths")
})
.0
.last()
.map(|s| s.to_string()),
visibility: types::Visibility::Public,
inner: types::ItemEnum::Trait(trait_item.clone().into_tcx(self.tcx)),
span: None,
docs: Default::default(),
links: Default::default(),
attrs: Default::default(),
deprecation: Default::default(),
},

Meaning that for code:

// --- src/test/rustdoc-json/reexport/synthesize_trait_with_docs.rs ---

// aux-build: trait_with_docs.rs

extern crate trait_with_docs;
pub struct Local;
impl trait_with_docs::HasDocs for Local {}

// --- src/test/rustdoc-json/reexport/auxiliary/trait_with_docs.rs ---

/// The Docs
pub trait HasDocs {}

Produces

{
  "crate_version": null,
  "external_crates": { ... },
  "format_version": 23,
  "includes_private": false,
  "index": {
    "0:0:1568": {
      "crate_id": 0,
      "docs": null,
      "id": "0:0:1568",
      "inner": {"is_crate": true, "is_stripped": false, "items": ["0:4:1566"]},
      "kind": "module",
      "links": {},
      "name": "synthesise_trait_with_docs"
    },
    "0:4:1566": {
      "crate_id": 0,
      "docs": null,
      "id": "0:4:1566",
      "inner": {
        "generics": {"params": [], "where_predicates": []},
        "impls": [ ..., "0:6" ],
        "kind": "unit"
      },
      "kind": "struct",
      "links": {},
      "name": "Local"
    },
    "0:6": {
      "crate_id": 0,
      "docs": null,
      "id": "0:6",
      "inner": {
        "blanket_impl": null,
        "for": {
          "inner": {"id": "0:4:1566", "name": "Local"},
          "kind": "resolved_path"
        },
        "generics": {"params": [], "where_predicates": []},
        "is_unsafe": false,
        "items": [],
        "negative": false,
        "provided_trait_methods": [],
        "synthetic": false,
        "trait": {"id": "20:3:1567", "name": "HasDocs"}
      },
      "kind": "impl",
      "links": {},
      "name": null
    },
    "20:3:1567": {
      "crate_id": 20,
      "docs": null,
      "id": "20:3:1567",
      "inner": {
        "bounds": [],
        "generics": {"params": [], "where_predicates": []},
        "implementations": [],
        "is_auto": false,
        "is_unsafe": false,
        "items": []
      },
      "kind": "trait",
      "links": {},
      "name": "HasDocs"
    }
  },
  "paths": {
    "0:0:1568": {"crate_id": 0, "kind": "module", "path": ["synthesise_trait_with_docs"]},
    "0:4:1566": {"crate_id": 0, "kind": "struct", "path": ["synthesise_trait_with_docs", "Local"]},
    "20:0:1565": {"crate_id": 20, "kind": "module", "path": ["trait_with_docs"]},
    "20:3:1567": {"crate_id": 20, "kind": "trait", "path": ["trait_with_docs", "HasDocs"]}
  },
  "root": "0:0:1568"
}

Where the docs for 20:3:1567 are null.

Either foreign trait syntesis should be done correctly, or not at all, and let users resolve via paths

@rustbot modify labels: +A-rustdoc-json +T-rustdoc

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