mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
rustdoc: wrap Type with Box instead of Generics
When these `Box<Generics>` types were introduced, `Generics` was made with `Vec` and much larger. Now that it's made with `ThinVec`, `Type` is bigger and should be boxed instead.
This commit is contained in:
parent
111adde7ed
commit
b67985e113
@ -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 },
|
||||
}
|
||||
}
|
||||
|
@ -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 },
|
||||
}
|
||||
}
|
||||
@ -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() },
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
@ -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));
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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.
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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.
|
||||
static_assert_size!(ItemKind, 72);
|
||||
static_assert_size!(ItemKind, 56);
|
||||
static_assert_size!(PathSegment, 40);
|
||||
static_assert_size!(Type, 32);
|
||||
// tidy-alphabetical-end
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user