From f3ef4b2cefb5f4dc944ed4ae2f74d9f9918d7822 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 21:27:19 -0400 Subject: [PATCH] Use ItemType in cache --- src/librustdoc/clean/types.rs | 1 - src/librustdoc/formats/item_type.rs | 22 +--------------------- src/librustdoc/html/render/cache.rs | 10 +++++----- src/librustdoc/html/render/mod.rs | 10 +++++----- 4 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 8569c87d3148..de37f4eedf6a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1456,7 +1456,6 @@ crate enum TypeKind { Foreign, Macro, TraitAlias, - Primitive, } impl From for TypeKind { diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index 588281292c15..cfaa5b59a26b 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -20,7 +20,7 @@ use crate::clean; /// module headings. If you are adding to this enum and want to ensure that the sidebar also prints /// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an /// ordering based on a helper function inside `item_module`, in the same file. -#[derive(Copy, PartialEq, Eq, Clone, Debug, PartialOrd, Ord)] +#[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)] crate enum ItemType { Module = 0, ExternCrate = 1, @@ -103,26 +103,6 @@ impl<'a> From<&'a clean::Item> for ItemType { } } -impl From for ItemType { - fn from(kind: clean::TypeKind) -> ItemType { - match kind { - clean::TypeKind::Struct => ItemType::Struct, - clean::TypeKind::Union => ItemType::Union, - clean::TypeKind::Enum => ItemType::Enum, - clean::TypeKind::Function => ItemType::Function, - clean::TypeKind::Trait => ItemType::Trait, - clean::TypeKind::Module => ItemType::Module, - clean::TypeKind::Static => ItemType::Static, - clean::TypeKind::Const => ItemType::Constant, - clean::TypeKind::Typedef => ItemType::Typedef, - clean::TypeKind::Foreign => ItemType::ForeignType, - clean::TypeKind::Macro => ItemType::Macro, - clean::TypeKind::TraitAlias => ItemType::TraitAlias, - clean::TypeKind::Primitive => ItemType::Primitive, - } - } -} - impl From for ItemType { fn from(other: hir::def::DefKind) -> Self { match other { diff --git a/src/librustdoc/html/render/cache.rs b/src/librustdoc/html/render/cache.rs index b8544a0f439a..f93a0d4fc2d7 100644 --- a/src/librustdoc/html/render/cache.rs +++ b/src/librustdoc/html/render/cache.rs @@ -7,7 +7,7 @@ use rustc_span::symbol::{sym, Symbol}; use serde::ser::{Serialize, SerializeStruct, Serializer}; use crate::clean::types::{ - FnDecl, FnRetTy, GenericBound, Generics, GetDefId, Type, TypeKind, WherePredicate, + FnDecl, FnRetTy, GenericBound, Generics, GetDefId, Type, WherePredicate, }; use crate::clean::{self, AttributesExt}; use crate::formats::cache::Cache; @@ -316,15 +316,15 @@ crate fn get_real_types<'tcx>( arg: &Type, tcx: TyCtxt<'tcx>, recurse: i32, - res: &mut FxHashSet<(Type, TypeKind)>, + res: &mut FxHashSet<(Type, ItemType)>, ) -> usize { - fn insert(res: &mut FxHashSet<(Type, TypeKind)>, tcx: TyCtxt<'_>, ty: Type) -> usize { + fn insert(res: &mut FxHashSet<(Type, ItemType)>, tcx: TyCtxt<'_>, ty: Type) -> usize { if let Some(kind) = ty.def_id().map(|did| tcx.def_kind(did).into()) { res.insert((ty, kind)); 1 } else if ty.is_primitive() { // This is a primitive, let's store it as such. - res.insert((ty, TypeKind::Primitive)); + res.insert((ty, ItemType::Primitive)); 1 } else { 0 @@ -394,7 +394,7 @@ crate fn get_all_types<'tcx>( generics: &Generics, decl: &FnDecl, tcx: TyCtxt<'tcx>, -) -> (Vec<(Type, TypeKind)>, Vec<(Type, TypeKind)>) { +) -> (Vec<(Type, ItemType)>, Vec<(Type, ItemType)>) { let mut all_types = FxHashSet::default(); for arg in decl.inputs.values.iter() { if arg.type_.is_self_type() { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d773f37ad90a..f1d0ba9319a7 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -54,7 +54,7 @@ use rustc_span::symbol::{kw, sym, Symbol}; use serde::ser::SerializeSeq; use serde::{Serialize, Serializer}; -use crate::clean::{self, GetDefId, RenderedLink, SelfTy, TypeKind}; +use crate::clean::{self, GetDefId, RenderedLink, SelfTy}; use crate::docfs::PathError; use crate::error::Error; use crate::formats::cache::Cache; @@ -182,11 +182,11 @@ impl Serialize for IndexItemFunctionType { #[derive(Debug)] crate struct TypeWithKind { ty: RenderType, - kind: TypeKind, + kind: ItemType, } -impl From<(RenderType, TypeKind)> for TypeWithKind { - fn from(x: (RenderType, TypeKind)) -> TypeWithKind { +impl From<(RenderType, ItemType)> for TypeWithKind { + fn from(x: (RenderType, ItemType)) -> TypeWithKind { TypeWithKind { ty: x.0, kind: x.1 } } } @@ -196,7 +196,7 @@ impl Serialize for TypeWithKind { where S: Serializer, { - (&self.ty.name, ItemType::from(self.kind)).serialize(serializer) + (&self.ty.name, self.kind).serialize(serializer) } }