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] Partially remove paths and introduce external_index #103085

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,14 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
crate_version: self.cache.crate_version.clone(),
includes_private: self.cache.document_private,
index: index.into_iter().collect(),
paths: self
external_index: self
.cache
.paths
.external_paths
.iter()
.chain(&self.cache.external_paths)
.map(|(&k, &(ref path, kind))| {
(
from_item_id(k.into(), self.tcx),
types::ItemSummary {
types::ExternalItem {
crate_id: k.krate.as_u32(),
path: path.iter().map(|s| s.to_string()).collect(),
kind: kind.into_tcx(self.tcx),
Expand Down
12 changes: 8 additions & 4 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
use serde::{Deserialize, Serialize};

/// rustdoc format-version.
pub const FORMAT_VERSION: u32 = 22;
pub const FORMAT_VERSION: u32 = 23;

/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
/// about the language items in the local crate, as well as info about external items to allow
Expand All @@ -25,8 +25,8 @@ pub struct Crate {
/// A collection of all items in the local crate as well as some external traits and their
/// items that are referenced locally.
pub index: HashMap<Id, Item>,
/// Maps IDs to fully qualified paths and other info helpful for generating links.
pub paths: HashMap<Id, ItemSummary>,
/// Maps external IDs to basic informations.
pub external_index: HashMap<Id, ExternalItem>,
/// Maps `crate_id` of items to a crate name and html_root_url if it exists.
pub external_crates: HashMap<u32, ExternalCrate>,
/// A single version number to be used in the future when making backwards incompatible changes
Expand All @@ -45,7 +45,7 @@ pub struct ExternalCrate {
/// question, or can be used by a tool that takes the json output of multiple crates to find
/// the actual item definition with all the relevant info.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ItemSummary {
pub struct ExternalItem {
/// Can be used to look up the name and html_root_url of the crate this item came from in the
/// `external_crates` map.
pub crate_id: u32,
Expand All @@ -56,6 +56,10 @@ pub struct ItemSummary {
/// defined. Currenty, this is the full path to where the item was defined. Eg
/// [`String`] is currently `["alloc", "string", "String"]` and [`HashMap`] is
/// `["std", "collections", "hash", "map", "HashMap"]`, but this is subject to change.
///
/// Be aware that this field maybe be subject to change (like complete removal) in the
/// future, see issue <https://github.com/rust-lang/rust/issues/93522> and
/// <https://github.com/rust-lang/rust/pull/103085> for more information.
pub path: Vec<String>,
/// Whether this item is a struct, trait, macro, etc.
pub kind: ItemKind,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/jsondoclint/src/item_kind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustdoc_json_types::{Item, ItemEnum, ItemKind, ItemSummary};
use rustdoc_json_types::{ExternalItem, Item, ItemEnum, ItemKind};

/// A univeral way to represent an [`ItemEnum`] or [`ItemKind`]
#[derive(Debug)]
Expand Down Expand Up @@ -150,7 +150,7 @@ impl Kind {
}
}

pub fn from_summary(s: &ItemSummary) -> Self {
pub fn from_summary(s: &ExternalItem) -> Self {
use Kind::*;
match s.kind {
ItemKind::AssocConst => AssocConst,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/jsondoclint/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a> Validator<'a> {
}
}
} else {
assert!(self.krate.paths.contains_key(id));
assert!(self.krate.external_index.contains_key(id));
}
}

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