Skip to content

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

Closed
@gifnksm

Description

@gifnksm

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

Metadata

Metadata

Assignees

Labels

A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameA-rustdoc-jsonArea: Rustdoc JSON backendC-bugCategory: This is a bug.T-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