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: Items who'se original path isn't visiable doen't appear in Crate::paths #135309

Closed
aDotInTheVoid opened this issue Jan 9, 2025 · 1 comment · Fixed by #135348
Closed
Assignees
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Jan 9, 2025

With this code:

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

mod inner {
    pub struct Public;
}

pub use inner::Public;

We produce the following JSON (redacted for clarity):

{
  "crate_version": null,
  "external_crates": {},
  "format_version": 37,
  "includes_private": false,
  "index": {
    "0": {
      "attrs": [],
      "docs": null,
      "inner": {"struct": {"generics": {"params": [], "where_predicates": []}, "impls": [], "kind": "unit"}},
      "name": "Public",
      "visibility": "public"
    },
    "2": {
      "attrs": [],
      "docs": null,
      "inner": {"use": {"id": 0, "is_glob": false, "name": "Public", "source": "inner::Public"}},
      "name": null,
      "visibility": "public"
    },
    "3": {
      "attrs": ["#![feature(no_core)]", "#![no_core]"],
      "docs": null,
      "inner": {"module": {"is_crate": true, "is_stripped": false, "items": [2]}},
      "name": "simple_private",
      "visibility": "public"
    }
  },
  "paths": {"3": {"crate_id": 0, "kind": "module", "path": ["simple_private"]}},
  "root": 3
}

There's no path entry for 0, but there should be.


Found while looking at #134880.

We should have the jsondoclint validator check this, something like

diff --git a/src/tools/jsondoclint/src/validator.rs b/src/tools/jsondoclint/src/validator.rs
index f7c752033c5..73aa86d9c90 100644
--- a/src/tools/jsondoclint/src/validator.rs
+++ b/src/tools/jsondoclint/src/validator.rs
@@ -303,7 +303,12 @@ fn check_path(&mut self, x: &'a Path, kind: PathKind) {
             PathKind::Trait => self.add_trait_or_alias_id(&x.id),
             PathKind::Type => self.add_type_id(&x.id),
         }
-        if let Some(args) = &x.args {
+
+        if !self.krate.paths.contains_key(&x.id) {
+            panic!("no $.paths entry for {x:?}");
+        }
+
+        if let Some(args) = &*x.args {
             self.check_generic_args(&**args);
         }
     }
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 9, 2025
@aDotInTheVoid aDotInTheVoid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-json Area: Rustdoc JSON backend and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 9, 2025
@aDotInTheVoid
Copy link
Member Author

Found a fix, PR soon(tm)

@rustbot claim

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 12, 2025
…uillaumeGomez

rustdoc-json: Include items in stripped modules in `Crate::paths`.

Closes rust-lang#135309

When we're running rustdoc-json, we should err on the side of adding more items to `Cache::paths`, as that directly becomes `Crate::paths` in the output.

r? `@GuillaumeGomez.` Best reviewed commit-by-commit.
@bors bors closed this as completed in 9d3ae11 Jan 13, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 13, 2025
Rollup merge of rust-lang#135348 - aDotInTheVoid:pathspathspaths, r=GuillaumeGomez

rustdoc-json: Include items in stripped modules in `Crate::paths`.

Closes rust-lang#135309

When we're running rustdoc-json, we should err on the side of adding more items to `Cache::paths`, as that directly becomes `Crate::paths` in the output.

r? ``@GuillaumeGomez.`` Best reviewed commit-by-commit.
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 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.

2 participants