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 re-exports only include one item per name across all namespaces #107677

Closed
obi1kenobi opened this issue Feb 5, 2023 · 4 comments · Fixed by #107766
Closed

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

obi1kenobi opened this issue Feb 5, 2023 · 4 comments · Fixed by #107766
Labels
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

@obi1kenobi
Copy link
Member

obi1kenobi commented Feb 5, 2023

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).

@obi1kenobi obi1kenobi added the C-bug Category: This is a bug. label Feb 5, 2023
@obi1kenobi
Copy link
Member Author

It seems like the simplest fix would be to have rustdoc JSON emit multiple "import" entries, one per "id" that is pointed to and with duplicated names. That appears to be both forward and backward compatible.

@obi1kenobi
Copy link
Member Author

@rustbot label T-rustdoc

@GuillaumeGomez
Copy link
Member

It's working for the HTML output too.

@obi1kenobi
Copy link
Member Author

Thanks for the fix, much appreciated! 🎉

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