Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aDotInTheVoid opened this issue Nov 28, 2022 · 0 comments · Fixed by #105182
Closed

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

aDotInTheVoid opened this issue Nov 28, 2022 · 0 comments · Fixed by #105182
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

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

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 28, 2022
aDotInTheVoid added a commit to aDotInTheVoid/rust that referenced this issue Dec 2, 2022
@bors bors closed this as completed in 9afa850 Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants