mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
rustdoc: use a single box to store Attributes and ItemKind
This commit is contained in:
parent
e80c9ac3e2
commit
65903362ad
@ -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,
|
||||
})
|
||||
|
@ -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,
|
||||
});
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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<Symbol>,
|
||||
pub(crate) attrs: Box<Attributes>,
|
||||
/// 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<ItemKind>,
|
||||
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
|
||||
@ -332,6 +329,21 @@ pub(crate) struct Item {
|
||||
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.
|
||||
/// 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 @@ impl Item {
|
||||
}
|
||||
|
||||
pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option<Span> {
|
||||
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 @@ impl Item {
|
||||
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 @@ impl Item {
|
||||
def_id: DefId,
|
||||
name: Option<Symbol>,
|
||||
kind: ItemKind,
|
||||
attrs: Box<Attributes>,
|
||||
attrs: Attributes,
|
||||
cfg: Option<Arc<Cfg>>,
|
||||
) -> 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 @@ impl Item {
|
||||
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 @@ impl Item {
|
||||
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<bool> {
|
||||
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 @@ impl Item {
|
||||
}
|
||||
|
||||
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 @@ impl Item {
|
||||
};
|
||||
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 @@ impl Item {
|
||||
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);
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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 @@ pub(crate) trait DocFolder: Sized {
|
||||
|
||||
/// 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
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
|
||||
// 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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
|
||||
// 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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
|
||||
// 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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
// 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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
_ => false,
|
||||
};
|
||||
|
||||
match *item.kind {
|
||||
match item.kind {
|
||||
clean::StructItem(..)
|
||||
| clean::EnumItem(..)
|
||||
| clean::TypeAliasItem(..)
|
||||
@ -350,7 +350,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// 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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
|
||||
// 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 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
||||
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(),
|
||||
|
@ -70,7 +70,7 @@ impl Serialize for ItemType {
|
||||
|
||||
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,
|
||||
};
|
||||
|
@ -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"),
|
||||
}
|
||||
|
@ -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!()
|
||||
};
|
||||
|
@ -800,7 +800,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
||||
// 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!()
|
||||
};
|
||||
|
@ -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, "<div class=\"where\">{}</div>", 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("<div class=\"where\"> ");
|
||||
let empty_set = FxHashSet::default();
|
||||
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 { "" };
|
||||
write!(w, "<details class=\"toggle{method_toggle_class}\" open><summary>");
|
||||
}
|
||||
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 render_impl(
|
||||
w.write_str("</h4></section>");
|
||||
}
|
||||
}
|
||||
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, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
|
||||
@ -1734,7 +1734,7 @@ fn render_impl(
|
||||
);
|
||||
w.write_str("</h4></section>");
|
||||
}
|
||||
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, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
|
||||
@ -1808,7 +1808,7 @@ fn render_impl(
|
||||
|
||||
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("<div class=\"where\"> ");
|
||||
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.
|
||||
|
@ -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 item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
|
||||
);
|
||||
}
|
||||
|
||||
match *myitem.kind {
|
||||
match myitem.kind {
|
||||
clean::ExternCrateItem { ref src } => {
|
||||
use crate::html::format::anchor;
|
||||
|
||||
@ -477,7 +477,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items:
|
||||
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 item_union(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean:
|
||||
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("<span class=\"comment\">/* private fields */</span>");
|
||||
@ -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("<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
|
||||
{
|
||||
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, "<span class=\"comment\">/* private fields */</span>");
|
||||
@ -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),)
|
||||
|
@ -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();
|
||||
|
@ -119,7 +119,7 @@ pub(crate) mod filters {
|
||||
pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
|
||||
let mut ids = IdMap::new();
|
||||
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::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<Link<'a>> {
|
||||
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)
|
||||
|
@ -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;
|
||||
|
@ -49,7 +49,7 @@ impl JsonRenderer<'_> {
|
||||
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 @@ pub(crate) fn id_from_item_inner(
|
||||
}
|
||||
|
||||
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 })
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ struct ImportFinder {
|
||||
|
||||
impl DocFolder for ImportFinder {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
match *i.kind {
|
||||
match i.kind {
|
||||
clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => {
|
||||
self.imported.insert(did);
|
||||
Some(i)
|
||||
|
@ -85,7 +85,7 @@ impl<'tcx> JsonRenderer<'tcx> {
|
||||
// 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 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ impl<'a, 'b> DocVisitor for CoverageCalculator<'a, 'b> {
|
||||
return;
|
||||
}
|
||||
|
||||
match *i.kind {
|
||||
match i.kind {
|
||||
clean::StrippedItem(..) => {
|
||||
// don't count items in stripped modules
|
||||
return;
|
||||
|
@ -57,7 +57,7 @@ impl crate::doctest::DocTestVisitor for Tests {
|
||||
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(..)
|
||||
|
@ -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
|
||||
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 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
||||
|
||||
// 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 @@ 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(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));
|
||||
|
@ -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,
|
||||
|
@ -23,7 +23,7 @@ struct AliasedNonLocalStripper<'tcx> {
|
||||
|
||||
impl<'tcx> DocFolder for AliasedNonLocalStripper<'tcx> {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
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
|
||||
|
@ -89,7 +89,7 @@ impl<'a, 'tcx> Stripper<'a, 'tcx> {
|
||||
impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
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 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
|
||||
// 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
|
||||
|
@ -39,7 +39,7 @@ fn is_item_reachable(
|
||||
|
||||
impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
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 @@ impl<'a, 'tcx> DocFolder for Stripper<'a, 'tcx> {
|
||||
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 @@ impl<'a> ImplStripper<'a, '_> {
|
||||
|
||||
impl<'a> DocFolder for ImplStripper<'a, '_> {
|
||||
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
|
||||
// documentation.
|
||||
//
|
||||
@ -272,7 +272,7 @@ impl<'tcx> ImportStripper<'tcx> {
|
||||
|
||||
impl<'tcx> DocFolder for ImportStripper<'tcx> {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
match *i.kind {
|
||||
match &i.kind {
|
||||
clean::ImportItem(imp)
|
||||
if !self.document_hidden && self.import_should_be_hidden(&i, &imp) =>
|
||||
{
|
||||
|
@ -48,8 +48,8 @@ pub(crate) trait DocVisitor: Sized {
|
||||
|
||||
/// 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),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user