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

Fix json reexports of different items with same name #107766

Conversation

GuillaumeGomez
Copy link
Member

Fixes #107677.

I renamed from_item_id* functions into id_from_item instead because it makes more sense now. I also simplified the logic around it a bit so that the ids function will now directly pass &clean::Item to id_from_item and the ID will be consistently generated (it caused an issue when I updated the ID for imports).

So now, the big change of this PR: I changed how imports' ID is generated: it now includes the target item's ID at the end of the ID. It's to prevent two reexported items with the same name (but different types).

r? @aDotInTheVoid

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 7, 2023
@rust-log-analyzer

This comment has been minimized.

@GuillaumeGomez
Copy link
Member Author

Fixed the bad primitive change I made.

Copy link
Member

@aDotInTheVoid aDotInTheVoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot author

src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
src/librustdoc/json/conversions.rs Outdated Show resolved Hide resolved
#[allow(non_snake_case)]
pub fn Foo() {}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this test be expanded a bit more? I'd like to see it checking that their are items for both Foos, and that each name imports both of the foo items (instead of just checking that their are two imports with each name).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eg:

#![feature(no_core)]
#![no_core]

pub mod nested {
    // @set foo_struct = "$.index[*][?(@.docs == 'Foo the struct')].id"

    /// Foo the struct
    pub struct Foo {}

    // @set foo_fn = "$.index[*][?(@.docs == 'Foo the function')].id"

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

// @ismany "$.index[*][?(@.inner.name == 'Foo' && @.kind == 'import')].inner.id" $foo_fn $foo_struct
// @ismany "$.index[*][?(@.inner.name == 'Bar' && @.kind == 'import')].inner.id" $foo_fn $foo_struct

// @count "$.index[*][?(@.inner.name == 'Foo' && @.kind == 'import')]" 2
pub use nested::Foo;
// @count "$.index[*][?(@.inner.name == 'Bar' && @.kind == 'import')]" 2
pub use Foo as Bar;

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 14, 2023
@aDotInTheVoid
Copy link
Member

Looking at the output (of tests/rustdoc-json/reexport/same_name_different_types.rs), for some reason it's duplicating ID's in the output:

  "index": {
    "0:0:1588": {
      "crate_id": 0,
      "docs": null,
      "id": "0:0:1588",
      "inner": {
        "is_crate": true,
        "is_stripped": false,
        "items": [
          "0:1:1582",
          "0:4-0:2:1584",
          "0:4-0:3:1584",
          "0:4-0:2:1584",
          "0:4-0:3:1584",
          "0:5-0:2:1584",
          "0:5-0:3:1584",
          "0:5-0:2:1584",
          "0:5-0:3:1584"
        ]
      },
      "kind": "module",
      "name": "same_name_different_types"
    },

I'm not really sure whats causing this, but idealy it wouldn't happen, although I'd be willing to merge as is, as long as an issue gets created to follow up.

(Also, jsondoclint should probably catch this)

@GuillaumeGomez GuillaumeGomez force-pushed the fix-json-reexports-of-different-items-with-same-name branch from b1b003b to 1ae875f Compare February 18, 2023 17:28
@GuillaumeGomez
Copy link
Member Author

I think it's better to fix it in another PR since this one is already quite big. We can fix it easily by having a HashSet but I'd like to investigate why it's needed in the first place.

@GuillaumeGomez
Copy link
Member Author

And also: updated.

@aDotInTheVoid
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 19, 2023

📌 Commit 1ae875f has been approved by aDotInTheVoid

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 19, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 19, 2023
…llaumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#107766 (Fix json reexports of different items with same name)
 - rust-lang#108129 (Correctly handle links starting with whitespace)
 - rust-lang#108188 (Change src/etc/vscode_settings.json to always treat ./library as the sysroot source)
 - rust-lang#108203 (Fix RPITITs in default trait methods (by assuming projection predicates in param-env))
 - rust-lang#108212 (Download rustfmt regardless of rustc being set in config.toml)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 49d7ed1 into rust-lang:master Feb 19, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 19, 2023
@GuillaumeGomez GuillaumeGomez deleted the fix-json-reexports-of-different-items-with-same-name branch February 19, 2023 18:43
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 S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rustdoc re-exports only include one item per name across all namespaces
5 participants