Auto merge of #129789 - notriddle:notriddle/inline-stmt-local, r=GuillaumeGomez

rustdoc: use strategic boxing to shrink `clean::Item`

* `inline_stmt_id` is never a cross-crate DefId, so save space by not storing it.
* Instead of two inner boxes for `Item`, use one.
This commit is contained in:
bors 2024-09-09 23:16:56 +00:00
commit 712463de61
28 changed files with 215 additions and 197 deletions

View File

@ -115,17 +115,19 @@ fn synthesize_auto_trait_impl<'tcx>(
Some(clean::Item { Some(clean::Item {
name: None, 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 }, 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, cfg: None,
inline_stmt_id: None, inline_stmt_id: None,
}) })

View File

@ -84,42 +84,44 @@ pub(crate) fn synthesize_blanket_impls(
blanket_impls.push(clean::Item { blanket_impls.push(clean::Item {
name: None, name: None,
attrs: Default::default(),
item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: Box::new(clean::ImplItem(Box::new(clean::Impl { inner: Box::new(clean::ItemInner {
safety: hir::Safety::Safe, attrs: Default::default(),
generics: clean_ty_generics( kind: clean::ImplItem(Box::new(clean::Impl {
cx, safety: hir::Safety::Safe,
tcx.generics_of(impl_def_id), generics: clean_ty_generics(
tcx.explicit_predicates_of(impl_def_id), cx,
), tcx.generics_of(impl_def_id),
// FIXME(eddyb) compute both `trait_` and `for_` from tcx.explicit_predicates_of(impl_def_id),
// the post-inference `trait_ref`, as it's more accurate. ),
trait_: Some(clean_trait_ref_with_constraints( // FIXME(eddyb) compute both `trait_` and `for_` from
cx, // the post-inference `trait_ref`, as it's more accurate.
ty::Binder::dummy(trait_ref.instantiate_identity()), trait_: Some(clean_trait_ref_with_constraints(
ThinVec::new(), cx,
)), ty::Binder::dummy(trait_ref.instantiate_identity()),
for_: clean_middle_ty( ThinVec::new(),
ty::Binder::dummy(ty.instantiate_identity()), )),
cx, for_: clean_middle_ty(
None, ty::Binder::dummy(ty.instantiate_identity()),
None, cx,
), None,
items: tcx None,
.associated_items(impl_def_id) ),
.in_definition_order() items: tcx
.filter(|item| !item.is_impl_trait_in_trait()) .associated_items(impl_def_id)
.map(|item| clean_middle_assoc_item(item, cx)) .in_definition_order()
.collect(), .filter(|item| !item.is_impl_trait_in_trait())
polarity: ty::ImplPolarity::Positive, .map(|item| clean_middle_assoc_item(item, cx))
kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty( .collect(),
ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()), polarity: ty::ImplPolarity::Positive,
cx, kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty(
None, ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
None, cx,
))), None,
}))), None,
))),
})),
}),
cfg: None, cfg: None,
inline_stmt_id: None, inline_stmt_id: None,
}); });

View File

