Skip to content
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

rustdoc: wrap Type with Box instead of Generics #117070

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,13 @@ fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
clean::simplify::move_bounds_to_generic_parameters(&mut generics);

clean::Constant {
type_: clean_middle_ty(
type_: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()),
cx,
Some(def_id),
None,
),
generics: Box::new(generics),
)),
generics,
kind: clean::ConstantKind::Extern { def_id },
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id();
Constant {
type_: clean_middle_ty(
type_: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()),
cx,
Some(def_id),
None,
),
generics: Box::new(Generics::default()),
)),
generics: Generics::default(),
kind: ConstantKind::Anonymous { body: constant.value.body },
}
}
Expand All @@ -276,8 +276,8 @@ pub(crate) fn clean_middle_const<'tcx>(
) -> Constant {
// FIXME: instead of storing the stringified expression, store `self` directly instead.
Constant {
type_: clean_middle_ty(constant.map_bound(|c| c.ty()), cx, None, None),
generics: Box::new(Generics::default()),
type_: Box::new(clean_middle_ty(constant.map_bound(|c| c.ty()), cx, None, None)),
generics: Generics::default(),
kind: ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() },
}
}
Expand Down Expand Up @@ -1216,14 +1216,14 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
hir::TraitItemKind::Const(ty, Some(default)) => {
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
AssocConstItem(
Box::new(generics),
clean_ty(ty, cx),
generics,
Box::new(clean_ty(ty, cx)),
ConstantKind::Local { def_id: local_did, body: default },
)
}
hir::TraitItemKind::Const(ty, None) => {
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
TyAssocConstItem(Box::new(generics), clean_ty(ty, cx))
TyAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Body(body));
Expand Down Expand Up @@ -1272,7 +1272,7 @@ pub(crate) fn clean_impl_item<'tcx>(
hir::ImplItemKind::Const(ty, expr) => {
let generics = clean_generics(impl_.generics, cx);
let default = ConstantKind::Local { def_id: local_did, body: expr };
AssocConstItem(Box::new(generics), clean_ty(ty, cx), default)
AssocConstItem(generics, Box::new(clean_ty(ty, cx)), default)
}
hir::ImplItemKind::Fn(ref sig, body) => {
let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
Expand Down Expand Up @@ -1311,18 +1311,18 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
let tcx = cx.tcx;
let kind = match assoc_item.kind {
ty::AssocKind::Const => {
let ty = clean_middle_ty(
let ty = Box::new(clean_middle_ty(
ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()),
cx,
Some(assoc_item.def_id),
None,
);
));

let mut generics = Box::new(clean_ty_generics(
let mut generics = clean_ty_generics(
cx,
tcx.generics_of(assoc_item.def_id),
tcx.explicit_predicates_of(assoc_item.def_id),
));
);
simplify::move_bounds_to_generic_parameters(&mut generics);

let provided = match assoc_item.container {
Expand Down Expand Up @@ -2718,8 +2718,8 @@ fn clean_maybe_renamed_item<'tcx>(
StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) })
}
ItemKind::Const(ty, generics, body_id) => ConstantItem(Constant {
type_: clean_ty(ty, cx),
generics: Box::new(clean_generics(generics, cx)),
type_: Box::new(clean_ty(ty, cx)),
generics: clean_generics(generics, cx),
kind: ConstantKind::Local { body: body_id, def_id },
}),
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,9 @@ pub(crate) enum ItemKind {
ProcMacroItem(ProcMacro),
PrimitiveItem(PrimitiveType),
/// A required associated constant in a trait declaration.
TyAssocConstItem(Box<Generics>, Type),
TyAssocConstItem(Generics, Box<Type>),
/// An associated constant in a trait impl or a provided one in a trait declaration.
AssocConstItem(Box<Generics>, Type, ConstantKind),
AssocConstItem(Generics, Box<Type>, ConstantKind),
/// A required associated type in a trait declaration.
///
/// The bounds may be non-empty if there is a `where` clause.
Expand Down Expand Up @@ -2282,8 +2282,8 @@ pub(crate) struct Static {

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) struct Constant {
pub(crate) type_: Type,
pub(crate) generics: Box<Generics>,
pub(crate) type_: Box<Type>,
pub(crate) generics: Generics,
pub(crate) kind: ConstantKind,
}

Expand Down Expand Up @@ -2525,7 +2525,7 @@ mod size_asserts {
static_assert_size!(Generics, 16);
static_assert_size!(Item, 56);
// FIXME(generic_const_items): Further reduce the size.
notriddle marked this conversation as resolved.
Show resolved Hide resolved
static_assert_size!(ItemKind, 72);
static_assert_size!(ItemKind, 56);
static_assert_size!(PathSegment, 40);
static_assert_size!(Type, 32);
// tidy-alphabetical-end
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl FromWithTcx<clean::Constant> for Constant {
let expr = constant.expr(tcx);
let value = constant.value(tcx);
let is_literal = constant.is_literal(tcx);
Constant { type_: constant.type_.into_tcx(tcx), expr, value, is_literal }
Constant { type_: (*constant.type_).into_tcx(tcx), expr, value, is_literal }
}
}

Expand Down Expand Up @@ -325,11 +325,11 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
}
// FIXME(generic_const_items): Add support for generic associated consts.
TyAssocConstItem(_generics, ty) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: None }
ItemEnum::AssocConst { type_: (*ty).into_tcx(tcx), default: None }
}
// FIXME(generic_const_items): Add support for generic associated consts.
AssocConstItem(_generics, ty, default) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) }
ItemEnum::AssocConst { type_: (*ty).into_tcx(tcx), default: Some(default.expr(tcx)) }
}
TyAssocTypeItem(g, b) => ItemEnum::AssocType {
generics: g.into_tcx(tcx),
Expand Down