Revert "rustdoc: Store DefId's in ItemId on heap for decreasing Item's size"

This reverts commit 41a345d4c46dad1a98c9993bc78513415994e8ba.
This commit is contained in:
Justus K 2021-06-27 09:28:17 +02:00
parent 45d3daece3
commit 97c82d8731
No known key found for this signature in database
GPG Key ID: 8C62FE98A62FC462
16 changed files with 109 additions and 115 deletions

View File

@ -113,7 +113,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: ItemId::Auto(box ImplId { trait_: trait_def_id, for_: item_def_id }),
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
span: Span::dummy(),
unsafety: hir::Unsafety::Normal,

View File

@ -96,7 +96,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
name: None,
attrs: Default::default(),
visibility: Inherited,
def_id: ItemId::Blanket(box ImplId { trait_: trait_def_id, for_: item_def_id }),
def_id: ItemId::Blanket { trait_: trait_def_id, for_: item_def_id },
kind: box ImplItem(Impl {
span: self.cx.tcx.def_span(impl_def_id).clean(self.cx),
unsafety: hir::Unsafety::Normal,

View File

@ -18,7 +18,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::lang_items::LangItem;
use rustc_hir::{BodyId, Mutability};
use rustc_index::vec::IndexVec;
@ -50,59 +50,61 @@ use self::Type::*;
crate type ItemIdSet = FxHashSet<ItemId>;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
crate struct ImplId {
crate trait_: DefId,
crate for_: DefId,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
crate enum ItemId {
/// A "normal" item that uses a [`DefId`] for identification.
DefId(DefId),
/// Identifier that is used for auto traits.
Auto(Box<ImplId>),
Auto { trait_: DefId, for_: DefId },
/// Identifier that is used for blanket implementations.
Blanket(Box<ImplId>),
Blanket { trait_: DefId, for_: DefId },
/// Identifier for primitive types.
Primitive(CrateNum),
}
impl ItemId {
#[inline]
crate fn is_local(&self) -> bool {
crate fn is_local(self) -> bool {
match self {
ItemId::Auto(box ImplId { for_: id, .. })
| ItemId::Blanket(box ImplId { for_: id, .. })
ItemId::Auto { for_: id, .. }
| ItemId::Blanket { for_: id, .. }
| ItemId::DefId(id) => id.is_local(),
ItemId::Primitive(krate) => *krate == LOCAL_CRATE,
ItemId::Primitive(krate) => krate == LOCAL_CRATE,
}
}
#[inline]
#[track_caller]
crate fn expect_def_id(&self) -> DefId {
crate fn expect_def_id(self) -> DefId {
self.as_def_id()
.unwrap_or_else(|| panic!("ItemId::expect_def_id: `{:?}` isn't a DefId", self))
}
#[inline]
crate fn as_def_id(&self) -> Option<DefId> {
crate fn as_def_id(self) -> Option<DefId> {
match self {
ItemId::DefId(id) => Some(*id),
ItemId::DefId(id) => Some(id),
_ => None,
}
}
#[inline]
crate fn krate(&self) -> CrateNum {
match *self {
ItemId::Auto(box ImplId { for_: id, .. })
| ItemId::Blanket(box ImplId { for_: id, .. })
crate fn krate(self) -> CrateNum {
match self {
ItemId::Auto { for_: id, .. }
| ItemId::Blanket { for_: id, .. }
| ItemId::DefId(id) => id.krate,
ItemId::Primitive(krate) => krate,
}
}
#[inline]
crate fn index(self) -> Option<DefIndex> {
match self {
ItemId::DefId(id) => Some(id.index),
_ => None,
}
}
}
impl From<DefId> for ItemId {
@ -377,7 +379,7 @@ impl Item {
{
*span
} else {
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(|| Span::dummy())
}
}

View File

@ -128,8 +128,8 @@ impl<'tcx> DocContext<'tcx> {
/// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds.
/// (This avoids a slice-index-out-of-bounds panic.)
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: &ItemId) -> Option<HirId> {
match *def_id {
crate fn as_local_hir_id(tcx: TyCtxt<'_>, def_id: ItemId) -> Option<HirId> {
match def_id {
ItemId::DefId(real_id) => {
real_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
}
@ -432,7 +432,7 @@ crate fn run_global_ctxt(
);
tcx.struct_lint_node(
crate::lint::MISSING_CRATE_LEVEL_DOCS,
DocContext::as_local_hir_id(tcx, &krate.module.def_id).unwrap(),
DocContext::as_local_hir_id(tcx, krate.module.def_id).unwrap(),
|lint| {
let mut diag =
lint.build("no documentation found for this crate's top-level module");

View File

@ -290,7 +290,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// A crate has a module at its root, containing all items,
// which should not be indexed. The crate-item itself is
// inserted later on when serializing the search-index.
if item.def_id.as_def_id().map_or(false, |did| did.index != CRATE_DEF_INDEX) {
if item.def_id.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) {
let desc = item.doc_value().map_or_else(String::new, |x| {
short_markdown_summary(&x.as_str(), &item.link_names(&self.cache))
});

View File

@ -753,7 +753,7 @@ fn assoc_const(
w,
"{}{}const <a href=\"{}\" class=\"constant\"><b>{}</b></a>: {}",
extra,
it.visibility.print_with_space(it.def_id.clone(), cx),
it.visibility.print_with_space(it.def_id, cx),
naive_assoc_href(it, link, cx),
it.name.as_ref().unwrap(),
ty.print(cx)
@ -872,7 +872,7 @@ fn render_assoc_item(
.unwrap_or_else(|| format!("#{}.{}", ty, name))
}
};
let vis = meth.visibility.print_with_space(meth.def_id.clone(), cx).to_string();
let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string();
let constness =
print_constness_with_space(&header.constness, meth.const_stability(cx.tcx()));
let asyncness = header.asyncness.print_with_space();
@ -984,7 +984,7 @@ fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item) {
}
}
#[derive(Clone)]
#[derive(Copy, Clone)]
enum AssocItemLink<'a> {
Anchor(Option<&'a str>),
GotoSource(ItemId, &'a FxHashSet<Symbol>),
@ -994,7 +994,7 @@ impl<'a> AssocItemLink<'a> {
fn anchor(&self, id: &'a str) -> Self {
match *self {
AssocItemLink::Anchor(_) => AssocItemLink::Anchor(Some(&id)),
ref other => other.clone(),
ref other => *other,
}
}
}
@ -1306,14 +1306,7 @@ fn render_impl(
} else {
// In case the item isn't documented,
// provide short documentation from the trait.
document_short(
&mut doc_buffer,
it,
cx,
link.clone(),
parent,
show_def_docs,
);
document_short(&mut doc_buffer, it, cx, link, parent, show_def_docs);
}
}
} else {
@ -1324,7 +1317,7 @@ fn render_impl(
}
}
} else {
document_short(&mut doc_buffer, item, cx, link.clone(), parent, show_def_docs);
document_short(&mut doc_buffer, item, cx, link, parent, show_def_docs);
}
}
let w = if short_documented && trait_.is_some() { interesting } else { boring };
@ -1452,7 +1445,7 @@ fn render_impl(
trait_item,
if trait_.is_some() { &i.impl_item } else { parent },
parent,
link.clone(),
link,
render_mode,
false,
trait_.map(|t| &t.trait_),

View File

@ -245,7 +245,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
// (which is the position in the vector).
indices.dedup_by_key(|i| {
(
items[*i].def_id.clone(),
items[*i].def_id,
if items[*i].name.as_ref().is_some() { Some(full_path(cx, &items[*i])) } else { None },
items[*i].type_(),
if items[*i].is_import() { *i } else { 0 },
@ -288,14 +288,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
Some(ref src) => write!(
w,
"<div class=\"item-left\"><code>{}extern crate {} as {};",
myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
myitem.visibility.print_with_space(myitem.def_id, cx),
anchor(myitem.def_id.expect_def_id(), &*src.as_str(), cx),
myitem.name.as_ref().unwrap(),
),
None => write!(
w,
"<div class=\"item-left\"><code>{}extern crate {};",
myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
myitem.visibility.print_with_space(myitem.def_id, cx),
anchor(
myitem.def_id.expect_def_id(),
&*myitem.name.as_ref().unwrap().as_str(),
@ -336,7 +336,7 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl
<div class=\"item-right docblock-short\">{stab_tags}</div>",
stab = stab.unwrap_or_default(),
add = add,
vis = myitem.visibility.print_with_space(myitem.def_id.clone(), cx),
vis = myitem.visibility.print_with_space(myitem.def_id, cx),
imp = import.print(cx),
stab_tags = stab_tags.unwrap_or_default(),
);
@ -437,7 +437,7 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) ->
}
fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) {
let vis = it.visibility.print_with_space(it.def_id.clone(), cx).to_string();
let vis = it.visibility.print_with_space(it.def_id, cx).to_string();
let constness = print_constness_with_space(&f.header.constness, it.const_stability(cx.tcx()));
let asyncness = f.header.asyncness.print_with_space();
let unsafety = f.header.unsafety.print_with_space();
@ -489,7 +489,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
write!(
w,
"{}{}{}trait {}{}{}",
it.visibility.print_with_space(it.def_id.clone(), cx),
it.visibility.print_with_space(it.def_id, cx),
t.unsafety.print_with_space(),
if t.is_auto { "auto " } else { "" },
it.name.as_ref().unwrap(),
@ -710,10 +710,8 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
for implementor in foreign {
let provided_methods = implementor.inner_impl().provided_trait_methods(cx.tcx());
let assoc_link = AssocItemLink::GotoSource(
implementor.impl_item.def_id.clone(),
&provided_methods,
);
let assoc_link =
AssocItemLink::GotoSource(implementor.impl_item.def_id, &provided_methods);
render_impl(
w,
cx,
@ -917,7 +915,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!(
w,
"{}enum {}{}{}",
it.visibility.print_with_space(it.def_id.clone(), cx),
it.visibility.print_with_space(it.def_id, cx),
it.name.as_ref().unwrap(),
e.generics.print(cx),
print_where_clause(&e.generics, cx, 0, true),
@ -1105,7 +1103,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean::
write!(
w,
"{vis}const {name}: {typ}",
vis = it.visibility.print_with_space(it.def_id.clone(), cx),
vis = it.visibility.print_with_space(it.def_id, cx),
name = it.name.as_ref().unwrap(),
typ = c.type_.print(cx),
);
@ -1195,7 +1193,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St
write!(
w,
"{vis}static {mutability}{name}: {typ}</pre>",
vis = it.visibility.print_with_space(it.def_id.clone(), cx),
vis = it.visibility.print_with_space(it.def_id, cx),
mutability = s.mutability.print_with_space(),
name = it.name.as_ref().unwrap(),
typ = s.type_.print(cx)
@ -1209,7 +1207,7 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
write!(
w,
" {}type {};\n}}</pre>",
it.visibility.print_with_space(it.def_id.clone(), cx),
it.visibility.print_with_space(it.def_id, cx),
it.name.as_ref().unwrap(),
);
@ -1364,7 +1362,7 @@ fn render_union(
write!(
w,
"{}{}{}",
it.visibility.print_with_space(it.def_id.clone(), cx),
it.visibility.print_with_space(it.def_id, cx),
if structhead { "union " } else { "" },
it.name.as_ref().unwrap()
);
@ -1386,7 +1384,7 @@ fn render_union(
write!(
w,
" {}{}: {},\n{}",
field.visibility.print_with_space(field.def_id.clone(), cx),
field.visibility.print_with_space(field.def_id, cx),
field.name.as_ref().unwrap(),
ty.print(cx),
tab
@ -1416,7 +1414,7 @@ fn render_struct(
write!(
w,
"{}{}{}",
it.visibility.print_with_space(it.def_id.clone(), cx),
it.visibility.print_with_space(it.def_id, cx),
if structhead { "struct " } else { "" },
it.name.as_ref().unwrap()
);
@ -1442,7 +1440,7 @@ fn render_struct(
w,
"\n{} {}{}: {},",
tab,
field.visibility.print_with_space(field.def_id.clone(), cx),
field.visibility.print_with_space(field.def_id, cx),
field.name.as_ref().unwrap(),
ty.print(cx),
);
@ -1476,7 +1474,7 @@ fn render_struct(
write!(
w,
"{}{}",
field.visibility.print_with_space(field.def_id.clone(), cx),
field.visibility.print_with_space(field.def_id, cx),
ty.print(cx),
)
}

View File

@ -30,7 +30,7 @@ impl JsonRenderer<'_> {
.into_iter()
.flatten()
.filter_map(|clean::ItemLink { link, did, .. }| {
did.map(|did| (link.clone(), from_item_id(&did.into())))
did.map(|did| (link.clone(), from_item_id(did.into())))
})
.collect();
let docs = item.attrs.collapsed_doc_value();
@ -41,15 +41,14 @@ impl JsonRenderer<'_> {
.map(rustc_ast_pretty::pprust::attribute_to_string)
.collect();
let span = item.span(self.tcx);
let clean::Item { name, attrs: _, kind: _, visibility, ref def_id, cfg: _ } = item;
let def_id = def_id.clone();
let clean::Item { name, attrs: _, kind: _, visibility, def_id, cfg: _ } = item;
let inner = match *item.kind {
clean::StrippedItem(_) => return None,
_ => from_clean_item(item, self.tcx),
};
Some(Item {
id: from_item_id(def_id),
crate_id: def_id.krate().as_u32(),
id: from_item_id(&def_id),
name: name.map(|sym| sym.to_string()),
span: self.convert_span(span),
visibility: self.convert_visibility(visibility),
@ -87,7 +86,7 @@ impl JsonRenderer<'_> {
Inherited => Visibility::Default,
Restricted(did) if did.index == CRATE_DEF_INDEX => Visibility::Crate,
Restricted(did) => Visibility::Restricted {
parent: from_item_id(&did.into()),
parent: from_item_id(did.into()),
path: self.tcx.def_path(did).to_string_no_crate_verbose(),
},
}
@ -171,7 +170,7 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind {
}
}
crate fn from_item_id(did: &ItemId) -> Id {
crate fn from_item_id(did: ItemId) -> Id {
match did {
ItemId::DefId(did) => Id(format!("{}:{}", did.krate.as_u32(), u32::from(did.index))),
_ => todo!("how should json ItemId's be represented?"),
@ -374,7 +373,7 @@ impl FromWithTcx<clean::Type> for Type {
match ty {
ResolvedPath { path, did, is_generic: _ } => Type::ResolvedPath {
name: path.whole_name(),
id: from_item_id(&did.into()),
id: from_item_id(did.into()),
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
param_names: Vec::new(),
},
@ -386,7 +385,7 @@ impl FromWithTcx<clean::Type> for Type {
Type::ResolvedPath {
name: path.whole_name(),
id: from_item_id(&id.into()),
id: from_item_id(id.into()),
args: path
.segments
.last()
@ -567,13 +566,13 @@ impl FromWithTcx<clean::Import> for Import {
Simple(s) => Import {
source: import.source.path.whole_name(),
name: s.to_string(),
id: import.source.did.map(ItemId::from).as_ref().map(from_item_id),
id: import.source.did.map(ItemId::from).map(from_item_id),
glob: false,
},
Glob => Import {
source: import.source.path.whole_name(),
name: import.source.path.last_name().to_string(),
id: import.source.did.map(ItemId::from).as_ref().map(from_item_id),
id: import.source.did.map(ItemId::from).map(from_item_id),
glob: true,
},
}
@ -667,5 +666,5 @@ impl FromWithTcx<ItemType> for ItemKind {
}
fn ids(items: impl IntoIterator<Item = clean::Item>) -> Vec<Id> {
items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_item_id(&i.def_id)).collect()
items.into_iter().filter(|x| !x.is_stripped()).map(|i| from_item_id(i.def_id)).collect()
}

View File

@ -53,7 +53,7 @@ impl JsonRenderer<'tcx> {
.map(|i| {
let item = &i.impl_item;
self.item(item.clone()).unwrap();
from_item_id(&item.def_id)
from_item_id(item.def_id)
})
.collect()
})
@ -71,7 +71,7 @@ impl JsonRenderer<'tcx> {
let item = &i.impl_item;
if item.def_id.is_local() {
self.item(item.clone()).unwrap();
Some(from_item_id(&item.def_id))
Some(from_item_id(item.def_id))
} else {
None
}
@ -91,9 +91,9 @@ impl JsonRenderer<'tcx> {
let trait_item = &trait_item.trait_;
trait_item.items.clone().into_iter().for_each(|i| self.item(i).unwrap());
Some((
from_item_id(&id.into()),
from_item_id(id.into()),
types::Item {
id: from_item_id(&id.into()),
id: from_item_id(id.into()),
crate_id: id.krate.as_u32(),
name: self
.cache
@ -161,7 +161,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
// Flatten items that recursively store other items
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
let id = item.def_id.clone();
let id = item.def_id;
if let Some(mut new_item) = self.convert_item(item) {
if let types::ItemEnum::Trait(ref mut t) = new_item.inner {
t.implementors = self.get_trait_implementors(id.expect_def_id())
@ -170,7 +170,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
} else if let types::ItemEnum::Enum(ref mut e) = new_item.inner {
e.impls = self.get_impls(id.expect_def_id())
}
let removed = self.index.borrow_mut().insert(from_item_id(&id), new_item.clone());
let removed = self.index.borrow_mut().insert(from_item_id(id), new_item.clone());
// FIXME(adotinthevoid): Currently, the index is duplicated. This is a sanity check
// to make sure the items are unique. The main place this happens is when an item, is
@ -207,7 +207,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
.chain(self.cache.external_paths.clone().into_iter())
.map(|(k, (path, kind))| {
(
from_item_id(&k.into()),
from_item_id(k.into()),
types::ItemSummary {
crate_id: k.krate.as_u32(),
path,

View File

@ -58,7 +58,7 @@ crate fn check_bare_urls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
impl<'a, 'tcx> DocFolder for BareUrlsLinter<'a, 'tcx> {
fn fold_item(&mut self, item: Item) -> Option<Item> {
let hir_id = match DocContext::as_local_hir_id(self.cx.tcx, &item.def_id) {
let hir_id = match DocContext::as_local_hir_id(self.cx.tcx, item.def_id) {
Some(hir_id) => hir_id,
None => {
// If non-local, no need to check anything.

View File

@ -838,34 +838,41 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
// find item's parent to resolve `Self` in item's docs below
debug!("looking for the `Self` type");
let self_id = item.def_id.as_def_id().and_then(|did| {
if (matches!(self.cx.tcx.def_kind(did), DefKind::Field)
&& matches!(
self.cx.tcx.def_kind(self.cx.tcx.parent(did).unwrap()),
DefKind::Variant
))
let self_id = match item.def_id.as_def_id() {
None => None,
Some(did)
if (matches!(self.cx.tcx.def_kind(did), DefKind::Field)
&& matches!(
self.cx.tcx.def_kind(self.cx.tcx.parent(did).unwrap()),
DefKind::Variant
)) =>
{
self.cx.tcx.parent(did).and_then(|item_id| self.cx.tcx.parent(item_id))
} else if matches!(
self.cx.tcx.def_kind(did),
DefKind::AssocConst
| DefKind::AssocFn
| DefKind::AssocTy
| DefKind::Variant
| DefKind::Field
) {
}
Some(did)
if matches!(
self.cx.tcx.def_kind(did),
DefKind::AssocConst
| DefKind::AssocFn
| DefKind::AssocTy
| DefKind::Variant
| DefKind::Field
) =>
{
self.cx.tcx.parent(did)
} else if let Some(parent) = self.cx.tcx.parent(did) {
}
Some(did) => match self.cx.tcx.parent(did) {
// HACK(jynelson): `clean` marks associated types as `TypedefItem`, not as `AssocTypeItem`.
// Fixing this breaks `fn render_deref_methods`.
// As a workaround, see if the parent of the item is an `impl`; if so this must be an associated item,
// regardless of what rustdoc wants to call it.
let parent_kind = self.cx.tcx.def_kind(parent);
Some(if parent_kind == DefKind::Impl { parent } else { did })
} else {
Some(did)
}
});
Some(parent) => {
let parent_kind = self.cx.tcx.def_kind(parent);
Some(if parent_kind == DefKind::Impl { parent } else { did })
}
None => Some(did),
},
};
// FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
let self_name = self_id.and_then(|self_id| {
@ -909,12 +916,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
for md_link in markdown_links(&doc) {
let link = self.resolve_link(&item, &doc, &self_name, parent_node, krate, md_link);
if let Some(link) = link {
self.cx
.cache
.intra_doc_links
.entry(item.def_id.clone())
.or_default()
.push(link);
self.cx.cache.intra_doc_links.entry(item.def_id).or_default().push(link);
}
}
}
@ -1710,7 +1712,7 @@ fn report_diagnostic(
DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>,
decorate: impl FnOnce(&mut DiagnosticBuilder<'_>, Option<rustc_span::Span>),
) {
let hir_id = match DocContext::as_local_hir_id(tcx, &item.def_id) {
let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) {
Some(hir_id) => hir_id,
None => {
// If non-local, no need to check anything.

View File

@ -46,7 +46,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
// FIXME(eddyb) is this `doc(hidden)` check needed?
if !cx.tcx.get_attrs(def_id).lists(sym::doc).has_word(sym::hidden) {
let impls = get_auto_trait_and_blanket_impls(cx, def_id.into());
new_items.extend(impls.filter(|i| cx.inlined.insert(i.def_id.clone())));
new_items.extend(impls.filter(|i| cx.inlined.insert(i.def_id)));
}
});
}
@ -165,7 +165,7 @@ impl ItemCollector {
impl DocFolder for ItemCollector {
fn fold_item(&mut self, i: Item) -> Option<Item> {
self.items.insert(i.def_id.clone());
self.items.insert(i.def_id);
Some(self.fold_item_recur(i))
}

View File

@ -84,7 +84,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo
}
crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
let hir_id = match DocContext::as_local_hir_id(cx.tcx, &item.def_id) {
let hir_id = match DocContext::as_local_hir_id(cx.tcx, item.def_id) {
Some(hir_id) => hir_id,
None => {
// If non-local, no need to check anything.

View File

@ -168,7 +168,7 @@ fn extract_tags(
impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {
fn fold_item(&mut self, item: Item) -> Option<Item> {
let tcx = self.cx.tcx;
let hir_id = match DocContext::as_local_hir_id(tcx, &item.def_id) {
let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) {
Some(hir_id) => hir_id,
None => {
// If non-local, no need to check anything.

View File

@ -52,7 +52,7 @@ impl<'a> DocFolder for Stripper<'a> {
}
} else {
if self.update_retained {
self.retained.insert(i.def_id.clone());
self.retained.insert(i.def_id);
}
}
Some(self.fold_item_recur(i))

View File

@ -100,7 +100,7 @@ impl<'a> DocFolder for Stripper<'a> {
let i = if fastreturn {
if self.update_retained {
self.retained.insert(i.def_id.clone());
self.retained.insert(i.def_id);
}
return Some(i);
} else {
@ -108,7 +108,7 @@ impl<'a> DocFolder for Stripper<'a> {
};
if self.update_retained {
self.retained.insert(i.def_id.clone());
self.retained.insert(i.def_id);
}
Some(i)
}