1
Fork 0

Use ItemType in cache

This commit is contained in:
Joshua Nelson 2021-04-22 21:27:19 -04:00
parent 1481af9f59
commit f3ef4b2cef
4 changed files with 11 additions and 32 deletions

View file

@ -1456,7 +1456,6 @@ crate enum TypeKind {
Foreign, Foreign,
Macro, Macro,
TraitAlias, TraitAlias,
Primitive,
} }
impl From<hir::def::DefKind> for TypeKind { impl From<hir::def::DefKind> for TypeKind {

View file

@ -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 /// 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 /// 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. /// 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 { crate enum ItemType {
Module = 0, Module = 0,
ExternCrate = 1, ExternCrate = 1,
@ -103,26 +103,6 @@ impl<'a> From<&'a clean::Item> for ItemType {
} }
} }
impl From<clean::TypeKind> 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<hir::def::DefKind> for ItemType { impl From<hir::def::DefKind> for ItemType {
fn from(other: hir::def::DefKind) -> Self { fn from(other: hir::def::DefKind) -> Self {
match other { match other {

View file

@ -7,7 +7,7 @@ use rustc_span::symbol::{sym, Symbol};
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use crate::clean::types::{ 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::clean::{self, AttributesExt};
use crate::formats::cache::Cache; use crate::formats::cache::Cache;
@ -316,15 +316,15 @@ crate fn get_real_types<'tcx>(
arg: &Type, arg: &Type,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
recurse: i32, recurse: i32,
res: &mut FxHashSet<(Type, TypeKind)>, res: &mut FxHashSet<(Type, ItemType)>,
) -> usize { ) -> 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()) { if let Some(kind) = ty.def_id().map(|did| tcx.def_kind(did).into()) {
res.insert((ty, kind)); res.insert((ty, kind));
1 1
} else if ty.is_primitive() { } else if ty.is_primitive() {
// This is a primitive, let's store it as such. // This is a primitive, let's store it as such.
res.insert((ty, TypeKind::Primitive)); res.insert((ty, ItemType::Primitive));
1 1
} else { } else {
0 0
@ -394,7 +394,7 @@ crate fn get_all_types<'tcx>(
generics: &Generics, generics: &Generics,
decl: &FnDecl, decl: &FnDecl,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
) -> (Vec<(Type, TypeKind)>, Vec<(Type, TypeKind)>) { ) -> (Vec<(Type, ItemType)>, Vec<(Type, ItemType)>) {
let mut all_types = FxHashSet::default(); let mut all_types = FxHashSet::default();
for arg in decl.inputs.values.iter() { for arg in decl.inputs.values.iter() {
if arg.type_.is_self_type() { if arg.type_.is_self_type() {

View file

@ -54,7 +54,7 @@ use rustc_span::symbol::{kw, sym, Symbol};
use serde::ser::SerializeSeq; use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer}; 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::docfs::PathError;
use crate::error::Error; use crate::error::Error;
use crate::formats::cache::Cache; use crate::formats::cache::Cache;
@ -182,11 +182,11 @@ impl Serialize for IndexItemFunctionType {
#[derive(Debug)] #[derive(Debug)]
crate struct TypeWithKind { crate struct TypeWithKind {
ty: RenderType, ty: RenderType,
kind: TypeKind, kind: ItemType,
} }
impl From<(RenderType, TypeKind)> for TypeWithKind { impl From<(RenderType, ItemType)> for TypeWithKind {
fn from(x: (RenderType, TypeKind)) -> TypeWithKind { fn from(x: (RenderType, ItemType)) -> TypeWithKind {
TypeWithKind { ty: x.0, kind: x.1 } TypeWithKind { ty: x.0, kind: x.1 }
} }
} }
@ -196,7 +196,7 @@ impl Serialize for TypeWithKind {
where where
S: Serializer, S: Serializer,
{ {
(&self.ty.name, ItemType::from(self.kind)).serialize(serializer) (&self.ty.name, self.kind).serialize(serializer)
} }
} }