Skip to content

Commit 5c9982d

Browse files
committed
[rustdoc-json] Partially remove paths and introduce external_index
Introduce a new `external_index` that only contains a `ExternalItem` struct from the previous `ItemSummary`. This "new" index only contains external item and is only here so that IDs continue to referring to an "item". A previous version of this patch also removed `path` but at least until #99513 is fixed it is unfortunately still required (as a workaround).
1 parent 33b530e commit 5c9982d

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

src/librustdoc/json/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,14 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
292292
crate_version: self.cache.crate_version.clone(),
293293
includes_private: self.cache.document_private,
294294
index: index.into_iter().collect(),
295-
paths: self
295+
external_index: self
296296
.cache
297-
.paths
297+
.external_paths
298298
.iter()
299-
.chain(&self.cache.external_paths)
300299
.map(|(&k, &(ref path, kind))| {
301300
(
302301
from_item_id(k.into(), self.tcx),
303-
types::ItemSummary {
302+
types::ExternalItem {
304303
crate_id: k.krate.as_u32(),
305304
path: path.iter().map(|s| s.to_string()).collect(),
306305
kind: kind.into_tcx(self.tcx),

src/rustdoc-json-types/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
use serde::{Deserialize, Serialize};
1010

1111
/// rustdoc format-version.
12-
pub const FORMAT_VERSION: u32 = 22;
12+
pub const FORMAT_VERSION: u32 = 23;
1313

1414
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
1515
/// about the language items in the local crate, as well as info about external items to allow
@@ -25,8 +25,8 @@ pub struct Crate {
2525
/// A collection of all items in the local crate as well as some external traits and their
2626
/// items that are referenced locally.
2727
pub index: HashMap<Id, Item>,
28-
/// Maps IDs to fully qualified paths and other info helpful for generating links.
29-
pub paths: HashMap<Id, ItemSummary>,
28+
/// Maps external IDs to basic informations.
29+
pub external_index: HashMap<Id, ExternalItem>,
3030
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
3131
pub external_crates: HashMap<u32, ExternalCrate>,
3232
/// A single version number to be used in the future when making backwards incompatible changes
@@ -45,7 +45,7 @@ pub struct ExternalCrate {
4545
/// question, or can be used by a tool that takes the json output of multiple crates to find
4646
/// the actual item definition with all the relevant info.
4747
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
48-
pub struct ItemSummary {
48+
pub struct ExternalItem {
4949
/// Can be used to look up the name and html_root_url of the crate this item came from in the
5050
/// `external_crates` map.
5151
pub crate_id: u32,
@@ -56,6 +56,10 @@ pub struct ItemSummary {
5656
/// defined. Currenty, this is the full path to where the item was defined. Eg
5757
/// [`String`] is currently `["alloc", "string", "String"]` and [`HashMap`] is
5858
/// `["std", "collections", "hash", "map", "HashMap"]`, but this is subject to change.
59+
///
60+
/// Be aware that this field maybe be subject to change (like complete removal) in the
61+
/// future, see issue <https://github.com/rust-lang/rust/issues/93522> and
62+
/// <https://github.com/rust-lang/rust/pull/103085> for more information.
5963
pub path: Vec<String>,
6064
/// Whether this item is a struct, trait, macro, etc.
6165
pub kind: ItemKind,

src/tools/jsondoclint/src/item_kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustdoc_json_types::{Item, ItemEnum, ItemKind, ItemSummary};
1+
use rustdoc_json_types::{ExternalItem, Item, ItemEnum, ItemKind};
22

33
/// A univeral way to represent an [`ItemEnum`] or [`ItemKind`]
44
#[derive(Debug)]
@@ -150,7 +150,7 @@ impl Kind {
150150
}
151151
}
152152

153-
pub fn from_summary(s: &ItemSummary) -> Self {
153+
pub fn from_summary(s: &ExternalItem) -> Self {
154154
use Kind::*;
155155
match s.kind {
156156
ItemKind::AssocConst => AssocConst,

src/tools/jsondoclint/src/validator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a> Validator<'a> {
9090
}
9191
}
9292
} else {
93-
assert!(self.krate.paths.contains_key(id));
93+
assert!(self.krate.external_index.contains_key(id));
9494
}
9595
}
9696

@@ -424,7 +424,7 @@ impl<'a> Validator<'a> {
424424
fn kind_of(&mut self, id: &Id) -> Option<Kind> {
425425
if let Some(item) = self.krate.index.get(id) {
426426
Some(Kind::from_item(item))
427-
} else if let Some(summary) = self.krate.paths.get(id) {
427+
} else if let Some(summary) = self.krate.external_index.get(id) {
428428
Some(Kind::from_summary(summary))
429429
} else {
430430
None

0 commit comments

Comments
 (0)