Skip to content

rustdoc: remove ItemInner. #138916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,17 @@ fn synthesize_auto_trait_impl<'tcx>(

Some(clean::Item {
name: None,
inner: Box::new(clean::ItemInner {
attrs: Default::default(),
stability: None,
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,
})),
}),
attrs: Default::default(),
stability: None,
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 },
cfg: None,
inline_stmt_id: None,
Expand Down
74 changes: 36 additions & 38 deletions src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,42 @@ pub(crate) fn synthesize_blanket_impls(
blanket_impls.push(clean::Item {
name: None,
item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
inner: Box::new(clean::ItemInner {
attrs: Default::default(),
stability: None,
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,
))),
})),
}),
attrs: Default::default(),
stability: None,
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,
});
Expand Down
38 changes: 18 additions & 20 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,27 +669,25 @@ fn build_module_items(
// We can use the item's `DefId` directly since the only information ever used
// from it is `DefId.krate`.
item_id: ItemId::DefId(did),
inner: Box::new(clean::ItemInner {
attrs: Default::default(),
stability: None,
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,
attrs: Default::default(),
stability: None,
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(),
},
}],
},
true,
)),
}),
did: None,
},
true,
)),
cfg: None,
inline_stmt_id: None,
});
Expand Down
37 changes: 13 additions & 24 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,30 +314,18 @@ 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) 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.
/// E.g., struct vs enum vs function.
pub(crate) kind: ItemKind,
pub(crate) attrs: Attributes,
/// The effective stability, filled out by the `propagate-stability` pass.
pub(crate) stability: Option<Stability>,
}

impl std::ops::Deref for Item {
type Target = ItemInner;
fn deref(&self) -> &ItemInner {
&self.inner
}
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>>,
}

/// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs.
Expand Down Expand Up @@ -383,13 +371,12 @@ impl Item {
///
/// This method should only be called after the `propagate-stability` pass has been run.
pub(crate) fn stability(&self, tcx: TyCtxt<'_>) -> Option<Stability> {
let stability = self.inner.stability;
debug_assert!(
stability.is_some()
self.stability.is_some()
|| self.def_id().is_none_or(|did| tcx.lookup_stability(did).is_none()),
"missing stability for cleaned item: {self:?}",
);
stability
self.stability
}

pub(crate) fn const_stability(&self, tcx: TyCtxt<'_>) -> Option<ConstStability> {
Expand Down Expand Up @@ -489,7 +476,9 @@ impl Item {

Item {
item_id: def_id.into(),
inner: Box::new(ItemInner { kind, attrs, stability: None }),
kind,
attrs,
stability: None,
name,
cfg,
inline_stmt_id: None,
Expand Down Expand Up @@ -2618,13 +2607,13 @@ mod size_asserts {

use super::*;
// tidy-alphabetical-start
static_assert_size!(Crate, 56); // frequently moved by-value
static_assert_size!(Crate, 144); // frequently moved by-value
static_assert_size!(DocFragment, 32);
static_assert_size!(GenericArg, 32);
static_assert_size!(GenericArgs, 24);
static_assert_size!(GenericParamDef, 40);
static_assert_size!(Generics, 16);
static_assert_size!(Item, 48);
static_assert_size!(Item, 136);
static_assert_size!(ItemKind, 48);
static_assert_size!(PathSegment, 32);
static_assert_size!(Type, 32);
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(m) = &mut module.inner.kind else { unreachable!() };
let ItemKind::ModuleItem(m) = &mut module.kind else { unreachable!() };
m.items.extend(primitives.iter().map(|&(def_id, prim)| {
Item::from_def_id_and_parts(
def_id,
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::mem;
use crate::clean::*;

pub(crate) fn strip_item(mut item: Item) -> Item {
if !matches!(item.inner.kind, StrippedItem(..)) {
item.inner.kind = StrippedItem(Box::new(item.inner.kind));
if !matches!(item.kind, StrippedItem(..)) {
item.kind = StrippedItem(Box::new(item.kind));
}
item
}
Expand Down Expand Up @@ -102,9 +102,9 @@ pub(crate) trait DocFolder: Sized {

/// don't override!
fn fold_item_recur(&mut self, mut item: Item) -> Item {
item.inner.kind = match item.inner.kind {
item.kind = match item.kind {
StrippedItem(box i) => StrippedItem(Box::new(self.fold_inner_recur(i))),
_ => self.fold_inner_recur(item.inner.kind),
_ => self.fold_inner_recur(item.kind),
};
item
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ impl DocFolder for CacheBuilder<'_, '_> {

// Once we've recursively found all the generics, hoard off all the
// implementations elsewhere.
let ret = if let clean::Item {
inner: box clean::ItemInner { kind: clean::ImplItem(ref i), .. },
..
} = item
{
let ret = if let clean::Item { 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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/formats/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(

cx.mod_item_in(&item)?;
let (clean::StrippedItem(box clean::ModuleItem(module)) | clean::ModuleItem(module)) =
item.inner.kind
item.kind
else {
unreachable!()
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ fn from_clean_item(item: clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum {
let is_crate = item.is_crate();
let header = item.fn_header(renderer.tcx);

match item.inner.kind {
match item.kind {
ModuleItem(m) => {
ItemEnum::Module(Module { is_crate, items: renderer.ids(m.items), is_stripped: false })
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
}
});

if let ModuleItem(Module { items, .. }) = &mut krate.module.inner.kind {
if let ModuleItem(Module { items, .. }) = &mut krate.module.kind {
items.extend(synth_impls);
items.extend(new_items_external);
items.extend(new_items_local);
Expand Down Expand Up @@ -259,7 +259,7 @@ impl DocVisitor<'_> for ItemAndAliasCollector<'_> {
fn visit_item(&mut self, i: &Item) {
self.items.insert(i.item_id);

if let TypeAliasItem(alias) = &i.inner.kind
if let TypeAliasItem(alias) = &i.kind
&& let Some(did) = alias.type_.def_id(self.cache)
{
self.items.insert(ItemId::DefId(did));
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/propagate_stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl DocFolder for StabilityPropagator<'_, '_> {
}
};

item.inner.stability = stability;
item.stability = stability;
self.parent_stability = stability;
let item = self.fold_item_recur(item);
self.parent_stability = parent_stability;
Expand Down
Loading