Skip to content

Rustdoc re-exports only include one item per name across all namespaces #107677

Closed
@obi1kenobi

Description

@obi1kenobi

I tried this code:

//! This crate exports the following:
//! - the function `Foo`, also as `Bar` and `nested::Foo`
//! - the type `Foo`, also as `Bar` and `nested::Foo`

pub mod nested {
    pub struct Foo {}

    #[allow(non_snake_case)]
    pub fn Foo() {}
}

pub use nested::Foo;
pub use Foo as Bar;

// Proof that both the type and the function are visible.
// Not exported.
#[allow(dead_code)]
fn proof() -> Bar {
    Bar();
    Bar {}
}

I expected to see this happen: generated rustdoc JSON should include "import" items that point to both the function and the type named Foo, for each of the re-exported Foo and Bar names.

Instead, this happened: the rustdoc JSON only one "import" item for Foo and one for Bar, both pointing to the function. No re-export items pointing to the struct were present, as if the struct was not re-exported (even though the proof() function shows it is).

These are the only "kind": "import" items present in the rustdoc JSON.

{
    // ...
    "kind": "import",
    "inner": {
        "source": "nested::Foo",
        "name": "Foo",
        "id": "0:5:1592",
        "glob": false
    }

    // ...
    "kind": "import",
    "inner": {
        "source": "Foo",
        "name": "Bar",
        "id": "0:5:1592",
        "glob": false
    }
}

This is the item those point to:

"0:5:1592": {
    "id": "0:5:1592",
    "crate_id": 0,
    "name": "Foo",
    "span": {
        "filename": "src/lib.rs",
        "begin": [
            18,
            4
        ],
        "end": [
            18,
            19
        ]
    },
    "visibility": "public",
    "docs": null,
    "links": {},
    "attrs": [
        "#[allow(non_snake_case)]"
    ],
    "deprecation": null,
    "kind": "function",
    // ...
}

This issue originally came up as obi1kenobi/cargo-semver-checks#343, since clap v3.2.0 re-exports a trait and a derive macro that have the same name.

trustfall-rustdoc-adapter PR obi1kenobi/trustfall-rustdoc-adapter#72 includes this failing test case.

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.69.0-nightly (d7948c843 2023-01-26)
binary: rustc
commit-hash: d7948c843de94245c794e8c63dd4301a78bb5ba3
commit-date: 2023-01-26
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Also present in 1.67 and 1.68.0-beta.1 (efd2745 2023-01-25).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-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