Remove unneeded ItemId::Primitive variant
This commit is contained in:
parent
c54c8cbac8
commit
36c9b49c14
5 changed files with 74 additions and 50 deletions
|
@ -600,7 +600,9 @@ fn build_module_items(
|
||||||
items.push(clean::Item {
|
items.push(clean::Item {
|
||||||
name: None,
|
name: None,
|
||||||
attrs: Box::new(clean::Attributes::default()),
|
attrs: Box::new(clean::Attributes::default()),
|
||||||
item_id: ItemId::Primitive(prim_ty, did.krate),
|
// We can use the item's `DefId` directly since the only information ever used
|
||||||
|
// from it is `DefId.krate`.
|
||||||
|
item_id: ItemId::DefId(did),
|
||||||
kind: Box::new(clean::ImportItem(clean::Import::new_simple(
|
kind: Box::new(clean::ImportItem(clean::Import::new_simple(
|
||||||
item.ident.name,
|
item.ident.name,
|
||||||
clean::ImportSource {
|
clean::ImportSource {
|
||||||
|
|
|
@ -62,8 +62,6 @@ pub(crate) enum ItemId {
|
||||||
Auto { trait_: DefId, for_: DefId },
|
Auto { trait_: DefId, for_: DefId },
|
||||||
/// Identifier that is used for blanket implementations.
|
/// Identifier that is used for blanket implementations.
|
||||||
Blanket { impl_id: DefId, for_: DefId },
|
Blanket { impl_id: DefId, for_: DefId },
|
||||||
/// Identifier for primitive types.
|
|
||||||
Primitive(PrimitiveType, CrateNum),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemId {
|
impl ItemId {
|
||||||
|
@ -73,7 +71,6 @@ impl ItemId {
|
||||||
ItemId::Auto { for_: id, .. }
|
ItemId::Auto { for_: id, .. }
|
||||||
| ItemId::Blanket { for_: id, .. }
|
| ItemId::Blanket { for_: id, .. }
|
||||||
| ItemId::DefId(id) => id.is_local(),
|
| ItemId::DefId(id) => id.is_local(),
|
||||||
ItemId::Primitive(_, krate) => krate == LOCAL_CRATE,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +95,6 @@ impl ItemId {
|
||||||
ItemId::Auto { for_: id, .. }
|
ItemId::Auto { for_: id, .. }
|
||||||
| ItemId::Blanket { for_: id, .. }
|
| ItemId::Blanket { for_: id, .. }
|
||||||
| ItemId::DefId(id) => id.krate,
|
| ItemId::DefId(id) => id.krate,
|
||||||
ItemId::Primitive(_, krate) => krate,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -707,15 +703,13 @@ impl Item {
|
||||||
let def_id = match self.item_id {
|
let def_id = match self.item_id {
|
||||||
// Anything but DefId *shouldn't* matter, but return a reasonable value anyway.
|
// Anything but DefId *shouldn't* matter, but return a reasonable value anyway.
|
||||||
ItemId::Auto { .. } | ItemId::Blanket { .. } => return None,
|
ItemId::Auto { .. } | ItemId::Blanket { .. } => return None,
|
||||||
// Primitives and Keywords are written in the source code as private modules.
|
|
||||||
// The modules need to be private so that nobody actually uses them, but the
|
|
||||||
// keywords and primitives that they are documenting are public.
|
|
||||||
ItemId::Primitive(..) => return Some(Visibility::Public),
|
|
||||||
ItemId::DefId(def_id) => def_id,
|
ItemId::DefId(def_id) => def_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
match *self.kind {
|
match *self.kind {
|
||||||
// Explication on `ItemId::Primitive` just above.
|
// Primitives and Keywords are written in the source code as private modules.
|
||||||
|
// The modules need to be private so that nobody actually uses them, but the
|
||||||
|
// keywords and primitives that they are documenting are public.
|
||||||
ItemKind::KeywordItem | ItemKind::PrimitiveItem(_) => return Some(Visibility::Public),
|
ItemKind::KeywordItem | ItemKind::PrimitiveItem(_) => return Some(Visibility::Public),
|
||||||
// Variant fields inherit their enum's visibility.
|
// Variant fields inherit their enum's visibility.
|
||||||
StructFieldItem(..) if is_field_vis_inherited(tcx, def_id) => {
|
StructFieldItem(..) if is_field_vis_inherited(tcx, def_id) => {
|
||||||
|
|
|
@ -53,12 +53,6 @@ impl Impl {
|
||||||
ItemId::Blanket { impl_id, .. } => impl_id,
|
ItemId::Blanket { impl_id, .. } => impl_id,
|
||||||
ItemId::Auto { trait_, .. } => trait_,
|
ItemId::Auto { trait_, .. } => trait_,
|
||||||
ItemId::DefId(def_id) => def_id,
|
ItemId::DefId(def_id) => def_id,
|
||||||
ItemId::Primitive(_, _) => {
|
|
||||||
panic!(
|
|
||||||
"Unexpected ItemId::Primitive in expect_def_id: {:?}",
|
|
||||||
self.impl_item.item_id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ use std::collections::BTreeMap;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::def_id::LOCAL_CRATE;
|
|
||||||
use rustc_span::symbol::Symbol;
|
use rustc_span::symbol::Symbol;
|
||||||
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
use serde::ser::{Serialize, SerializeStruct, Serializer};
|
||||||
|
|
||||||
|
@ -24,6 +23,7 @@ pub(crate) fn build_index<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut itemid_to_pathid = FxHashMap::default();
|
let mut itemid_to_pathid = FxHashMap::default();
|
||||||
|
let mut primitives = FxHashMap::default();
|
||||||
let mut crate_paths = vec![];
|
let mut crate_paths = vec![];
|
||||||
|
|
||||||
// Attach all orphan items to the type's definition if the type
|
// Attach all orphan items to the type's definition if the type
|
||||||
|
@ -78,42 +78,16 @@ pub(crate) fn build_index<'tcx>(
|
||||||
// First, on function signatures
|
// First, on function signatures
|
||||||
let mut search_index = std::mem::replace(&mut cache.search_index, Vec::new());
|
let mut search_index = std::mem::replace(&mut cache.search_index, Vec::new());
|
||||||
for item in search_index.iter_mut() {
|
for item in search_index.iter_mut() {
|
||||||
fn convert_render_type(
|
fn insert_into_map<F: std::hash::Hash + Eq>(
|
||||||
ty: &mut RenderType,
|
ty: &mut RenderType,
|
||||||
cache: &mut Cache,
|
map: &mut FxHashMap<F, usize>,
|
||||||
itemid_to_pathid: &mut FxHashMap<ItemId, usize>,
|
itemid: F,
|
||||||
lastpathid: &mut usize,
|
lastpathid: &mut usize,
|
||||||
crate_paths: &mut Vec<(ItemType, Symbol)>,
|
crate_paths: &mut Vec<(ItemType, Symbol)>,
|
||||||
|
item_type: ItemType,
|
||||||
|
path: Symbol,
|
||||||
) {
|
) {
|
||||||
if let Some(generics) = &mut ty.generics {
|
match map.entry(itemid) {
|
||||||
for item in generics {
|
|
||||||
convert_render_type(item, cache, itemid_to_pathid, lastpathid, crate_paths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let Cache { ref paths, ref external_paths, .. } = *cache;
|
|
||||||
let Some(id) = ty.id.clone() else {
|
|
||||||
assert!(ty.generics.is_some());
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let (itemid, path, item_type) = match id {
|
|
||||||
RenderTypeId::DefId(defid) => {
|
|
||||||
if let Some(&(ref fqp, item_type)) =
|
|
||||||
paths.get(&defid).or_else(|| external_paths.get(&defid))
|
|
||||||
{
|
|
||||||
(ItemId::DefId(defid), *fqp.last().unwrap(), item_type)
|
|
||||||
} else {
|
|
||||||
ty.id = None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RenderTypeId::Primitive(primitive) => (
|
|
||||||
ItemId::Primitive(primitive, LOCAL_CRATE),
|
|
||||||
primitive.as_sym(),
|
|
||||||
ItemType::Primitive,
|
|
||||||
),
|
|
||||||
RenderTypeId::Index(_) => return,
|
|
||||||
};
|
|
||||||
match itemid_to_pathid.entry(itemid) {
|
|
||||||
Entry::Occupied(entry) => ty.id = Some(RenderTypeId::Index(*entry.get())),
|
Entry::Occupied(entry) => ty.id = Some(RenderTypeId::Index(*entry.get())),
|
||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
let pathid = *lastpathid;
|
let pathid = *lastpathid;
|
||||||
|
@ -124,12 +98,72 @@ pub(crate) fn build_index<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn convert_render_type(
|
||||||
|
ty: &mut RenderType,
|
||||||
|
cache: &mut Cache,
|
||||||
|
itemid_to_pathid: &mut FxHashMap<ItemId, usize>,
|
||||||
|
primitives: &mut FxHashMap<Symbol, usize>,
|
||||||
|
lastpathid: &mut usize,
|
||||||
|
crate_paths: &mut Vec<(ItemType, Symbol)>,
|
||||||
|
) {
|
||||||
|
if let Some(generics) = &mut ty.generics {
|
||||||
|
for item in generics {
|
||||||
|
convert_render_type(
|
||||||
|
item,
|
||||||
|
cache,
|
||||||
|
itemid_to_pathid,
|
||||||
|
primitives,
|
||||||
|
lastpathid,
|
||||||
|
crate_paths,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let Cache { ref paths, ref external_paths, .. } = *cache;
|
||||||
|
let Some(id) = ty.id.clone() else {
|
||||||
|
assert!(ty.generics.is_some());
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
match id {
|
||||||
|
RenderTypeId::DefId(defid) => {
|
||||||
|
if let Some(&(ref fqp, item_type)) =
|
||||||
|
paths.get(&defid).or_else(|| external_paths.get(&defid))
|
||||||
|
{
|
||||||
|
insert_into_map(
|
||||||
|
ty,
|
||||||
|
itemid_to_pathid,
|
||||||
|
ItemId::DefId(defid),
|
||||||
|
lastpathid,
|
||||||
|
crate_paths,
|
||||||
|
item_type,
|
||||||
|
*fqp.last().unwrap(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
ty.id = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RenderTypeId::Primitive(primitive) => {
|
||||||
|
let sym = primitive.as_sym();
|
||||||
|
insert_into_map(
|
||||||
|
ty,
|
||||||
|
primitives,
|
||||||
|
sym,
|
||||||
|
lastpathid,
|
||||||
|
crate_paths,
|
||||||
|
ItemType::Primitive,
|
||||||
|
sym,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
RenderTypeId::Index(_) => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(search_type) = &mut item.search_type {
|
if let Some(search_type) = &mut item.search_type {
|
||||||
for item in &mut search_type.inputs {
|
for item in &mut search_type.inputs {
|
||||||
convert_render_type(
|
convert_render_type(
|
||||||
item,
|
item,
|
||||||
cache,
|
cache,
|
||||||
&mut itemid_to_pathid,
|
&mut itemid_to_pathid,
|
||||||
|
&mut primitives,
|
||||||
&mut lastpathid,
|
&mut lastpathid,
|
||||||
&mut crate_paths,
|
&mut crate_paths,
|
||||||
);
|
);
|
||||||
|
@ -139,6 +173,7 @@ pub(crate) fn build_index<'tcx>(
|
||||||
item,
|
item,
|
||||||
cache,
|
cache,
|
||||||
&mut itemid_to_pathid,
|
&mut itemid_to_pathid,
|
||||||
|
&mut primitives,
|
||||||
&mut lastpathid,
|
&mut lastpathid,
|
||||||
&mut crate_paths,
|
&mut crate_paths,
|
||||||
);
|
);
|
||||||
|
|
|
@ -252,7 +252,6 @@ pub(crate) fn from_item_id_with_name(item_id: ItemId, tcx: TyCtxt<'_>, name: Opt
|
||||||
ItemId::Auto { for_, trait_ } => {
|
ItemId::Auto { for_, trait_ } => {
|
||||||
Id(format!("a:{}-{}", DisplayDefId(trait_, tcx, None), DisplayDefId(for_, tcx, name)))
|
Id(format!("a:{}-{}", DisplayDefId(trait_, tcx, None), DisplayDefId(for_, tcx, name)))
|
||||||
}
|
}
|
||||||
ItemId::Primitive(_, _) => unreachable!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue