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: link may be set to the ID of the item containing the link target #101531

Closed
gifnksm opened this issue Sep 7, 2022 · 2 comments · Fixed by #101633
Closed

Rustdoc-Json: link may be set to the ID of the item containing the link target #101531

gifnksm opened this issue Sep 7, 2022 · 2 comments · Fixed by #101633
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@gifnksm
Copy link
Contributor

gifnksm commented Sep 7, 2022

link field contains wrong IDs for some kind of items.

Items for which no independent HTML is generated (link target URL is <parent_kind>.<parent_name>.html#<kind>.<name>) appear to have incorrect IDs.

I tried this code:

//! [FooStruct::foo_field]
//! [FooEnum::FooVariant]
//! [FooTrait::FOO_CONSTANT]
//! [FooTrait::FooType]
//! [FooTrait::foo_method]

pub struct FooStruct {
    pub foo_field: bool,
}

pub enum FooEnum {
    FooVariant,
}

pub trait FooTrait {
    const FOO_CONSTANT: bool;
    type FooType;
    fn foo_method();
}
$ rustdoc +nightly foo_mod.rs --output-format json -Z unstable-options

$ jq -C < doc/foo_mod.json '.index[.root]'
{
  "id": "0:0:1593",
  "crate_id": 0,
  "name": "foo_mod",
  "span": {
    "filename": "foo_mod.rs",
    "begin": [
      1,
      0
    ],
    "end": [
      19,
      1
    ]
  },
  "visibility": "public",
  "docs": "[FooStruct::foo_field]\n[FooEnum::FooVariant]\n[FooTrait::FOO_CONSTANT]\n[FooTrait::FooType]\n[FooTrait::foo_method]",
  "links": {
    "FooTrait::foo_method": "0:8:1589",
    "FooEnum::FooVariant": "0:5:1587",
    "FooStruct::foo_field": "0:3:1585",
    "FooTrait::FooType": "0:8:1589",
    "FooTrait::FOO_CONSTANT": "0:8:1589"
  },
  "attrs": [],
  "deprecation": null,
  "kind": "module",
  "inner": {
    "is_crate": true,
    "items": [
      "0:3:1585",
      "0:5:1587",
      "0:8:1589"
    ],
    "is_stripped": false
  }
}

I expected to see this happen: links contains the IDs of link targets

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooStruct::foo_field"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooStruct",
    "foo_field"
  ],
  "kind": "struct_field"
}

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooEnum::FooVariant"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooEnum",
    "Variant"
  ],
  "kind": "variant"
}

$  jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooTrait::FOO_CONSTANT"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooTrait",
    "FOO_CONSTANT"
  ],
  "kind": "assoc_const"
}

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooTrait::FooType"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooTrait",
    "FooType"
  ],
  "kind": "assoc_type"
}

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooTrait::foo_method"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooTrait",
    "foo_method"
  ],
  "kind": "method"
}

Instead, this happened: link contains the ID of the items containing the link targets

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooStruct::foo_field"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooStruct"
  ],
  "kind": "struct"
}

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooEnum::FooVariant"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooEnum"
  ],
  "kind": "enum"
}

$  jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooTrait::FOO_CONSTANT"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooTrait"
  ],
  "kind": "trait"
}

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooTrait::FooType"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooTrait"
  ],
  "kind": "trait"
}

$ jq -C < doc/foo_mod.json '.paths[.index[.root].links["FooTrait::foo_method"]]'
{
  "crate_id": 0,
  "path": [
    "foo_mod",
    "FooTrait",
  ],
  "kind": "trait"
}

Meta

rustdoc +nightly --version --verbose:

rustdoc 1.65.0-nightly (78a891d36 2022-09-06)
binary: rustdoc
commit-hash: 78a891d364a7358ed9eb9c93099ba2f3e6817ca6
commit-date: 2022-09-06
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
@gifnksm gifnksm added the C-bug Category: This is a bug. label Sep 7, 2022
@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Sep 9, 2022

@rustbot modify labels: +A-rustdoc-json +T-rustdoc +A-intra-doc-links

@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. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Sep 9, 2022
@aDotInTheVoid
Copy link
Member

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 10, 2022
Rustdoc-Json: Correcty handle intra-doc-links to items without HTML page

Closes rust-lang#101531

I renamed the `did` field in `ItemLink ` to more accurately describe what it does.

r? `@jyn514`
@bors bors closed this as completed in 2c17099 Sep 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. 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.

3 participants