@ -5,7 +5,7 @@ use std::sync::Arc;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, DefIdSet, LocalModDefId}; use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModDefId};
use rustc_hir::Mutability; use rustc_hir::Mutability;
use rustc_metadata::creader::{CStore, LoadedMacro}; use rustc_metadata::creader::{CStore, LoadedMacro};
use rustc_middle::ty::fast_reject::SimplifiedType; use rustc_middle::ty::fast_reject::SimplifiedType;
@ -43,7 +43,7 @@ pub(crate) fn try_inline(
cx: &mut DocContext<'_>, cx: &mut DocContext<'_>,
res: Res, res: Res,
name: Symbol, name: Symbol,
attrs: Option<(&[ast::Attribute], Option<DefId>)>, attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
visited: &mut DefIdSet, visited: &mut DefIdSet,
) -> Option<Vec<clean::Item>> { ) -> Option<Vec<clean::Item>> {
let did = res.opt_def_id()?; let did = res.opt_def_id()?;
@ -152,14 +152,8 @@ pub(crate) fn try_inline(
}; };
cx.inlined.insert(did.into()); cx.inlined.insert(did.into());
let mut item = crate::clean::generate_item_with_correct_attrs( let mut item =
cx, crate::clean::generate_item_with_correct_attrs(cx, kind, did, name, import_def_id, None);
kind,
did,
name,
import_def_id.and_then(|def_id| def_id.as_local()),
None,
);
// The visibility needs to reflect the one from the reexport and not from the "source" DefId. // The visibility needs to reflect the one from the reexport and not from the "source" DefId.
item.inline_stmt_id = import_def_id; item.inline_stmt_id = import_def_id;
ret.push(item); ret.push(item);
@ -198,7 +192,7 @@ pub(crate) fn try_inline_glob(
visited, visited,
inlined_names, inlined_names,
Some(&reexports), Some(&reexports),
Some((attrs, Some(import.owner_id.def_id.to_def_id()))), Some((attrs, Some(import.owner_id.def_id))),
); );
items.retain(|item| { items.retain(|item| {
if let Some(name) = item.name { if let Some(name) = item.name {
@ -372,7 +366,7 @@ fn build_type_alias(
pub(crate) fn build_impls( pub(crate) fn build_impls(
cx: &mut DocContext<'_>, cx: &mut DocContext<'_>,
did: DefId, did: DefId,
attrs: Option<(&[ast::Attribute], Option<DefId>)>, attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
ret: &mut Vec<clean::Item>, ret: &mut Vec<clean::Item>,
) { ) {
let _prof_timer = cx.tcx.sess.prof.generic_activity("build_inherent_impls"); let _prof_timer = cx.tcx.sess.prof.generic_activity("build_inherent_impls");
@ -405,7 +399,7 @@ pub(crate) fn build_impls(
pub(crate) fn merge_attrs( pub(crate) fn merge_attrs(
cx: &mut DocContext<'_>, cx: &mut DocContext<'_>,
old_attrs: &[ast::Attribute], old_attrs: &[ast::Attribute],
new_attrs: Option<(&[ast::Attribute], Option<DefId>)>, new_attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
) -> (clean::Attributes, Option<Arc<clean::cfg::Cfg>>) { ) -> (clean::Attributes, Option<Arc<clean::cfg::Cfg>>) {
// NOTE: If we have additional attributes (from a re-export), // NOTE: If we have additional attributes (from a re-export),
// always insert them first. This ensure that re-export // always insert them first. This ensure that re-export
@ -416,7 +410,7 @@ pub(crate) fn merge_attrs(
both.extend_from_slice(old_attrs); both.extend_from_slice(old_attrs);
( (
if let Some(item_id) = item_id { if let Some(item_id) = item_id {
Attributes::from_ast_with_additional(old_attrs, (inner, item_id)) Attributes::from_ast_with_additional(old_attrs, (inner, item_id.to_def_id()))
} else { } else {
Attributes::from_ast(&both) Attributes::from_ast(&both)
}, },
@ -431,7 +425,7 @@ pub(crate) fn merge_attrs(
pub(crate) fn build_impl( pub(crate) fn build_impl(
cx: &mut DocContext<'_>, cx: &mut DocContext<'_>,
did: DefId, did: DefId,
attrs: Option<(&[ast::Attribute], Option<DefId>)>, attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
ret: &mut Vec<clean::Item>, ret: &mut Vec<clean::Item>,
) { ) {
if !cx.inlined.insert(did.into()) { if !cx.inlined.insert(did.into()) {
@ -623,7 +617,7 @@ pub(crate) fn build_impl(
ImplKind::Normal ImplKind::Normal
}, },
})), })),
Box::new(merged_attrs), merged_attrs,
cfg, cfg,
)); ));
} }
@ -641,7 +635,7 @@ fn build_module_items(
visited: &mut DefIdSet, visited: &mut DefIdSet,
inlined_names: &mut FxHashSet<(ItemType, Symbol)>, inlined_names: &mut FxHashSet<(ItemType, Symbol)>,
allowed_def_ids: Option<&DefIdSet>, allowed_def_ids: Option<&DefIdSet>,
attrs: Option<(&[ast::Attribute], Option<DefId>)>, attrs: Option<(&[ast::Attribute], Option<LocalDefId>)>,
) -> Vec<clean::Item> { ) -> Vec<clean::Item> {
let mut items = Vec::new(); let mut items = Vec::new();
@ -673,27 +667,29 @@ fn build_module_items(
let prim_ty = clean::PrimitiveType::from(p); let prim_ty = clean::PrimitiveType::from(p);
items.push(clean::Item { items.push(clean::Item {
name: None, name: None,
attrs: Box::default(),
// We can use the item's `DefId` directly since the only information ever used // We can use the item's `DefId` directly since the only information ever used
// from it is `DefId.krate`. // from it is `DefId.krate`.
item_id: ItemId::DefId(did), item_id: ItemId::DefId(did),
kind: Box::new(clean::ImportItem(clean::Import::new_simple( inner: Box::new(clean::ItemInner {
item.ident.name, attrs: Default::default(),
clean::ImportSource { kind: clean::ImportItem(clean::Import::new_simple(
path: clean::Path { item.ident.name,
res, clean::ImportSource {
segments: thin_vec![clean::PathSegment { path: clean::Path {
name: prim_ty.as_sym(), res,
args: clean::GenericArgs::AngleBracketed { segments: thin_vec![clean::PathSegment {
args: Default::default(), name: prim_ty.as_sym(),
constraints: ThinVec::new(), args: clean::GenericArgs::AngleBracketed {
}, args: Default::default(),
}], constraints: ThinVec::new(),
},
}],
},
did: None,
}, },
did: None, true,
}, )),
true, }),
))),
cfg: None, cfg: None,
inline_stmt_id: None, inline_stmt_id: None,
}); });
@ -745,7 +741,7 @@ fn build_macro(
cx: &mut DocContext<'_>, cx: &mut DocContext<'_>,
def_id: DefId, def_id: DefId,
name: Symbol, name: Symbol,
import_def_id: Option<DefId>, import_def_id: Option<LocalDefId>,
macro_kind: MacroKind, macro_kind: MacroKind,
is_doc_hidden: bool, is_doc_hidden: bool,
) -> clean::ItemKind { ) -> clean::ItemKind {
@ -753,7 +749,8 @@ fn build_macro(
LoadedMacro::MacroDef(item_def, _) => match macro_kind { LoadedMacro::MacroDef(item_def, _) => match macro_kind {
MacroKind::Bang => { MacroKind::Bang => {
if let ast::ItemKind::MacroDef(ref def) = item_def.kind { if let ast::ItemKind::MacroDef(ref def) = item_def.kind {
let vis = cx.tcx.visibility(import_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 { clean::MacroItem(clean::Macro {
source: utils::display_macro_source( source: utils::display_macro_source(
cx, cx,

View File

@ -203,8 +203,8 @@ fn generate_item_with_correct_attrs(
let attrs = Attributes::from_ast_iter(attrs.iter().map(|(attr, did)| (&**attr, *did)), false); let attrs = Attributes::from_ast_iter(attrs.iter().map(|(attr, did)| (&**attr, *did)), false);
let name = renamed.or(Some(name)); 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.map(|local| local.to_def_id()); item.inline_stmt_id = import_id;
item item
} }
@ -2927,7 +2927,7 @@ fn clean_extern_crate<'tcx>(
}) })
&& !cx.output_format.is_json(); && !cx.output_format.is_json();
let krate_owner_def_id = krate.owner_id.to_def_id(); let krate_owner_def_id = krate.owner_id.def_id;
if please_inline { if please_inline {
if let Some(items) = inline::try_inline( if let Some(items) = inline::try_inline(
cx, cx,
@ -2941,7 +2941,7 @@ fn clean_extern_crate<'tcx>(
} }
vec![Item::from_def_id_and_parts( vec![Item::from_def_id_and_parts(
krate_owner_def_id, krate_owner_def_id.to_def_id(),
Some(name), Some(name),
ExternCrateItem { src: orig_name }, ExternCrateItem { src: orig_name },
cx, cx,
@ -2988,7 +2988,7 @@ fn clean_use_statement_inner<'tcx>(
let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline); let inline_attr = attrs.lists(sym::doc).get_word_attr(sym::inline);
let pub_underscore = visibility.is_public() && name == kw::Underscore; let pub_underscore = visibility.is_public() && name == kw::Underscore;
let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id); let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id);
let import_def_id = import.owner_id.def_id.to_def_id(); let import_def_id = import.owner_id.def_id;
// The parent of the module in which this import resides. This // The parent of the module in which this import resides. This
// is the same as `current_mod` if that's already the top // is the same as `current_mod` if that's already the top
@ -3071,7 +3071,7 @@ fn clean_use_statement_inner<'tcx>(
) )
{ {
items.push(Item::from_def_id_and_parts( items.push(Item::from_def_id_and_parts(
import_def_id, import_def_id.to_def_id(),
None, None,
ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)), ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)),
cx, cx,
@ -3081,7 +3081,7 @@ fn clean_use_statement_inner<'tcx>(
Import::new_simple(name, resolve_use_source(cx, path), true) Import::new_simple(name, resolve_use_source(cx, path), true)
}; };
vec![Item::from_def_id_and_parts(import_def_id, None, ImportItem(inner), cx)] vec![Item::from_def_id_and_parts(import_def_id.to_def_id(), None, ImportItem(inner), cx)]
} }
fn clean_maybe_renamed_foreign_item<'tcx>( fn clean_maybe_renamed_foreign_item<'tcx>(

View File

@ -320,14 +320,28 @@ pub(crate) struct Item {
/// The name of this item. /// The name of this item.
/// Optional because not every item has a name, e.g. impls. /// Optional because not every item has a name, e.g. impls.
pub(crate) name: Option<Symbol>, pub(crate) name: Option<Symbol>,
pub(crate) attrs: Box<Attributes>, pub(crate) inner: Box<ItemInner>,
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
/// always belongs to the current crate.
pub(crate) inline_stmt_id: Option<LocalDefId>,
pub(crate) cfg: Option<Arc<Cfg>>,
}
#[derive(Clone)]
pub(crate) struct ItemInner {
/// Information about this item that is specific to what kind of item it is. /// Information about this item that is specific to what kind of item it is.
/// E.g., struct vs enum vs function. /// E.g., struct vs enum vs function.
pub(crate) kind: Box<ItemKind>, pub(crate) kind: ItemKind,
pub(crate) item_id: ItemId, pub(crate) attrs: Attributes,
/// This is the `DefId` of the `use` statement if the item was inlined. }
pub(crate) inline_stmt_id: Option<DefId>,
pub(crate) cfg: Option<Arc<Cfg>>, 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. /// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
@ -389,9 +403,9 @@ impl Item {
} }
pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> { pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
let kind = match &*self.kind { let kind = match &self.kind {
ItemKind::StrippedItem(k) => k, ItemKind::StrippedItem(k) => &*k,
_ => &*self.kind, _ => &self.kind,
}; };
match kind { match kind {
ItemKind::ModuleItem(Module { span, .. }) => Some(*span), ItemKind::ModuleItem(Module { span, .. }) => Some(*span),
@ -436,7 +450,7 @@ impl Item {
def_id, def_id,
name, name,
kind, kind,
Box::new(Attributes::from_ast(ast_attrs)), Attributes::from_ast(ast_attrs),
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg), ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
) )
} }
@ -445,16 +459,15 @@ impl Item {
def_id: DefId, def_id: DefId,
name: Option<Symbol>, name: Option<Symbol>,
kind: ItemKind, kind: ItemKind,
attrs: Box<Attributes>, attrs: Attributes,
cfg: Option<Arc<Cfg>>, cfg: Option<Arc<Cfg>>,
) -> Item { ) -> Item {
trace!("name={name:?}, def_id={def_id:?} cfg={cfg:?}"); trace!("name={name:?}, def_id={def_id:?} cfg={cfg:?}");
Item { Item {
item_id: def_id.into(), item_id: def_id.into(),
kind: Box::new(kind), inner: Box::new(ItemInner { kind, attrs }),
name, name,
attrs,
cfg, cfg,
inline_stmt_id: None, inline_stmt_id: None,
} }
@ -522,16 +535,16 @@ impl Item {
self.type_() == ItemType::Variant self.type_() == ItemType::Variant
} }
pub(crate) fn is_associated_type(&self) -> bool { 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 { 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 { 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 { 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 { pub(crate) fn is_method(&self) -> bool {
self.type_() == ItemType::Method self.type_() == ItemType::Method
@ -555,14 +568,14 @@ impl Item {
self.type_() == ItemType::Keyword self.type_() == ItemType::Keyword
} }
pub(crate) fn is_stripped(&self) -> bool { pub(crate) fn is_stripped(&self) -> bool {
match *self.kind { match self.kind {
StrippedItem(..) => true, StrippedItem(..) => true,
ImportItem(ref i) => !i.should_be_displayed, ImportItem(ref i) => !i.should_be_displayed,
_ => false, _ => false,
} }
} }
pub(crate) fn has_stripped_entries(&self) -> Option<bool> { pub(crate) fn has_stripped_entries(&self) -> Option<bool> {
match *self.kind { match self.kind {
StructItem(ref struct_) => Some(struct_.has_stripped_entries()), StructItem(ref struct_) => Some(struct_.has_stripped_entries()),
UnionItem(ref union_) => Some(union_.has_stripped_entries()), UnionItem(ref union_) => Some(union_.has_stripped_entries()),
EnumItem(ref enum_) => Some(enum_.has_stripped_entries()), EnumItem(ref enum_) => Some(enum_.has_stripped_entries()),
@ -605,7 +618,7 @@ impl Item {
} }
pub(crate) fn is_default(&self) -> bool { pub(crate) fn is_default(&self) -> bool {
match *self.kind { match self.kind {
ItemKind::MethodItem(_, Some(defaultness)) => { ItemKind::MethodItem(_, Some(defaultness)) => {
defaultness.has_value() && !defaultness.is_final() defaultness.has_value() && !defaultness.is_final()
} }
@ -633,7 +646,7 @@ impl Item {
}; };
hir::FnHeader { safety: sig.safety(), abi: sig.abi(), constness, asyncness } hir::FnHeader { safety: sig.safety(), abi: sig.abi(), constness, asyncness }
} }
let header = match *self.kind { let header = match self.kind {
ItemKind::ForeignFunctionItem(_, safety) => { ItemKind::ForeignFunctionItem(_, safety) => {
let def_id = self.def_id().unwrap(); let def_id = self.def_id().unwrap();
let abi = tcx.fn_sig(def_id).skip_binder().abi(); let abi = tcx.fn_sig(def_id).skip_binder().abi();
@ -672,7 +685,7 @@ impl Item {
ItemId::DefId(def_id) => def_id, ItemId::DefId(def_id) => def_id,
}; };
match *self.kind { match self.kind {
// Primitives and Keywords are written in the source code as private modules. // 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 // The modules need to be private so that nobody actually uses them, but the
// keywords and primitives that they are documenting are public. // keywords and primitives that they are documenting are public.
@ -702,7 +715,7 @@ impl Item {
_ => {} _ => {}
} }
let def_id = match self.inline_stmt_id { let def_id = match self.inline_stmt_id {
Some(inlined) => inlined, Some(inlined) => inlined.to_def_id(),
None => def_id, None => def_id,
}; };
Some(tcx.visibility(def_id)) Some(tcx.visibility(def_id))
@ -2559,13 +2572,13 @@ mod size_asserts {
use super::*; use super::*;
// tidy-alphabetical-start // 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!(DocFragment, 32);
static_assert_size!(GenericArg, 32); static_assert_size!(GenericArg, 32);
static_assert_size!(GenericArgs, 32); static_assert_size!(GenericArgs, 32);
static_assert_size!(GenericParamDef, 40); static_assert_size!(GenericParamDef, 40);
static_assert_size!(Generics, 16); static_assert_size!(Generics, 16);
static_assert_size!(Item, 56); static_assert_size!(Item, 48);
static_assert_size!(ItemKind, 48); static_assert_size!(ItemKind, 48);
static_assert_size!(PathSegment, 40); static_assert_size!(PathSegment, 40);
static_assert_size!(Type, 32); static_assert_size!(Type, 32);

View File

@ -36,7 +36,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
// understood by rustdoc. // understood by rustdoc.
let mut module = clean_doc_module(&module, cx); let mut module = clean_doc_module(&module, cx);
match *module.kind { match module.kind {
ItemKind::ModuleItem(ref module) => { ItemKind::ModuleItem(ref module) => {
for it in &module.items { for it in &module.items {
// `compiler_builtins` should be masked too, but we can't apply // `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 primitives = local_crate.primitives(cx.tcx);
let keywords = local_crate.keywords(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)| { m.items.extend(primitives.iter().map(|&(def_id, prim)| {
Item::from_def_id_and_parts( Item::from_def_id_and_parts(
def_id, def_id,
@ -281,7 +281,7 @@ pub(crate) fn build_deref_target_impls(
let tcx = cx.tcx; let tcx = cx.tcx;
for item in items { for item in items {
let target = match *item.kind { let target = match item.kind {
ItemKind::AssocTypeItem(ref t, _) => &t.type_, ItemKind::AssocTypeItem(ref t, _) => &t.type_,
_ => continue, _ => continue,
}; };

View File

@ -1,8 +1,8 @@
use crate::clean::*; use crate::clean::*;
pub(crate) fn strip_item(mut item: Item) -> Item { pub(crate) fn strip_item(mut item: Item) -> Item {
if !matches!(*item.kind, StrippedItem(..)) { if !matches!(item.inner.kind, StrippedItem(..)) {
item.kind = Box::new(StrippedItem(item.kind)); item.inner.kind = StrippedItem(Box::new(item.inner.kind));
} }
item item
} }
@ -99,10 +99,10 @@ pub(crate) trait DocFolder: Sized {
/// don't override! /// don't override!
fn fold_item_recur(&mut self, mut item: Item) -> Item { 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))), 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 item
} }

View File

@ -216,7 +216,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// If this is a stripped module, // If this is a stripped module,
// we don't want it or its children in the search index. // 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(..)) => { clean::StrippedItem(box clean::ModuleItem(..)) => {
mem::replace(&mut self.cache.stripped_mod, true) mem::replace(&mut self.cache.stripped_mod, true)
} }
@ -232,7 +232,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// If the impl is from a masked crate or references something from a // If the impl is from a masked crate or references something from a
// masked crate then remove it completely. // 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()) && (self.cache.masked_crates.contains(&item.item_id.krate())
|| i.trait_ || i.trait_
.as_ref() .as_ref()
@ -246,9 +246,9 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Propagate a trait method's documentation to all implementors of the // Propagate a trait method's documentation to all implementors of the
// trait. // 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()); 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_ && let Some(trait_) = &i.trait_
&& !i.kind.is_blanket() && !i.kind.is_blanket()
{ {
@ -263,7 +263,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Index this method for searching later on. // Index this method for searching later on.
let search_name = if !item.is_stripped() { let search_name = if !item.is_stripped() {
item.name.or_else(|| { 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 && let clean::ImportKind::Simple(s) = i.kind
{ {
Some(s) Some(s)
@ -287,7 +287,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
_ => false, _ => false,
}; };
match *item.kind { match item.kind {
clean::StructItem(..) clean::StructItem(..)
| clean::EnumItem(..) | clean::EnumItem(..)
| clean::TypeAliasItem(..) | clean::TypeAliasItem(..)
@ -350,7 +350,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
} }
// Maintain the parent stack. // Maintain the parent stack.
let (item, parent_pushed) = match *item.kind { let (item, parent_pushed) = match item.kind {
clean::TraitItem(..) clean::TraitItem(..)
| clean::EnumItem(..) | clean::EnumItem(..)
| clean::ForeignTypeItem | clean::ForeignTypeItem
@ -367,7 +367,11 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
// Once we've recursively found all the generics, hoard off all the // Once we've recursively found all the generics, hoard off all the
// implementations elsewhere. // 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 // Figure out the id of this impl. This may map to a
// primitive rather than always to a struct/enum. // primitive rather than always to a struct/enum.
// Note: matching twice to restrict the lifetime of the `i` borrow. // Note: matching twice to restrict the lifetime of the `i` borrow.
@ -436,7 +440,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::Item, name: Symbol) { 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). // 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 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::StrippedItem(..) => return,
clean::AssocConstItem(..) | clean::AssocTypeItem(..) clean::AssocConstItem(..) | clean::AssocTypeItem(..)
if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) => 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 either an inline, or a true re-export
// - It's got the same name // - It's got the same name
// - Both of them have the same exact path // - 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), clean::ItemKind::ImportItem(import) => import.source.did.unwrap_or(item_def_id),
_ => item_def_id, _ => item_def_id,
}; };
@ -605,7 +609,7 @@ enum ParentStackItem {
impl ParentStackItem { impl ParentStackItem {
fn new(item: &clean::Item) -> Self { fn new(item: &clean::Item) -> Self {
match &*item.kind { match &item.kind {
clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => { clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => {
ParentStackItem::Impl { ParentStackItem::Impl {
for_: for_.clone(), for_: for_.clone(),

View File

@ -70,7 +70,7 @@ impl Serialize for ItemType {
impl<'a> From<&'a clean::Item> for ItemType { impl<'a> From<&'a clean::Item> for ItemType {
fn from(item: &'a clean::Item) -> ItemType { fn from(item: &'a clean::Item) -> ItemType {
let kind = match *item.kind { let kind = match item.kind {
clean::StrippedItem(box ref item) => item, clean::StrippedItem(box ref item) => item,
ref kind => kind, ref kind => kind,
}; };

View File

@ -16,7 +16,7 @@ pub(crate) struct Impl {
impl Impl { impl Impl {
pub(crate) fn inner_impl(&self) -> &clean::Impl { pub(crate) fn inner_impl(&self) -> &clean::Impl {
match *self.impl_item.kind { match self.impl_item.kind {
clean::ImplItem(ref impl_) => impl_, clean::ImplItem(ref impl_) => impl_,
_ => panic!("non-impl item found in impl"), _ => panic!("non-impl item found in impl"),
} }

View File

@ -77,7 +77,7 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>(
cx.mod_item_in(&item)?; cx.mod_item_in(&item)?;
let (clean::StrippedItem(box clean::ModuleItem(module)) | clean::ModuleItem(module)) = let (clean::StrippedItem(box clean::ModuleItem(module)) | clean::ModuleItem(module)) =
*item.kind item.inner.kind
else { else {
unreachable!() unreachable!()
}; };

View File

@ -800,7 +800,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
// Render sidebar-items.js used throughout this module. // Render sidebar-items.js used throughout this module.
if !self.render_redirect_pages { if !self.render_redirect_pages {
let (clean::StrippedItem(box clean::ModuleItem(ref module)) let (clean::StrippedItem(box clean::ModuleItem(ref module))
| clean::ModuleItem(ref module)) = *item.kind | clean::ModuleItem(ref module)) = item.kind
else { else {
unreachable!() unreachable!()
}; };

View File

@ -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, clean::ItemKind::StrippedItem(box kind) | kind => kind,
}; };
@ -1072,7 +1072,7 @@ fn render_assoc_item(
cx: &mut Context<'_>, cx: &mut Context<'_>,
render_mode: RenderMode, render_mode: RenderMode,
) { ) {
match &*item.kind { match &item.kind {
clean::StrippedItem(..) => {} clean::StrippedItem(..) => {}
clean::TyMethodItem(m) => { clean::TyMethodItem(m) => {
assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode) assoc_method(w, item, &m.generics, &m.decl, link, parent, cx, render_mode)
@ -1350,7 +1350,7 @@ fn render_deref_methods(
.inner_impl() .inner_impl()
.items .items
.iter() .iter()
.find_map(|item| match *item.kind { .find_map(|item| match item.kind {
clean::AssocTypeItem(box ref t, _) => Some(match *t { clean::AssocTypeItem(box ref t, _) => Some(match *t {
clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_), clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.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 { 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::MethodItem(ref method, _) => method.decl.receiver_type(),
clean::TyMethodItem(ref method) => method.decl.receiver_type(), clean::TyMethodItem(ref method) => method.decl.receiver_type(),
_ => None, _ => None,
@ -1491,7 +1491,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) {
write!(&mut out, "<div class=\"where\">{}</div>", impl_.print(false, cx)); write!(&mut out, "<div class=\"where\">{}</div>", impl_.print(false, cx));
for it in &impl_.items { 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("<div class=\"where\"> "); out.push_str("<div class=\"where\"> ");
let empty_set = FxHashSet::default(); let empty_set = FxHashSet::default();
let src_link = AssocItemLink::GotoSource(trait_did.into(), &empty_set); let src_link = AssocItemLink::GotoSource(trait_did.into(), &empty_set);
@ -1659,7 +1659,7 @@ fn render_impl(
let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" }; let method_toggle_class = if item_type.is_method() { " method-toggle" } else { "" };
write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>"); write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>");
} }
match &*item.kind { match &item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => { clean::MethodItem(..) | clean::TyMethodItem(_) => {
// Only render when the method is not static or we allow static methods // Only render when the method is not static or we allow static methods
if render_method_item { if render_method_item {
@ -1690,7 +1690,7 @@ fn render_impl(
w.write_str("</h4></section>"); w.write_str("</h4></section>");
} }
} }
clean::TyAssocConstItem(generics, ty) => { clean::TyAssocConstItem(ref generics, ref ty) => {
let source_id = format!("{item_type}.{name}"); let source_id = format!("{item_type}.{name}");
let id = cx.derive_id(&source_id); let id = cx.derive_id(&source_id);
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">"); write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
@ -1734,7 +1734,7 @@ fn render_impl(
); );
w.write_str("</h4></section>"); w.write_str("</h4></section>");
} }
clean::TyAssocTypeItem(generics, bounds) => { clean::TyAssocTypeItem(ref generics, ref bounds) => {
let source_id = format!("{item_type}.{name}"); let source_id = format!("{item_type}.{name}");
let id = cx.derive_id(&source_id); let id = cx.derive_id(&source_id);
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">"); write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
@ -1808,7 +1808,7 @@ fn render_impl(
if !impl_.is_negative_trait_impl() { if !impl_.is_negative_trait_impl() {
for trait_item in &impl_.items { for trait_item in &impl_.items {
match *trait_item.kind { match trait_item.kind {
clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item), clean::MethodItem(..) | clean::TyMethodItem(_) => methods.push(trait_item),
clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => { clean::TyAssocTypeItem(..) | clean::AssocTypeItem(..) => {
assoc_types.push(trait_item) assoc_types.push(trait_item)
@ -2051,7 +2051,7 @@ pub(crate) fn render_impl_summary(
write!(w, "{}", inner_impl.print(use_absolute, cx)); write!(w, "{}", inner_impl.print(use_absolute, cx));
if show_def_docs { if show_def_docs {
for it in &inner_impl.items { 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("<div class=\"where\"> "); w.write_str("<div class=\"where\"> ");
assoc_type( assoc_type(
w, 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)> { 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() => { clean::ItemKind::ImplItem(ref i) if i.trait_.is_some() => {
// Alternative format produces no URLs, // Alternative format produces no URLs,
// so this parameter does nothing. // so this parameter does nothing.

View File

@ -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) { pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buffer) {
debug_assert!(!item.is_stripped()); debug_assert!(!item.is_stripped());
let typ = match *item.kind { let typ = match item.kind {
clean::ModuleItem(_) => { clean::ModuleItem(_) => {
if item.is_crate() { if item.is_crate() {
"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(); item_vars.render_into(buf).unwrap();
match &*item.kind { match &item.kind {
clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items), clean::ModuleItem(ref m) => item_module(buf, cx, item, &m.items),
clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f, _) => { clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f, _) => {
item_function(buf, cx, item, f) item_function(buf, cx, item, f)
@ -411,7 +411,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
); );
} }
match *myitem.kind { match myitem.kind {
clean::ExternCrateItem { ref src } => { clean::ExternCrateItem { ref src } => {
use crate::html::format::anchor; use crate::html::format::anchor;
@ -477,7 +477,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
continue; continue;
} }
let unsafety_flag = match *myitem.kind { let unsafety_flag = match myitem.kind {
clean::FunctionItem(_) | clean::ForeignFunctionItem(..) clean::FunctionItem(_) | clean::ForeignFunctionItem(..)
if myitem.fn_header(tcx).unwrap().safety == hir::Safety::Unsafe => if myitem.fn_header(tcx).unwrap().safety == hir::Safety::Unsafe =>
{ {
@ -1439,7 +1439,7 @@ fn item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
self.s self.s
.fields .fields
.iter() .iter()
.filter_map(|f| match *f.kind { .filter_map(|f| match f.kind {
clean::StructFieldItem(ref ty) => Some((f, ty)), clean::StructFieldItem(ref ty) => Some((f, ty)),
_ => None, _ => None,
}) })
@ -1457,7 +1457,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
display_fn(|f| { display_fn(|f| {
if !s.is_empty() if !s.is_empty()
&& s.iter().all(|field| { && s.iter().all(|field| {
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) matches!(field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
}) })
{ {
return f.write_str("<span class=\"comment\">/* private fields */</span>"); return f.write_str("<span class=\"comment\">/* private fields */</span>");
@ -1467,7 +1467,7 @@ fn print_tuple_struct_fields<'a, 'cx: 'a>(
if i > 0 { if i > 0 {
f.write_str(", ")?; f.write_str(", ")?;
} }
match *ty.kind { match ty.kind {
clean::StrippedItem(box clean::StructFieldItem(_)) => f.write_str("_")?, clean::StrippedItem(box clean::StructFieldItem(_)) => f.write_str("_")?,
clean::StructFieldItem(ref ty) => write!(f, "{}", ty.print(cx))?, clean::StructFieldItem(ref ty) => write!(f, "{}", ty.print(cx))?,
_ => unreachable!(), _ => unreachable!(),
@ -1521,7 +1521,7 @@ fn should_show_enum_discriminant(
) -> bool { ) -> bool {
let mut has_variants_with_value = false; let mut has_variants_with_value = false;
for variant in variants { 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) && matches!(var.kind, clean::VariantKind::CLike)
{ {
has_variants_with_value |= var.discriminant.is_some(); has_variants_with_value |= var.discriminant.is_some();
@ -1592,7 +1592,7 @@ fn render_enum_fields(
continue; continue;
} }
w.write_str(TAB); w.write_str(TAB);
match *v.kind { match v.kind {
clean::VariantItem(ref var) => match var.kind { clean::VariantItem(ref var) => match var.kind {
clean::VariantKind::CLike => display_c_like_variant( clean::VariantKind::CLike => display_c_like_variant(
w, w,
@ -1659,7 +1659,7 @@ fn item_variants(
" rightside", " rightside",
); );
w.write_str("<h3 class=\"code-header\">"); w.write_str("<h3 class=\"code-header\">");
if let clean::VariantItem(ref var) = *variant.kind if let clean::VariantItem(ref var) = variant.kind
&& let clean::VariantKind::CLike = var.kind && let clean::VariantKind::CLike = var.kind
{ {
display_c_like_variant( display_c_like_variant(
@ -1675,7 +1675,7 @@ fn item_variants(
w.write_str(variant.name.unwrap().as_str()); 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 { if let clean::VariantKind::Tuple(ref s) = variant_data.kind {
write!(w, "({})", print_tuple_struct_fields(cx, s)); write!(w, "({})", print_tuple_struct_fields(cx, s));
@ -1716,7 +1716,7 @@ fn item_variants(
document_non_exhaustive(variant) document_non_exhaustive(variant)
); );
for field in fields { for field in fields {
match *field.kind { match field.kind {
clean::StrippedItem(box clean::StructFieldItem(_)) => {} clean::StrippedItem(box clean::StructFieldItem(_)) => {}
clean::StructFieldItem(ref ty) => { clean::StructFieldItem(ref ty) => {
let id = cx.derive_id(format!( let id = cx.derive_id(format!(
@ -1886,7 +1886,7 @@ fn item_fields(
) { ) {
let mut fields = fields let mut fields = fields
.iter() .iter()
.filter_map(|f| match *f.kind { .filter_map(|f| match f.kind {
clean::StructFieldItem(ref ty) => Some((f, ty)), clean::StructFieldItem(ref ty) => Some((f, ty)),
_ => None, _ => None,
}) })
@ -2196,14 +2196,14 @@ fn render_union<'a, 'cx: 'a>(
write!(f, "{{\n")?; write!(f, "{{\n")?;
let count_fields = 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); let toggle = should_hide_fields(count_fields);
if toggle { if toggle {
toggle_open(&mut f, format_args!("{count_fields} fields")); toggle_open(&mut f, format_args!("{count_fields} fields"));
} }
for field in fields { for field in fields {
if let clean::StructFieldItem(ref ty) = *field.kind { if let clean::StructFieldItem(ref ty) = field.kind {
write!( write!(
f, f,
" {}{}: {},\n", " {}{}: {},\n",
@ -2279,14 +2279,14 @@ fn render_struct_fields(
w.write_str("{"); w.write_str("{");
} }
let count_fields = 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 has_visible_fields = count_fields > 0;
let toggle = should_hide_fields(count_fields); let toggle = should_hide_fields(count_fields);
if toggle { if toggle {
toggle_open(&mut w, format_args!("{count_fields} fields")); toggle_open(&mut w, format_args!("{count_fields} fields"));
} }
for field in fields { for field in fields {
if let clean::StructFieldItem(ref ty) = *field.kind { if let clean::StructFieldItem(ref ty) = field.kind {
write!( write!(
w, w,
"\n{tab} {vis}{name}: {ty},", "\n{tab} {vis}{name}: {ty},",
@ -2314,7 +2314,7 @@ fn render_struct_fields(
w.write_str("("); w.write_str("(");
if !fields.is_empty() if !fields.is_empty()
&& fields.iter().all(|field| { && fields.iter().all(|field| {
matches!(*field.kind, clean::StrippedItem(box clean::StructFieldItem(..))) matches!(field.kind, clean::StrippedItem(box clean::StructFieldItem(..)))
}) })
{ {
write!(w, "<span class=\"comment\">/* private fields */</span>"); write!(w, "<span class=\"comment\">/* private fields */</span>");
@ -2323,7 +2323,7 @@ fn render_struct_fields(
if i > 0 { if i > 0 {
w.write_str(", "); w.write_str(", ");
} }
match *field.kind { match field.kind {
clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"), clean::StrippedItem(box clean::StructFieldItem(..)) => write!(w, "_"),
clean::StructFieldItem(ref ty) => { clean::StructFieldItem(ref ty) => {
write!(w, "{}{}", visibility_print_with_space(field, cx), ty.print(cx),) write!(w, "{}{}", visibility_print_with_space(field, cx), ty.print(cx),)

View File

@ -758,7 +758,7 @@ pub(crate) fn get_function_type_for_search<'tcx>(
None 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) => { clean::FunctionItem(ref f) | clean::MethodItem(ref f, _) | clean::TyMethodItem(ref f) => {
get_fn_inputs_and_outputs(f, tcx, impl_or_trait_generics, cache) 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()) && trait_.items.iter().any(|at| at.is_ty_associated_type())
{ {
for assoc_ty in &trait_.items { 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 Some(name) = assoc_ty.name
{ {
let idx = -isize::try_from(rgen.len() + 1).unwrap(); let idx = -isize::try_from(rgen.len() + 1).unwrap();

View File

@ -119,7 +119,7 @@ pub(crate) mod filters {
pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
let mut ids = IdMap::new(); let mut ids = IdMap::new();
let mut blocks: Vec<LinkBlock<'_>> = docblock_toc(cx, it, &mut ids).into_iter().collect(); let mut blocks: Vec<LinkBlock<'_>> = 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::StructItem(ref s) => sidebar_struct(cx, it, s, &mut blocks),
clean::TraitItem(ref t) => sidebar_trait(cx, it, t, &mut blocks), clean::TraitItem(ref t) => sidebar_trait(cx, it, t, &mut blocks),
clean::PrimitiveItem(_) => sidebar_primitive(cx, it, &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 // crate title is displayed as part of logo lockup
let (title_prefix, title) = if !blocks.is_empty() && !it.is_crate() { let (title_prefix, title) = if !blocks.is_empty() && !it.is_crate() {
( (
match *it.kind { match it.kind {
clean::ModuleItem(..) => "Module ", 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<Link<'a>> { fn get_struct_fields_name<'a>(fields: &'a [clean::Item]) -> Vec<Link<'a>> {
let mut fields = fields let mut fields = fields
.iter() .iter()
.filter(|f| matches!(*f.kind, clean::StructFieldItem(..))) .filter(|f| matches!(f.kind, clean::StructFieldItem(..)))
.filter_map(|f| { .filter_map(|f| {
f.name.as_ref().map(|name| Link::new(format!("structfield.{name}"), name.as_str())) 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_:?}"); debug!("found Deref: {impl_:?}");
if let Some((target, real_target)) = 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::AssocTypeItem(box ref t, _) => Some(match *t {
clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_), clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_), _ => (&t.type_, &t.type_),
@ -587,7 +587,7 @@ fn sidebar_module(
&& it && it
.name .name
.or_else(|| { .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 && let clean::ImportKind::Simple(s) = i.kind
{ {
Some(s) Some(s)

View File

@ -783,7 +783,7 @@ impl<'cx, 'cache> DocVisitor for TypeImplCollector<'cx, 'cache> {
fn visit_item(&mut self, it: &Item) { fn visit_item(&mut self, it: &Item) {
self.visit_item_recur(it); self.visit_item_recur(it);
let cache = self.cache; 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 }; let Some(self_did) = it.item_id.as_def_id() else { return };
if !self.visited_aliases.insert(self_did) { if !self.visited_aliases.insert(self_did) {
return; return;

View File

@ -49,7 +49,7 @@ impl JsonRenderer<'_> {
let visibility = item.visibility(self.tcx); let visibility = item.visibility(self.tcx);
let clean::Item { name, item_id, .. } = item; let clean::Item { name, item_id, .. } = item;
let id = id_from_item(&item, self.tcx); let id = id_from_item(&item, self.tcx);
let inner = match *item.kind { let inner = match item.kind {
clean::KeywordItem => return None, clean::KeywordItem => return None,
clean::StrippedItem(ref inner) => { clean::StrippedItem(ref inner) => {
match &**inner { match &**inner {
@ -294,7 +294,7 @@ pub(crate) fn id_from_item_inner(
} }
pub(crate) fn id_from_item(item: &clean::Item, tcx: TyCtxt<'_>) -> Id { pub(crate) fn id_from_item(item: &clean::Item, tcx: TyCtxt<'_>) -> Id {
match *item.kind { match item.kind {
clean::ItemKind::ImportItem(ref import) => { clean::ItemKind::ImportItem(ref import) => {
let extra = let extra =
import.source.did.map(ItemId::from).map(|i| id_from_item_inner(i, tcx, None, None)); 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 is_crate = item.is_crate();
let header = item.fn_header(tcx); let header = item.fn_header(tcx);
match *item.kind { match item.inner.kind {
ModuleItem(m) => { ModuleItem(m) => {
ItemEnum::Module(Module { is_crate, items: ids(m.items, tcx), is_stripped: false }) ItemEnum::Module(Module { is_crate, items: ids(m.items, tcx), is_stripped: false })
} }

View File

@ -24,7 +24,7 @@ struct ImportFinder {
impl DocFolder for ImportFinder { impl DocFolder for ImportFinder {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
match *i.kind { match i.kind {
clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => { clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => {
self.imported.insert(did); self.imported.insert(did);
Some(i) Some(i)

View File

@ -85,7 +85,7 @@ impl<'tcx> JsonRenderer<'tcx> {
// document primitive items in an arbitrary crate by using // document primitive items in an arbitrary crate by using
// `rustc_doc_primitive`. // `rustc_doc_primitive`.
let mut is_primitive_impl = false; 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() && impl_.trait_.is_none()
&& let clean::types::Type::Primitive(_) = impl_.for_ && let clean::types::Type::Primitive(_) = impl_.for_
{ {
@ -164,7 +164,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
// Flatten items that recursively store other items. We include orphaned items from // Flatten items that recursively store other items. We include orphaned items from
// stripped modules and etc that are otherwise reachable. // 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()); inner.inner_items().for_each(|i| self.item(i.clone()).unwrap());
} }

View File

@ -195,7 +195,7 @@ impl<'a, 'b> DocVisitor for CoverageCalculator<'a, 'b> {
return; return;
} }
match *i.kind { match i.kind {
clean::StrippedItem(..) => { clean::StrippedItem(..) => {
// don't count items in stripped modules // don't count items in stripped modules
return; return;

View File

@ -57,7 +57,7 @@ impl crate::doctest::DocTestVisitor for Tests {
pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool { 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()) if !cx.cache.effective_visibilities.is_directly_public(cx.tcx, item.item_id.expect_def_id())
|| matches!( || matches!(
*item.kind, item.kind,
clean::StructFieldItem(_) clean::StructFieldItem(_)
| clean::VariantItem(_) | clean::VariantItem(_)
| clean::AssocConstItem(..) | clean::AssocConstItem(..)

View File

@ -160,13 +160,13 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
// scan through included items ahead of time to splice in Deref targets to the "valid" sets // 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()) { 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() && trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait()
&& cleaner.keep_impl(for_, true) && cleaner.keep_impl(for_, true)
{ {
let target = items let target = items
.iter() .iter()
.find_map(|item| match *item.kind { .find_map(|item| match item.kind {
AssocTypeItem(ref t, _) => Some(&t.type_), AssocTypeItem(ref t, _) => Some(&t.type_),
_ => None, _ => None,
}) })
@ -200,7 +200,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
// Filter out external items that are not needed // Filter out external items that are not needed
new_items_external.retain(|it| { 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( cleaner.keep_impl(
for_, for_,
trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(), trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait(),
@ -211,7 +211,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
} }
}); });
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(synth_impls);
items.extend(new_items_external); items.extend(new_items_external);
items.extend(new_items_local); items.extend(new_items_local);
@ -258,7 +258,7 @@ impl<'cache> DocVisitor for ItemAndAliasCollector<'cache> {
fn visit_item(&mut self, i: &Item) { fn visit_item(&mut self, i: &Item) {
self.items.insert(i.item_id); 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) && let Some(did) = alias.type_.def_id(self.cache)
{ {
self.items.insert(ItemId::DefId(did)); self.items.insert(ItemId::DefId(did));

View File

@ -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 // Some items need to merge their attributes with their parents' otherwise a few of them
// (mostly `cfg` ones) will be missing. // (mostly `cfg` ones) will be missing.
fn merge_with_parent_attributes(&mut self, item: &mut Item) { 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 // impl blocks can be in different modules with different cfg and we need to get them
// as well. // as well.
ItemKind::ImplItem(_) => false, ItemKind::ImplItem(_) => false,

View File

@ -23,7 +23,7 @@ struct AliasedNonLocalStripper<'tcx> {
impl<'tcx> DocFolder for AliasedNonLocalStripper<'tcx> { impl<'tcx> DocFolder for AliasedNonLocalStripper<'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
Some(match *i.kind { Some(match i.kind {
clean::TypeAliasItem(..) => { clean::TypeAliasItem(..) => {
let mut stripper = NonLocalStripper { tcx: self.tcx }; let mut stripper = NonLocalStripper { tcx: self.tcx };
// don't call `fold_item` as that could strip the type-alias it-self // don't call `fold_item` as that could strip the type-alias it-self

View File

@ -89,7 +89,7 @@ impl<'a, 'tcx> Stripper<'a, 'tcx> {
impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
let has_doc_hidden = i.is_doc_hidden(); 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, clean::ImplItem(..) => true,
// If the macro has the `#[macro_export]` attribute, it means it's accessible at the // If the macro has the `#[macro_export]` attribute, it means it's accessible at the
// crate level so it should be handled differently. // crate level so it should be handled differently.
@ -138,7 +138,7 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
// module it's defined in. Both of these are marked "stripped," and // 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 // 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. // on the final doc, cannot be completely removed from the Clean IR.
match *i.kind { match i.kind {
clean::StructFieldItem(..) | clean::ModuleItem(..) | clean::VariantItem(..) => { clean::StructFieldItem(..) | clean::ModuleItem(..) | clean::VariantItem(..) => {
// We need to recurse into stripped modules to // We need to recurse into stripped modules to
// strip things like impl methods but when doing so // strip things like impl methods but when doing so

View File

@ -39,7 +39,7 @@ fn is_item_reachable(
impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> { impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
match *i.kind { match i.kind {
clean::StrippedItem(..) => { clean::StrippedItem(..) => {
// We need to recurse into stripped modules to strip things // We need to recurse into stripped modules to strip things
// like impl methods but when doing so we must not add any // like impl methods but when doing so we must not add any
@ -130,7 +130,7 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
clean::KeywordItem => {} clean::KeywordItem => {}
} }
let fastreturn = match *i.kind { let fastreturn = match i.kind {
// nothing left to do for traits (don't want to filter their // nothing left to do for traits (don't want to filter their
// methods out, visibility controlled by the trait) // methods out, visibility controlled by the trait)
clean::TraitItem(..) => true, clean::TraitItem(..) => true,
@ -195,7 +195,7 @@ impl<'a> ImplStripper<'a, '_> {
impl<'a> DocFolder for ImplStripper<'a, '_> { impl<'a> DocFolder for ImplStripper<'a, '_> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
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 // Impl blocks can be skipped if they are: empty; not a trait impl; and have no
// documentation. // documentation.
// //
@ -272,7 +272,7 @@ impl<'tcx> ImportStripper<'tcx> {
impl<'tcx> DocFolder for ImportStripper<'tcx> { impl<'tcx> DocFolder for ImportStripper<'tcx> {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
match *i.kind { match &i.kind {
clean::ImportItem(imp) clean::ImportItem(imp)
if !self.document_hidden && self.import_should_be_hidden(&i, &imp) => if !self.document_hidden && self.import_should_be_hidden(&i, &imp) =>
{ {

View File

@ -48,8 +48,8 @@ pub(crate) trait DocVisitor: Sized {
/// don't override! /// don't override!
fn visit_item_recur(&mut self, item: &Item) { fn visit_item_recur(&mut self, item: &Item) {
match &*item.kind { match &item.kind {
StrippedItem(i) => self.visit_inner_recur(i), StrippedItem(i) => self.visit_inner_recur(&*i),
_ => self.visit_inner_recur(&item.kind), _ => self.visit_inner_recur(&item.kind),
} }
} }