From 65903362ad810c572e8ae742f6ed5ae3548238e4 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 30 Aug 2024 10:52:45 -0700 Subject: [PATCH] rustdoc: use a single box to store Attributes and ItemKind --- src/librustdoc/clean/auto_trait.rs | 22 +++--- src/librustdoc/clean/blanket_impl.rs | 72 ++++++++++--------- src/librustdoc/clean/inline.rs | 51 +++++++------ src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/types.rs | 55 ++++++++------ src/librustdoc/clean/utils.rs | 6 +- src/librustdoc/fold.rs | 10 +-- src/librustdoc/formats/cache.rs | 26 ++++--- src/librustdoc/formats/item_type.rs | 2 +- src/librustdoc/formats/mod.rs | 2 +- src/librustdoc/formats/renderer.rs | 2 +- src/librustdoc/html/render/context.rs | 2 +- src/librustdoc/html/render/mod.rs | 22 +++--- src/librustdoc/html/render/print_item.rs | 38 +++++----- src/librustdoc/html/render/search_index.rs | 4 +- src/librustdoc/html/render/sidebar.rs | 10 +-- src/librustdoc/html/render/write_shared.rs | 2 +- src/librustdoc/json/conversions.rs | 6 +- src/librustdoc/json/import_finder.rs | 2 +- src/librustdoc/json/mod.rs | 4 +- .../passes/calculate_doc_coverage.rs | 2 +- .../passes/check_doc_test_visibility.rs | 2 +- src/librustdoc/passes/collect_trait_impls.rs | 10 +-- src/librustdoc/passes/propagate_doc_cfg.rs | 2 +- .../passes/strip_aliased_non_local.rs | 2 +- src/librustdoc/passes/strip_hidden.rs | 4 +- src/librustdoc/passes/stripper.rs | 8 +-- src/librustdoc/visit.rs | 4 +- 28 files changed, 195 insertions(+), 179 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 65490108027..7e3881c798b 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -115,17 +115,19 @@ fn synthesize_auto_trait_impl<'tcx>( Some(clean::Item { name: None, - attrs: Default::default(), + inner: Box::new(clean::ItemInner { + attrs: Default::default(), + kind: clean::ImplItem(Box::new(clean::Impl { + safety: hir::Safety::Safe, + generics, + trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())), + for_: clean_middle_ty(ty::Binder::dummy(ty), cx, None, None), + items: Vec::new(), + polarity, + kind: clean::ImplKind::Auto, + })), + }), item_id: clean::ItemId::Auto { trait_: trait_def_id, for_: item_def_id }, - kind: Box::new(clean::ImplItem(Box::new(clean::Impl { - safety: hir::Safety::Safe, - generics, - trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())), - for_: clean_middle_ty(ty::Binder::dummy(ty), cx, None, None), - items: Vec::new(), - polarity, - kind: clean::ImplKind::Auto, - }))), cfg: None, inline_stmt_id: None, }) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 1f5f6602b9f..95f6616cec3 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -84,42 +84,44 @@ pub(crate) fn synthesize_blanket_impls( blanket_impls.push(clean::Item { name: None, - attrs: Default::default(), item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, - kind: Box::new(clean::ImplItem(Box::new(clean::Impl { - safety: hir::Safety::Safe, - generics: clean_ty_generics( - cx, - tcx.generics_of(impl_def_id), - tcx.explicit_predicates_of(impl_def_id), - ), - // FIXME(eddyb) compute both `trait_` and `for_` from - // the post-inference `trait_ref`, as it's more accurate. - trait_: Some(clean_trait_ref_with_constraints( - cx, - ty::Binder::dummy(trait_ref.instantiate_identity()), - ThinVec::new(), - )), - for_: clean_middle_ty( - ty::Binder::dummy(ty.instantiate_identity()), - cx, - None, - None, - ), - items: tcx - .associated_items(impl_def_id) - .in_definition_order() - .filter(|item| !item.is_impl_trait_in_trait()) - .map(|item| clean_middle_assoc_item(item, cx)) - .collect(), - polarity: ty::ImplPolarity::Positive, - kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty( - ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()), - cx, - None, - None, - ))), - }))), + inner: Box::new(clean::ItemInner { + attrs: Default::default(), + kind: clean::ImplItem(Box::new(clean::Impl { + safety: hir::Safety::Safe, + generics: clean_ty_generics( + cx, + tcx.generics_of(impl_def_id), + tcx.explicit_predicates_of(impl_def_id), + ), + // FIXME(eddyb) compute both `trait_` and `for_` from + // the post-inference `trait_ref`, as it's more accurate. + trait_: Some(clean_trait_ref_with_constraints( + cx, + ty::Binder::dummy(trait_ref.instantiate_identity()), + ThinVec::new(), + )), + for_: clean_middle_ty( + ty::Binder::dummy(ty.instantiate_identity()), + cx, + None, + None, + ), + items: tcx + .associated_items(impl_def_id) + .in_definition_order() + .filter(|item| !item.is_impl_trait_in_trait()) + .map(|item| clean_middle_assoc_item(item, cx)) + .collect(), + polarity: ty::ImplPolarity::Positive, + kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty( + ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()), + cx, + None, + None, + ))), + })), + }), cfg: None, inline_stmt_id: None, }); diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 7978ce6e22e..8383012885f 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -152,14 +152,8 @@ pub(crate) fn try_inline( }; cx.inlined.insert(did.into()); - let mut item = crate::clean::generate_item_with_correct_attrs( - cx, - kind, - did, - name, - import_def_id, - None, - ); + let mut item = + crate::clean::generate_item_with_correct_attrs(cx, kind, did, name, import_def_id, None); // The visibility needs to reflect the one from the reexport and not from the "source" DefId. item.inline_stmt_id = import_def_id; ret.push(item); @@ -623,7 +617,7 @@ pub(crate) fn build_impl( ImplKind::Normal }, })), - Box::new(merged_attrs), + merged_attrs, cfg, )); } @@ -673,27 +667,29 @@ fn build_module_items( let prim_ty = clean::PrimitiveType::from(p); items.push(clean::Item { name: None, - attrs: Box::default(), // 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( - item.ident.name, - clean::ImportSource { - path: clean::Path { - res, - segments: thin_vec![clean::PathSegment { - name: prim_ty.as_sym(), - args: clean::GenericArgs::AngleBracketed { - args: Default::default(), - constraints: ThinVec::new(), - }, - }], + inner: Box::new(clean::ItemInner { + attrs: Default::default(), + kind: clean::ImportItem(clean::Import::new_simple( + item.ident.name, + clean::ImportSource { + path: clean::Path { + res, + segments: thin_vec![clean::PathSegment { + name: prim_ty.as_sym(), + args: clean::GenericArgs::AngleBracketed { + args: Default::default(), + constraints: ThinVec::new(), + }, + }], + }, + did: None, }, - did: None, - }, - true, - ))), + true, + )), + }), cfg: None, inline_stmt_id: None, }); @@ -753,7 +749,8 @@ fn build_macro( LoadedMacro::MacroDef(item_def, _) => match macro_kind { MacroKind::Bang => { if let ast::ItemKind::MacroDef(ref def) = item_def.kind { - let vis = cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id)); + let vis = + cx.tcx.visibility(import_def_id.map(|d| d.to_def_id()).unwrap_or(def_id)); clean::MacroItem(clean::Macro { source: utils::display_macro_source( cx, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1dc6d820780..e47ae7df77f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -203,7 +203,7 @@ fn generate_item_with_correct_attrs( let attrs = Attributes::from_ast_iter(attrs.iter().map(|(attr, did)| (&**attr, *did)), false); let name = renamed.or(Some(name)); - let mut item = Item::from_def_id_and_attrs_and_parts(def_id, name, kind, Box::new(attrs), cfg); + let mut item = Item::from_def_id_and_attrs_and_parts(def_id, name, kind, attrs, cfg); item.inline_stmt_id = import_id; item } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 19aab211658..383efe568ae 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -320,10 +320,7 @@ pub(crate) struct Item { /// The name of this item. /// Optional because not every item has a name, e.g. impls. pub(crate) name: Option, - pub(crate) attrs: Box, - /// Information about this item that is specific to what kind of item it is. - /// E.g., struct vs enum vs function. - pub(crate) kind: Box, + pub(crate) inner: Box, pub(crate) item_id: ItemId, /// This is the `LocalDefId` of the `use` statement if the item was inlined. /// The crate metadata doesn't hold this information, so the `use` statement @@ -332,6 +329,21 @@ pub(crate) struct Item { pub(crate) cfg: Option>, } +#[derive(Clone)] +pub(crate) struct ItemInner { + /// Information about this item that is specific to what kind of item it is. + /// E.g., struct vs enum vs function. + pub(crate) kind: ItemKind, + pub(crate) attrs: Attributes, +} + +impl std::ops::Deref for Item { + type Target = ItemInner; + fn deref(&self) -> &ItemInner { + &*self.inner + } +} + /// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs. /// If you want to see the debug output for attributes and the `kind` as well, use `{:#?}` instead of `{:?}`. impl fmt::Debug for Item { @@ -391,9 +403,9 @@ pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool { } pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option { - let kind = match &*self.kind { - ItemKind::StrippedItem(k) => k, - _ => &*self.kind, + let kind = match &self.kind { + ItemKind::StrippedItem(k) => &*k, + _ => &self.kind, }; match kind { ItemKind::ModuleItem(Module { span, .. }) => Some(*span), @@ -438,7 +450,7 @@ pub(crate) fn from_def_id_and_parts( def_id, name, kind, - Box::new(Attributes::from_ast(ast_attrs)), + Attributes::from_ast(ast_attrs), ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg), ) } @@ -447,16 +459,15 @@ pub(crate) fn from_def_id_and_attrs_and_parts( def_id: DefId, name: Option, kind: ItemKind, - attrs: Box, + attrs: Attributes, cfg: Option>, ) -> Item { trace!("name={name:?}, def_id={def_id:?} cfg={cfg:?}"); Item { item_id: def_id.into(), - kind: Box::new(kind), + inner: Box::new(ItemInner { kind, attrs }), name, - attrs, cfg, inline_stmt_id: None, } @@ -524,16 +535,16 @@ pub(crate) fn is_variant(&self) -> bool { self.type_() == ItemType::Variant } pub(crate) fn is_associated_type(&self) -> bool { - matches!(&*self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..))) + matches!(self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..))) } pub(crate) fn is_ty_associated_type(&self) -> bool { - matches!(&*self.kind, TyAssocTypeItem(..) | StrippedItem(box TyAssocTypeItem(..))) + matches!(self.kind, TyAssocTypeItem(..) | StrippedItem(box TyAssocTypeItem(..))) } pub(crate) fn is_associated_const(&self) -> bool { - matches!(&*self.kind, AssocConstItem(..) | StrippedItem(box AssocConstItem(..))) + matches!(self.kind, AssocConstItem(..) | StrippedItem(box AssocConstItem(..))) } pub(crate) fn is_ty_associated_const(&self) -> bool { - matches!(&*self.kind, TyAssocConstItem(..) | StrippedItem(box TyAssocConstItem(..))) + matches!(self.kind, TyAssocConstItem(..) | StrippedItem(box TyAssocConstItem(..))) } pub(crate) fn is_method(&self) -> bool { self.type_() == ItemType::Method @@ -557,14 +568,14 @@ pub(crate) fn is_keyword(&self) -> bool { self.type_() == ItemType::Keyword } pub(crate) fn is_stripped(&self) -> bool { - match *self.kind { + match self.kind { StrippedItem(..) => true, ImportItem(ref i) => !i.should_be_displayed, _ => false, } } pub(crate) fn has_stripped_entries(&self) -> Option { - match *self.kind { + match self.kind { StructItem(ref struct_) => Some(struct_.has_stripped_entries()), UnionItem(ref union_) => Some(union_.has_stripped_entries()), EnumItem(ref enum_) => Some(enum_.has_stripped_entries()), @@ -607,7 +618,7 @@ pub(crate) fn type_(&self) -> ItemType { } pub(crate) fn is_default(&self) -> bool { - match *self.kind { + match self.kind { ItemKind::MethodItem(_, Some(defaultness)) => { defaultness.has_value() && !defaultness.is_final() } @@ -635,7 +646,7 @@ fn build_fn_header( }; hir::FnHeader { safety: sig.safety(), abi: sig.abi(), constness, asyncness } } - let header = match *self.kind { + let header = match self.kind { ItemKind::ForeignFunctionItem(_, safety) => { let def_id = self.def_id().unwrap(); let abi = tcx.fn_sig(def_id).skip_binder().abi(); @@ -674,7 +685,7 @@ pub(crate) fn visibility(&self, tcx: TyCtxt<'_>) -> Option> { ItemId::DefId(def_id) => def_id, }; - match *self.kind { + match self.kind { // 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. @@ -2561,13 +2572,13 @@ mod size_asserts { use super::*; // tidy-alphabetical-start - static_assert_size!(Crate, 64); // frequently moved by-value + static_assert_size!(Crate, 56); // frequently moved by-value static_assert_size!(DocFragment, 32); static_assert_size!(GenericArg, 32); static_assert_size!(GenericArgs, 32); static_assert_size!(GenericParamDef, 40); static_assert_size!(Generics, 16); - static_assert_size!(Item, 56); + static_assert_size!(Item, 48); static_assert_size!(ItemKind, 48); static_assert_size!(PathSegment, 40); static_assert_size!(Type, 32); diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 5686307d83d..885758c17cf 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -36,7 +36,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate { // understood by rustdoc. let mut module = clean_doc_module(&module, cx); - match *module.kind { + match module.kind { ItemKind::ModuleItem(ref module) => { for it in &module.items { // `compiler_builtins` should be masked too, but we can't apply @@ -60,7 +60,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate { let primitives = local_crate.primitives(cx.tcx); let keywords = local_crate.keywords(cx.tcx); { - let ItemKind::ModuleItem(ref mut m) = *module.kind else { unreachable!() }; + let ItemKind::ModuleItem(ref mut m) = &mut module.inner.kind else { unreachable!() }; m.items.extend(primitives.iter().map(|&(def_id, prim)| { Item::from_def_id_and_parts( def_id, @@ -281,7 +281,7 @@ pub(crate) fn build_deref_target_impls( let tcx = cx.tcx; for item in items { - let target = match *item.kind { + let target = match item.kind { ItemKind::AssocTypeItem(ref t, _) => &t.type_, _ => continue, }; diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index bf82c911f29..c25a4ddb6f3 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -1,8 +1,8 @@ use crate::clean::*; pub(crate) fn strip_item(mut item: Item) -> Item { - if !matches!(*item.kind, StrippedItem(..)) { - item.kind = Box::new(StrippedItem(item.kind)); + if !matches!(item.inner.kind, StrippedItem(..)) { + item.inner.kind = StrippedItem(Box::new(item.inner.kind)); } item } @@ -99,10 +99,10 @@ fn fold_inner_recur(&mut self, kind: ItemKind) -> ItemKind { /// don't override! fn fold_item_recur(&mut self, mut item: Item) -> Item { - item.kind = Box::new(match *item.kind { + item.inner.kind = match item.inner.kind { StrippedItem(box i) => StrippedItem(Box::new(self.fold_inner_recur(i))), - _ => self.fold_inner_recur(*item.kind), - }); + _ => self.fold_inner_recur(item.inner.kind), + }; item } diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index c5e2b33ccf8..1b3176e7918 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -216,7 +216,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option { // If this is a stripped module, // we don't want it or its children in the search index. - let orig_stripped_mod = match *item.kind { + let orig_stripped_mod = match item.kind { clean::StrippedItem(box clean::ModuleItem(..)) => { mem::replace(&mut self.cache.stripped_mod, true) } @@ -232,7 +232,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { // If the impl is from a masked crate or references something from a // masked crate then remove it completely. - if let clean::ImplItem(ref i) = *item.kind + if let clean::ImplItem(ref i) = item.kind && (self.cache.masked_crates.contains(&item.item_id.krate()) || i.trait_ .as_ref() @@ -246,9 +246,9 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { // Propagate a trait method's documentation to all implementors of the // trait. - if let clean::TraitItem(ref t) = *item.kind { + if let clean::TraitItem(ref t) = item.kind { self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| (**t).clone()); - } else if let clean::ImplItem(ref i) = *item.kind + } else if let clean::ImplItem(ref i) = item.kind && let Some(trait_) = &i.trait_ && !i.kind.is_blanket() { @@ -263,7 +263,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { // Index this method for searching later on. let search_name = if !item.is_stripped() { item.name.or_else(|| { - if let clean::ImportItem(ref i) = *item.kind + if let clean::ImportItem(ref i) = item.kind && let clean::ImportKind::Simple(s) = i.kind { Some(s) @@ -287,7 +287,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { _ => false, }; - match *item.kind { + match item.kind { clean::StructItem(..) | clean::EnumItem(..) | clean::TypeAliasItem(..) @@ -350,7 +350,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { } // Maintain the parent stack. - let (item, parent_pushed) = match *item.kind { + let (item, parent_pushed) = match item.kind { clean::TraitItem(..) | clean::EnumItem(..) | clean::ForeignTypeItem @@ -367,7 +367,11 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { // Once we've recursively found all the generics, hoard off all the // implementations elsewhere. - let ret = if let clean::Item { kind: box clean::ImplItem(ref i), .. } = item { + let ret = if let clean::Item { + inner: box clean::ItemInner { kind: clean::ImplItem(ref i), .. }, + .. + } = item + { // Figure out the id of this impl. This may map to a // primitive rather than always to a struct/enum. // Note: matching twice to restrict the lifetime of the `i` borrow. @@ -436,7 +440,7 @@ fn is_from_private_dep(tcx: TyCtxt<'_>, cache: &Cache, def_id: DefId) -> bool { fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::Item, name: Symbol) { // Item has a name, so it must also have a DefId (can't be an impl, let alone a blanket or auto impl). let item_def_id = item.item_id.as_def_id().unwrap(); - let (parent_did, parent_path) = match *item.kind { + let (parent_did, parent_path) = match item.kind { clean::StrippedItem(..) => return, clean::AssocConstItem(..) | clean::AssocTypeItem(..) if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) => @@ -528,7 +532,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It // - It's either an inline, or a true re-export // - It's got the same name // - Both of them have the same exact path - let defid = match &*item.kind { + let defid = match &item.kind { clean::ItemKind::ImportItem(import) => import.source.did.unwrap_or(item_def_id), _ => item_def_id, }; @@ -605,7 +609,7 @@ enum ParentStackItem { impl ParentStackItem { fn new(item: &clean::Item) -> Self { - match &*item.kind { + match &item.kind { clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => { ParentStackItem::Impl { for_: for_.clone(), diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index 9754e1e6f74..383e3135faa 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -70,7 +70,7 @@ fn serialize(&self, serializer: S) -> Result impl<'a> From<&'a clean::Item> for ItemType { fn from(item: &'a clean::Item) -> ItemType { - let kind = match *item.kind { + let kind = match item.kind { clean::StrippedItem(box ref item) => item, ref kind => kind, }; diff --git a/src/librustdoc/formats/mod.rs b/src/librustdoc/formats/mod.rs index 84adca8efa9..0bdea36043c 100644 --- a/src/librustdoc/formats/mod.rs +++ b/src/librustdoc/formats/mod.rs @@ -16,7 +16,7 @@ pub(crate) struct Impl { impl Impl { pub(crate) fn inner_impl(&self) -> &clean::Impl { - match *self.impl_item.kind { + match self.impl_item.kind { clean::ImplItem(ref impl_) => impl_, _ => panic!("non-impl item found in impl"), } diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index cc57dca86c3..edd7d56b179 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -77,7 +77,7 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>( cx.mod_item_in(&item)?; let (clean::StrippedItem(box clean::ModuleItem(module)) | clean::ModuleItem(module)) = - *item.kind + item.inner.kind else { unreachable!() }; diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 9fe43e428f2..58a228b74fc 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -800,7 +800,7 @@ fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> { // Render sidebar-items.js used throughout this module. if !self.render_redirect_pages { let (clean::StrippedItem(box clean::ModuleItem(ref module)) - | clean::ModuleItem(ref module)) = *item.kind + | clean::ModuleItem(ref module)) = item.kind else { unreachable!() }; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index f67d006116c..3b8eda08372 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -620,7 +620,7 @@ fn document_full_inner<'a, 'cx: 'a>( } } - let kind = match &*item.kind { + let kind = match &item.kind { clean::ItemKind::StrippedItem(box kind) | kind => kind, }; @@ -1072,7 +1072,7 @@ fn render_assoc_item( cx: &mut Context<'_>, render_mode: RenderMode, ) { - match &*item.kind { + match &item.kind { clean::StrippedItem(..) => {} clean::TyMethodItem(m) => { assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode) @@ -1350,7 +1350,7 @@ fn render_deref_methods( .inner_impl() .items .iter() - .find_map(|item| match *item.kind { + .find_map(|item| match item.kind { clean::AssocTypeItem(box ref t, _) => Some(match *t { clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), @@ -1381,7 +1381,7 @@ fn render_deref_methods( } fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) -> bool { - let self_type_opt = match *item.kind { + let self_type_opt = match item.kind { clean::MethodItem(ref method, _) => method.decl.receiver_type(), clean::TyMethodItem(ref method) => method.decl.receiver_type(), _ => None, @@ -1491,7 +1491,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { write!(&mut out, "
{}
", impl_.print(false, cx)); for it in &impl_.items { - if let clean::AssocTypeItem(ref tydef, ref _bounds) = *it.kind { + if let clean::AssocTypeItem(ref tydef, ref _bounds) = it.kind { out.push_str("
"); let empty_set = FxHashSet::default(); let src_link = AssocItemLink::GotoSource(trait_did.into(), &empty_set); @@ -1659,7 +1659,7 @@ fn doc_impl_item( let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" }; write!(w, "
"); } - match &*item.kind { + match &item.kind { clean::MethodItem(..) | clean::TyMethodItem(_) => { // Only render when the method is not static or we allow static methods if render_method_item { @@ -1690,7 +1690,7 @@ fn doc_impl_item( w.write_str(""); } } - clean::TyAssocConstItem(generics, ty) => { + clean::TyAssocConstItem(ref generics, ref ty) => { let source_id = format!("{item_type}.{name}"); let id = cx.derive_id(&source_id); write!(w, "
"); @@ -1734,7 +1734,7 @@ fn doc_impl_item( ); w.write_str("
"); } - clean::TyAssocTypeItem(generics, bounds) => { + clean::TyAssocTypeItem(ref generics, ref bounds) => { let source_id = format!("{item_type}.{name}"); let id = cx.derive_id(&source_id); write!(w, "
"); @@ -1808,7 +1808,7 @@ fn doc_impl_item( if !impl_.is_negative_trait_impl() { for trait_item in &impl_.items { - match *trait_item.kind { + match trait_item.kind { clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item), clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => { assoc_types.push(trait_item) @@ -2051,7 +2051,7 @@ pub(crate) fn render_impl_summary( write!(w, "{}", inner_impl.print(use_absolute, cx)); if show_def_docs { for it in &inner_impl.items { - if let clean::AssocTypeItem(ref tydef, ref _bounds) = *it.kind { + if let clean::AssocTypeItem(ref tydef, ref _bounds) = it.kind { w.write_str("
"); assoc_type( w, @@ -2172,7 +2172,7 @@ fn get_id_for_impl<'tcx>(tcx: TyCtxt<'tcx>, impl_id: ItemId) -> String { } fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String, String)> { - match *item.kind { + match item.kind { clean::ItemKind::ImplItem(ref i) if i.trait_.is_some() => { // Alternative format produces no URLs, // so this parameter does nothing. diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index cda5409a460..52e25152770 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -178,7 +178,7 @@ fn print_where_clause_and_check<'a, 'tcx: 'a>( pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buffer) { debug_assert!(!item.is_stripped()); - let typ = match *item.kind { + let typ = match item.kind { clean::ModuleItem(_) => { if item.is_crate() { "Crate " @@ -252,7 +252,7 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf item_vars.render_into(buf).unwrap(); - match &*item.kind { + match &item.kind { clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items), clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f, _) => { item_function(buf, cx, item, f) @@ -411,7 +411,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, tcx: TyCtxt<'_>) -> Ordering { ); } - match *myitem.kind { + match myitem.kind { clean::ExternCrateItem { ref src } => { use crate::html::format::anchor; @@ -477,7 +477,7 @@ fn cmp(i1: &clean::Item, i2: &clean::Item, tcx: TyCtxt<'_>) -> Ordering { continue; } - let unsafety_flag = match *myitem.kind { + let unsafety_flag = match myitem.kind { clean::FunctionItem(_) | clean::ForeignFunctionItem(..) if myitem.fn_header(tcx).unwrap().safety == hir::Safety::Unsafe => { @@ -1439,7 +1439,7 @@ fn fields_iter( self.s .fields .iter() - .filter_map(|f| match *f.kind { + .filter_map(|f| match f.kind { clean::StructFieldItem(ref ty) => Some((f, ty)), _ => None, }) @@ -1457,7 +1457,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>( display_fn(|f| { if !s.is_empty() && s.iter().all(|field| { - matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) + matches!(field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) }) { return f.write_str("/* private fields */"); @@ -1467,7 +1467,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>( if i > 0 { f.write_str(", ")?; } - match *ty.kind { + match ty.kind { clean::StrippedItem(box clean::StructFieldItem(_)) => f.write_str("_")?, clean::StructFieldItem(ref ty) => write!(f, "{}", ty.print(cx))?, _ => unreachable!(), @@ -1521,7 +1521,7 @@ fn should_show_enum_discriminant( ) -> bool { let mut has_variants_with_value = false; for variant in variants { - if let clean::VariantItem(ref var) = *variant.kind + if let clean::VariantItem(ref var) = variant.kind && matches!(var.kind, clean::VariantKind::CLike) { has_variants_with_value |= var.discriminant.is_some(); @@ -1592,7 +1592,7 @@ fn render_enum_fields( continue; } w.write_str(TAB); - match *v.kind { + match v.kind { clean::VariantItem(ref var) => match var.kind { clean::VariantKind::CLike => display_c_like_variant( w, @@ -1659,7 +1659,7 @@ fn item_variants( " rightside", ); w.write_str("

"); - if let clean::VariantItem(ref var) = *variant.kind + if let clean::VariantItem(ref var) = variant.kind && let clean::VariantKind::CLike = var.kind { display_c_like_variant( @@ -1675,7 +1675,7 @@ fn item_variants( w.write_str(variant.name.unwrap().as_str()); } - let clean::VariantItem(variant_data) = &*variant.kind else { unreachable!() }; + let clean::VariantItem(variant_data) = &variant.kind else { unreachable!() }; if let clean::VariantKind::Tuple(ref s) = variant_data.kind { write!(w, "({})", print_tuple_struct_fields(cx, s)); @@ -1716,7 +1716,7 @@ fn item_variants( document_non_exhaustive(variant) ); for field in fields { - match *field.kind { + match field.kind { clean::StrippedItem(box clean::StructFieldItem(_)) => {} clean::StructFieldItem(ref ty) => { let id = cx.derive_id(format!( @@ -1886,7 +1886,7 @@ fn item_fields( ) { let mut fields = fields .iter() - .filter_map(|f| match *f.kind { + .filter_map(|f| match f.kind { clean::StructFieldItem(ref ty) => Some((f, ty)), _ => None, }) @@ -2196,14 +2196,14 @@ fn render_union<'a, 'cx: 'a>( write!(f, "{{\n")?; let count_fields = - fields.iter().filter(|field| matches!(*field.kind, clean::StructFieldItem(..))).count(); + fields.iter().filter(|field| matches!(field.kind, clean::StructFieldItem(..))).count(); let toggle = should_hide_fields(count_fields); if toggle { toggle_open(&mut f, format_args!("{count_fields} fields")); } for field in fields { - if let clean::StructFieldItem(ref ty) = *field.kind { + if let clean::StructFieldItem(ref ty) = field.kind { write!( f, " {}{}: {},\n", @@ -2279,14 +2279,14 @@ fn render_struct_fields( w.write_str("{"); } let count_fields = - fields.iter().filter(|f| matches!(*f.kind, clean::StructFieldItem(..))).count(); + fields.iter().filter(|f| matches!(f.kind, clean::StructFieldItem(..))).count(); let has_visible_fields = count_fields > 0; let toggle = should_hide_fields(count_fields); if toggle { toggle_open(&mut w, format_args!("{count_fields} fields")); } for field in fields { - if let clean::StructFieldItem(ref ty) = *field.kind { + if let clean::StructFieldItem(ref ty) = field.kind { write!( w, "\n{tab} {vis}{name}: {ty},", @@ -2314,7 +2314,7 @@ fn render_struct_fields( w.write_str("("); if !fields.is_empty() && fields.iter().all(|field| { - matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) + matches!(field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) }) { write!(w, "/* private fields */"); @@ -2323,7 +2323,7 @@ fn render_struct_fields( if i > 0 { w.write_str(", "); } - match *field.kind { + match field.kind { clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"), clean::StructFieldItem(ref ty) => { write!(w, "{}{}", visibility_print_with_space(field, cx), ty.print(cx),) diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index bfdf457c529..b84c22ac746 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -758,7 +758,7 @@ pub(crate) fn get_function_type_for_search<'tcx>( None } }); - let (mut inputs, mut output, where_clause) = match *item.kind { + let (mut inputs, mut output, where_clause) = match item.kind { clean::FunctionItem(ref f) | clean::MethodItem(ref f, _) | clean::TyMethodItem(ref f) => { get_fn_inputs_and_outputs(f, tcx, impl_or_trait_generics, cache) } @@ -1132,7 +1132,7 @@ fn simplify_fn_type<'tcx, 'a>( && trait_.items.iter().any(|at| at.is_ty_associated_type()) { for assoc_ty in &trait_.items { - if let clean::ItemKind::TyAssocTypeItem(_generics, bounds) = &*assoc_ty.kind + if let clean::ItemKind::TyAssocTypeItem(_generics, bounds) = &assoc_ty.kind && let Some(name) = assoc_ty.name { let idx = -isize::try_from(rgen.len() + 1).unwrap(); diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 06cc57b2a55..842ee81624e 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -119,7 +119,7 @@ pub(crate) fn wrapped(v: T) -> rinja::Result> pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { let mut ids = IdMap::new(); let mut blocks: Vec> = docblock_toc(cx, it, &mut ids).into_iter().collect(); - match *it.kind { + match it.kind { clean::StructItem(ref s) => sidebar_struct(cx, it, s, &mut blocks), clean::TraitItem(ref t) => sidebar_trait(cx, it, t, &mut blocks), clean::PrimitiveItem(_) => sidebar_primitive(cx, it, &mut blocks), @@ -143,7 +143,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf // crate title is displayed as part of logo lockup let (title_prefix, title) = if !blocks.is_empty() && !it.is_crate() { ( - match *it.kind { + match it.kind { clean::ModuleItem(..) => "Module ", _ => "", }, @@ -181,7 +181,7 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buf fn get_struct_fields_name<'a>(fields: &'a [clean::Item]) -> Vec> { let mut fields = fields .iter() - .filter(|f| matches!(*f.kind, clean::StructFieldItem(..))) + .filter(|f| matches!(f.kind, clean::StructFieldItem(..))) .filter_map(|f| { f.name.as_ref().map(|name| Link::new(format!("structfield.{name}"), name.as_str())) }) @@ -467,7 +467,7 @@ fn sidebar_deref_methods<'a>( debug!("found Deref: {impl_:?}"); if let Some((target, real_target)) = - impl_.inner_impl().items.iter().find_map(|item| match *item.kind { + impl_.inner_impl().items.iter().find_map(|item| match item.kind { clean::AssocTypeItem(box ref t, _) => Some(match *t { clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), @@ -587,7 +587,7 @@ fn sidebar_module( && it .name .or_else(|| { - if let clean::ImportItem(ref i) = *it.kind + if let clean::ImportItem(ref i) = it.kind && let clean::ImportKind::Simple(s) = i.kind { Some(s) diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index b0af8d8c23e..e8d12320f82 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -783,7 +783,7 @@ impl<'cx, 'cache> DocVisitor for TypeImplCollector<'cx, 'cache> { fn visit_item(&mut self, it: &Item) { self.visit_item_recur(it); let cache = self.cache; - let ItemKind::TypeAliasItem(ref t) = *it.kind else { return }; + let ItemKind::TypeAliasItem(ref t) = it.kind else { return }; let Some(self_did) = it.item_id.as_def_id() else { return }; if !self.visited_aliases.insert(self_did) { return; diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b97d710c007..cae8d107da4 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -49,7 +49,7 @@ pub(super) fn convert_item(&self, item: clean::Item) -> Option { let visibility = item.visibility(self.tcx); let clean::Item { name, item_id, .. } = item; let id = id_from_item(&item, self.tcx); - let inner = match *item.kind { + let inner = match item.kind { clean::KeywordItem => return None, clean::StrippedItem(ref inner) => { match &**inner { @@ -294,7 +294,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { } pub(crate) fn id_from_item(item: &clean::Item, tcx: TyCtxt<'_>) -> Id { - match *item.kind { + match item.kind { clean::ItemKind::ImportItem(ref import) => { let extra = import.source.did.map(ItemId::from).map(|i| id_from_item_inner(i, tcx, None, None)); @@ -310,7 +310,7 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum { let is_crate = item.is_crate(); let header = item.fn_header(tcx); - match *item.kind { + match item.inner.kind { ModuleItem(m) => { ItemEnum::Module(Module { is_crate, items: ids(m.items, tcx), is_stripped: false }) } diff --git a/src/librustdoc/json/import_finder.rs b/src/librustdoc/json/import_finder.rs index 976a7fd69ae..e21fe9668d4 100644 --- a/src/librustdoc/json/import_finder.rs +++ b/src/librustdoc/json/import_finder.rs @@ -24,7 +24,7 @@ struct ImportFinder { impl DocFolder for ImportFinder { fn fold_item(&mut self, i: Item) -> Option { - match *i.kind { + match i.kind { clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => { self.imported.insert(did); Some(i) diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 1b2d61a7637..d375946a8c8 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -85,7 +85,7 @@ fn get_impls(&mut self, id: DefId) -> Vec { // document primitive items in an arbitrary crate by using // `rustc_doc_primitive`. let mut is_primitive_impl = false; - if let clean::types::ItemKind::ImplItem(ref impl_) = *item.kind + if let clean::types::ItemKind::ImplItem(ref impl_) = item.kind && impl_.trait_.is_none() && let clean::types::Type::Primitive(_) = impl_.for_ { @@ -164,7 +164,7 @@ fn item(&mut self, item: clean::Item) -> Result<(), Error> { // Flatten items that recursively store other items. We include orphaned items from // stripped modules and etc that are otherwise reachable. - if let ItemKind::StrippedItem(inner) = &*item.kind { + if let ItemKind::StrippedItem(inner) = &item.kind { inner.inner_items().for_each(|i| self.item(i.clone()).unwrap()); } diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs index 1d0b41fc429..7391909406e 100644 --- a/src/librustdoc/passes/calculate_doc_coverage.rs +++ b/src/librustdoc/passes/calculate_doc_coverage.rs @@ -195,7 +195,7 @@ fn visit_item(&mut self, i: &clean::Item) { return; } - match *i.kind { + match i.kind { clean::StrippedItem(..) => { // don't count items in stripped modules return; diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs index d456e8e24e6..733fd919e71 100644 --- a/src/librustdoc/passes/check_doc_test_visibility.rs +++ b/src/librustdoc/passes/check_doc_test_visibility.rs @@ -57,7 +57,7 @@ fn visit_test(&mut self, _: String, config: LangString, _: MdRelLine) { pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool { if !cx.cache.effective_visibilities.is_directly_public(cx.tcx, item.item_id.expect_def_id()) || matches!( - *item.kind, + item.kind, clean::StructFieldItem(_) | clean::VariantItem(_) | clean::AssocConstItem(..) diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 394a64df4bc..a9edc485d5e 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -160,13 +160,13 @@ fn add_deref_target( // scan through included items ahead of time to splice in Deref targets to the "valid" sets for it in new_items_external.iter().chain(new_items_local.iter()) { - if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind + if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = it.kind && trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() && cleaner.keep_impl(for_, true) { let target = items .iter() - .find_map(|item| match *item.kind { + .find_map(|item| match item.kind { AssocTypeItem(ref t, _) => Some(&t.type_), _ => None, }) @@ -200,7 +200,7 @@ fn add_deref_target( // Filter out external items that are not needed new_items_external.retain(|it| { - if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind { + if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = it.kind { cleaner.keep_impl( for_, trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(), @@ -211,7 +211,7 @@ fn add_deref_target( } }); - if let ModuleItem(Module { items, .. }) = &mut *krate.module.kind { + if let ModuleItem(Module { items, .. }) = &mut krate.module.inner.kind { items.extend(synth_impls); items.extend(new_items_external); items.extend(new_items_local); @@ -258,7 +258,7 @@ impl<'cache> DocVisitor for ItemAndAliasCollector<'cache> { fn visit_item(&mut self, i: &Item) { self.items.insert(i.item_id); - if let TypeAliasItem(alias) = &*i.kind + if let TypeAliasItem(alias) = &i.inner.kind && let Some(did) = alias.type_.def_id(self.cache) { self.items.insert(ItemId::DefId(did)); diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs index 5aa6a5ee604..6be51dd1560 100644 --- a/src/librustdoc/passes/propagate_doc_cfg.rs +++ b/src/librustdoc/passes/propagate_doc_cfg.rs @@ -31,7 +31,7 @@ impl<'a, 'tcx> CfgPropagator<'a, 'tcx> { // Some items need to merge their attributes with their parents' otherwise a few of them // (mostly `cfg` ones) will be missing. fn merge_with_parent_attributes(&mut self, item: &mut Item) { - let check_parent = match &*item.kind { + let check_parent = match &item.kind { // impl blocks can be in different modules with different cfg and we need to get them // as well. ItemKind::ImplItem(_) => false, diff --git a/src/librustdoc/passes/strip_aliased_non_local.rs b/src/librustdoc/passes/strip_aliased_non_local.rs index e1dd2d3af0f..6078ab36528 100644 --- a/src/librustdoc/passes/strip_aliased_non_local.rs +++ b/src/librustdoc/passes/strip_aliased_non_local.rs @@ -23,7 +23,7 @@ struct AliasedNonLocalStripper<'tcx> { impl<'tcx> DocFolder for AliasedNonLocalStripper<'tcx> { fn fold_item(&mut self, i: Item) -> Option { - Some(match *i.kind { + Some(match i.kind { clean::TypeAliasItem(..) => { let mut stripper = NonLocalStripper { tcx: self.tcx }; // don't call `fold_item` as that could strip the type-alias it-self diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index 86f14ddbe85..7c5fbac94e4 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -89,7 +89,7 @@ fn recurse_in_impl_or_exported_macro(&mut self, i: Item) -> Item { impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { fn fold_item(&mut self, i: Item) -> Option { let has_doc_hidden = i.is_doc_hidden(); - let is_impl_or_exported_macro = match *i.kind { + let is_impl_or_exported_macro = match i.kind { clean::ImplItem(..) => true, // If the macro has the `#[macro_export]` attribute, it means it's accessible at the // crate level so it should be handled differently. @@ -138,7 +138,7 @@ fn fold_item(&mut self, i: Item) -> Option { // module it's defined in. Both of these are marked "stripped," and // not included in the final docs, but since they still have an effect // on the final doc, cannot be completely removed from the Clean IR. - match *i.kind { + match i.kind { clean::StructFieldItem(..) | clean::ModuleItem(..) | clean::VariantItem(..) => { // We need to recurse into stripped modules to // strip things like impl methods but when doing so diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 3f706ac951f..a85428f8742 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -39,7 +39,7 @@ fn is_item_reachable( impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { fn fold_item(&mut self, i: Item) -> Option { - match *i.kind { + match i.kind { clean::StrippedItem(..) => { // We need to recurse into stripped modules to strip things // like impl methods but when doing so we must not add any @@ -130,7 +130,7 @@ fn fold_item(&mut self, i: Item) -> Option { clean::KeywordItem => {} } - let fastreturn = match *i.kind { + let fastreturn = match i.kind { // nothing left to do for traits (don't want to filter their // methods out, visibility controlled by the trait) clean::TraitItem(..) => true, @@ -195,7 +195,7 @@ fn should_keep_impl(&self, item: &Item, for_def_id: DefId) -> bool { impl<'a> DocFolder for ImplStripper<'a, '_> { fn fold_item(&mut self, i: Item) -> Option { - if let clean::ImplItem(ref imp) = *i.kind { + if let clean::ImplItem(ref imp) = i.kind { // Impl blocks can be skipped if they are: empty; not a trait impl; and have no // documentation. // @@ -272,7 +272,7 @@ fn import_should_be_hidden(&self, i: &Item, imp: &clean::Import) -> bool { impl<'tcx> DocFolder for ImportStripper<'tcx> { fn fold_item(&mut self, i: Item) -> Option { - match *i.kind { + match &i.kind { clean::ImportItem(imp) if !self.document_hidden && self.import_should_be_hidden(&i, &imp) => { diff --git a/src/librustdoc/visit.rs b/src/librustdoc/visit.rs index 430bbe991ea..7fb0a32cc94 100644 --- a/src/librustdoc/visit.rs +++ b/src/librustdoc/visit.rs @@ -48,8 +48,8 @@ fn visit_inner_recur(&mut self, kind: &ItemKind) { /// don't override! fn visit_item_recur(&mut self, item: &Item) { - match &*item.kind { - StrippedItem(i) => self.visit_inner_recur(i), + match &item.kind { + StrippedItem(i) => self.visit_inner_recur(&*i), _ => self.visit_inner_recur(&item.kind), } }