diff options
| author | Justus K <justus.k@protonmail.com> | 2021-06-26 20:47:33 +0200 |
|---|---|---|
| committer | Justus K <justus.k@protonmail.com> | 2021-07-05 19:51:51 +0200 |
| commit | 45d3daece364e4cf6b6bc4668dcfd7670197b1e8 (patch) | |
| tree | 6c6dad674e0b7ba6e4991f554b492f8b3ec6bef8 | |
| parent | acd4dc2d0ca8676fbf105507504e24d44e5dd1f6 (diff) | |
| download | rust-45d3daece364e4cf6b6bc4668dcfd7670197b1e8.tar.gz rust-45d3daece364e4cf6b6bc4668dcfd7670197b1e8.zip | |
rustdoc: Store DefId's in ItemId on heap for decreasing Item's size
| -rw-r--r-- | src/librustdoc/clean/auto_trait.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/blanket_impl.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 46 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/formats/cache.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/html/render/mod.rs | 21 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 36 | ||||
| -rw-r--r-- | src/librustdoc/json/conversions.rs | 21 | ||||
| -rw-r--r-- | src/librustdoc/json/mod.rs | 14 | ||||
| -rw-r--r-- | src/librustdoc/passes/bare_urls.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/passes/collect_intra_doc_links.rs | 58 | ||||
| -rw-r--r-- | src/librustdoc/passes/collect_trait_impls.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/passes/doc_test_lints.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/passes/html_tags.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/passes/strip_hidden.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/passes/stripper.rs | 4 |
16 files changed, 115 insertions, 109 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index e479d162b8f..5564261492e 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -113,7 +113,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { name: None, attrs: Default::default(), visibility: Inherited, - def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id }, + def_id: ItemId::Auto(box ImplId { trait_: trait_def_id, for_: item_def_id }), kind: box ImplItem(Impl { span: Span::dummy(), unsafety: hir::Unsafety::Normal, diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 59fefee5ee4..af8680fb40c 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -96,7 +96,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { name: None, attrs: Default::default(), visibility: Inherited, - def_id: ItemId::Blanket { trait_: trait_def_id, for_: item_def_id }, + def_id: ItemId::Blanket(box ImplId { 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, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 12c9e561f04..4fa1fde5f0b 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -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, DefIndex, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::lang_items::LangItem; use rustc_hir::{BodyId, Mutability}; use rustc_index::vec::IndexVec; @@ -50,61 +50,59 @@ use self::Type::*; crate type ItemIdSet = FxHashSet<ItemId>; -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)] +#[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)] crate enum ItemId { /// A "normal" item that uses a [`DefId`] for identification. DefId(DefId), /// Identifier that is used for auto traits. - Auto { trait_: DefId, for_: DefId }, + Auto(Box<ImplId>), /// Identifier that is used for blanket implementations. - Blanket { trait_: DefId, for_: DefId }, + Blanket(Box<ImplId>), /// 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 { for_: id, .. } - | ItemId::Blanket { for_: id, .. } + ItemId::Auto(box ImplId { for_: id, .. }) + | ItemId::Blanket(box ImplId { 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 { for_: id, .. } - | ItemId::Blanket { for_: id, .. } + crate fn krate(&self) -> CrateNum { + match *self { + ItemId::Auto(box ImplId { for_: id, .. }) + | ItemId::Blanket(box ImplId { 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 { @@ -379,7 +377,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) } } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 0689d72e4e0..a9f84e747b1 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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"); diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 671e9e5c382..978ba501fd0 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -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.index().map_or(false, |idx| idx != CRATE_DEF_INDEX) { + if item.def_id.as_def_id().map_or(false, |did| did.index != 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)) }); diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 97ee682c11c..1cee68baff4 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -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, cx), + it.visibility.print_with_space(it.def_id.clone(), 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, cx).to_string(); + let vis = meth.visibility.print_with_space(meth.def_id.clone(), 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(Copy, Clone)] +#[derive(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, + ref other => other.clone(), } } } @@ -1306,7 +1306,14 @@ 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, parent, show_def_docs); + document_short( + &mut doc_buffer, + it, + cx, + link.clone(), + parent, + show_def_docs, + ); } } } else { @@ -1317,7 +1324,7 @@ fn render_impl( } } } else { - document_short(&mut doc_buffer, item, cx, link, parent, show_def_docs); + document_short(&mut doc_buffer, item, cx, link.clone(), parent, show_def_docs); } } let w = if short_documented && trait_.is_some() { interesting } else { boring }; @@ -1445,7 +1452,7 @@ fn render_impl( trait_item, if trait_.is_some() { &i.impl_item } else { parent }, parent, - link, + link.clone(), render_mode, false, trait_.map(|t| &t.trait_), diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index eeac9d1a9db..70e80b20b2a 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -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, + items[*i].def_id.clone(), 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, cx), + myitem.visibility.print_with_space(myitem.def_id.clone(), 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, cx), + myitem.visibility.print_with_space(myitem.def_id.clone(), 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, cx), + vis = myitem.visibility.print_with_space(myitem.def_id.clone(), 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, cx).to_string(); + let vis = it.visibility.print_with_space(it.def_id.clone(), 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, cx), + it.visibility.print_with_space(it.def_id.clone(), cx), t.unsafety.print_with_space(), if t.is_auto { "auto " } else { "" }, it.name.as_ref().unwrap(), @@ -710,8 +710,10 @@ 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, &provided_methods); + let assoc_link = AssocItemLink::GotoSource( + implementor.impl_item.def_id.clone(), + &provided_methods, + ); render_impl( w, cx, @@ -915,7 +917,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, cx), + it.visibility.print_with_space(it.def_id.clone(), cx), it.name.as_ref().unwrap(), e.generics.print(cx), print_where_clause(&e.generics, cx, 0, true), @@ -1103,7 +1105,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, cx), + vis = it.visibility.print_with_space(it.def_id.clone(), cx), name = it.name.as_ref().unwrap(), typ = c.type_.print(cx), ); @@ -1193,7 +1195,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, cx), + vis = it.visibility.print_with_space(it.def_id.clone(), cx), mutability = s.mutability.print_with_space(), name = it.name.as_ref().unwrap(), typ = s.type_.print(cx) @@ -1207,7 +1209,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, cx), + it.visibility.print_with_space(it.def_id.clone(), cx), it.name.as_ref().unwrap(), ); @@ -1362,7 +1364,7 @@ fn render_union( write!( w, "{}{}{}", - it.visibility.print_with_space(it.def_id, cx), + it.visibility.print_with_space(it.def_id.clone(), cx), if structhead { "union " } else { "" }, it.name.as_ref().unwrap() ); @@ -1384,7 +1386,7 @@ fn render_union( write!( w, " {}{}: {},\n{}", - field.visibility.print_with_space(field.def_id, cx), + field.visibility.print_with_space(field.def_id.clone(), cx), field.name.as_ref().unwrap(), ty.print(cx), tab @@ -1414,7 +1416,7 @@ fn render_struct( write!( w, "{}{}{}", - it.visibility.print_with_space(it.def_id, cx), + it.visibility.print_with_space(it.def_id.clone(), cx), if structhead { "struct " } else { "" }, it.name.as_ref().unwrap() ); @@ -1440,7 +1442,7 @@ fn render_struct( w, "\n{} {}{}: {},", tab, - field.visibility.print_with_space(field.def_id, cx), + field.visibility.print_with_space(field.def_id.clone(), cx), field.name.as_ref().unwrap(), ty.print(cx), ); @@ -1474,7 +1476,7 @@ fn render_struct( write!( w, "{}{}", - field.visibility.print_with_space(field.def_id, cx), + field.visibility.print_with_space(field.def_id.clone(), cx), ty.print(cx), ) } diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index d4549a78f21..98c34ee8be7 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -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,14 +41,15 @@ impl JsonRenderer<'_> { .map(rustc_ast_pretty::pprust::attribute_to_string) .collect(); let span = item.span(self.tcx); - let clean::Item { name, attrs: _, kind: _, visibility, def_id, cfg: _ } = item; + let clean::Item { name, attrs: _, kind: _, visibility, ref def_id, cfg: _ } = item; + let def_id = def_id.clone(); 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), @@ -86,7 +87,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(), }, } @@ -170,7 +171,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?"), @@ -373,7 +374,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(), }, @@ -385,7 +386,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() @@ -566,13 +567,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).map(from_item_id), + id: import.source.did.map(ItemId::from).as_ref().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).map(from_item_id), + id: import.source.did.map(ItemId::from).as_ref().map(from_item_id), glob: true, }, } @@ -666,5 +667,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() } diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 8bdf1a59812..06c66ce5540 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -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; + let id = item.def_id.clone(); 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, diff --git a/src/librustdoc/passes/bare_urls.rs b/src/librustdoc/passes/bare_urls.rs index 56ef15eb884..9d02ae25072 100644 --- a/src/librustdoc/passes/bare_urls.rs +++ b/src/librustdoc/passes/bare_urls.rs @@ -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. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 44a3faf6f7b..61623bac27e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -838,41 +838,34 @@ 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 = 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 - )) => + 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 + )) { self.cx.tcx.parent(did).and_then(|item_id| self.cx.tcx.parent(item_id)) - } - Some(did) - if matches!( - self.cx.tcx.def_kind(did), - DefKind::AssocConst - | DefKind::AssocFn - | DefKind::AssocTy - | DefKind::Variant - | DefKind::Field - ) => - { + } else if matches!( + self.cx.tcx.def_kind(did), + DefKind::AssocConst + | DefKind::AssocFn + | DefKind::AssocTy + | DefKind::Variant + | DefKind::Field + ) { self.cx.tcx.parent(did) - } - Some(did) => match self.cx.tcx.parent(did) { + } else if let Some(parent) = 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. - Some(parent) => { - let parent_kind = self.cx.tcx.def_kind(parent); - Some(if parent_kind == DefKind::Impl { parent } else { did }) - } - None => Some(did), - }, - }; + let parent_kind = self.cx.tcx.def_kind(parent); + Some(if parent_kind == DefKind::Impl { parent } else { did }) + } else { + 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| { @@ -916,7 +909,12 @@ 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).or_default().push(link); + self.cx + .cache + .intra_doc_links + .entry(item.def_id.clone()) + .or_default() + .push(link); } } } @@ -1712,7 +1710,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. diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 91c495a2bbc..d589c697fa6 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -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))); + new_items.extend(impls.filter(|i| cx.inlined.insert(i.def_id.clone()))); } }); } @@ -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); + self.items.insert(i.def_id.clone()); Some(self.fold_item_recur(i)) } diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 03bc2b52f17..c3a30661e50 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -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. diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index f29d38e3e07..ad9f80c2e6c 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -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. diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index 0aedbda35e9..b0c745edbba 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -52,7 +52,7 @@ impl<'a> DocFolder for Stripper<'a> { } } else { if self.update_retained { - self.retained.insert(i.def_id); + self.retained.insert(i.def_id.clone()); } } Some(self.fold_item_recur(i)) diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4305268c9aa..6ee7179c5db 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -100,7 +100,7 @@ impl<'a> DocFolder for Stripper<'a> { let i = if fastreturn { if self.update_retained { - self.retained.insert(i.def_id); + self.retained.insert(i.def_id.clone()); } return Some(i); } else { @@ -108,7 +108,7 @@ impl<'a> DocFolder for Stripper<'a> { }; if self.update_retained { - self.retained.insert(i.def_id); + self.retained.insert(i.def_id.clone()); } Some(i) } |
