Rollup merge of #128263 - notriddle:notriddle/clean-up-again, r=GuillaumeGomez

rustdoc: use strategic ThinVec/Box to shrink `clean::ItemKind`
This commit is contained in:
Matthias Krüger 2024-07-28 13:42:19 +02:00 committed by GitHub
commit 3a4051cf3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 120 additions and 89 deletions

View File

@ -131,8 +131,8 @@ pub(crate) fn try_inline(
Res::Def(DefKind::Const, did) => { Res::Def(DefKind::Const, did) => {
record_extern_fqn(cx, did, ItemType::Constant); record_extern_fqn(cx, did, ItemType::Constant);
cx.with_param_env(did, |cx| { cx.with_param_env(did, |cx| {
let (generics, ty, ct) = build_const_item(cx, did); let ct = build_const_item(cx, did);
clean::ConstantItem(generics, Box::new(ty), ct) clean::ConstantItem(Box::new(ct))
}) })
} }
Res::Def(DefKind::Macro(kind), did) => { Res::Def(DefKind::Macro(kind), did) => {
@ -720,10 +720,7 @@ pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String {
} }
} }
fn build_const_item( fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
cx: &mut DocContext<'_>,
def_id: DefId,
) -> (clean::Generics, clean::Type, clean::Constant) {
let mut generics = let mut generics =
clean_ty_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id)); clean_ty_generics(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id));
clean::simplify::move_bounds_to_generic_parameters(&mut generics); clean::simplify::move_bounds_to_generic_parameters(&mut generics);
@ -733,17 +730,17 @@ fn build_const_item(
None, None,
None, None,
); );
(generics, ty, clean::Constant { kind: clean::ConstantKind::Extern { def_id } }) clean::Constant { generics, type_: ty, kind: clean::ConstantKind::Extern { def_id } }
} }
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static { fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
clean::Static { clean::Static {
type_: clean_middle_ty( type_: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity()), ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity()),
cx, cx,
Some(did), Some(did),
None, None,
), )),
mutability: if mutable { Mutability::Mut } else { Mutability::Not }, mutability: if mutable { Mutability::Mut } else { Mutability::Not },
expr: None, expr: None,
} }

View File

@ -287,23 +287,21 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
pub(crate) fn clean_const<'tcx>( pub(crate) fn clean_const<'tcx>(
constant: &hir::ConstArg<'tcx>, constant: &hir::ConstArg<'tcx>,
_cx: &mut DocContext<'tcx>, _cx: &mut DocContext<'tcx>,
) -> Constant { ) -> ConstantKind {
match &constant.kind { match &constant.kind {
hir::ConstArgKind::Path(qpath) => { hir::ConstArgKind::Path(qpath) => {
Constant { kind: ConstantKind::Path { path: qpath_to_string(&qpath).into() } } ConstantKind::Path { path: qpath_to_string(&qpath).into() }
}
hir::ConstArgKind::Anon(anon) => {
Constant { kind: ConstantKind::Anonymous { body: anon.body } }
} }
hir::ConstArgKind::Anon(anon) => ConstantKind::Anonymous { body: anon.body },
} }
} }
pub(crate) fn clean_middle_const<'tcx>( pub(crate) fn clean_middle_const<'tcx>(
constant: ty::Binder<'tcx, ty::Const<'tcx>>, constant: ty::Binder<'tcx, ty::Const<'tcx>>,
_cx: &mut DocContext<'tcx>, _cx: &mut DocContext<'tcx>,
) -> Constant { ) -> ConstantKind {
// FIXME: instead of storing the stringified expression, store `self` directly instead. // FIXME: instead of storing the stringified expression, store `self` directly instead.
Constant { kind: ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() } } ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() }
} }
pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Lifetime> { pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Lifetime> {
@ -1230,14 +1228,11 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
let local_did = trait_item.owner_id.to_def_id(); let local_did = trait_item.owner_id.to_def_id();
cx.with_param_env(local_did, |cx| { cx.with_param_env(local_did, |cx| {
let inner = match trait_item.kind { let inner = match trait_item.kind {
hir::TraitItemKind::Const(ty, Some(default)) => { hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(Box::new(Constant {
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)),
AssocConstItem( kind: ConstantKind::Local { def_id: local_did, body: default },
generics, type_: clean_ty(ty, cx),
Box::new(clean_ty(ty, cx)), })),
ConstantKind::Local { def_id: local_did, body: default },
)
}
hir::TraitItemKind::Const(ty, None) => { hir::TraitItemKind::Const(ty, None) => {
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
TyAssocConstItem(generics, Box::new(clean_ty(ty, cx))) TyAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
@ -1282,11 +1277,11 @@ pub(crate) fn clean_impl_item<'tcx>(
let local_did = impl_.owner_id.to_def_id(); let local_did = impl_.owner_id.to_def_id();
cx.with_param_env(local_did, |cx| { cx.with_param_env(local_did, |cx| {
let inner = match impl_.kind { let inner = match impl_.kind {
hir::ImplItemKind::Const(ty, expr) => { hir::ImplItemKind::Const(ty, expr) => AssocConstItem(Box::new(Constant {
let generics = clean_generics(impl_.generics, cx); generics: clean_generics(impl_.generics, cx),
let default = ConstantKind::Local { def_id: local_did, body: expr }; kind: ConstantKind::Local { def_id: local_did, body: expr },
AssocConstItem(generics, Box::new(clean_ty(ty, cx)), default) type_: clean_ty(ty, cx),
} })),
hir::ImplItemKind::Fn(ref sig, body) => { hir::ImplItemKind::Fn(ref sig, body) => {
let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body)); let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
let defaultness = cx.tcx.defaultness(impl_.owner_id); let defaultness = cx.tcx.defaultness(impl_.owner_id);
@ -1320,12 +1315,12 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
let tcx = cx.tcx; let tcx = cx.tcx;
let kind = match assoc_item.kind { let kind = match assoc_item.kind {
ty::AssocKind::Const => { ty::AssocKind::Const => {
let ty = Box::new(clean_middle_ty( let ty = clean_middle_ty(
ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()), ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()),
cx, cx,
Some(assoc_item.def_id), Some(assoc_item.def_id),
None, None,
)); );
let mut generics = clean_ty_generics( let mut generics = clean_ty_generics(
cx, cx,
@ -1339,9 +1334,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
ty::TraitContainer => tcx.defaultness(assoc_item.def_id).has_value(), ty::TraitContainer => tcx.defaultness(assoc_item.def_id).has_value(),
}; };
if provided { if provided {
AssocConstItem(generics, ty, ConstantKind::Extern { def_id: assoc_item.def_id }) AssocConstItem(Box::new(Constant {
generics,
kind: ConstantKind::Extern { def_id: assoc_item.def_id },
type_: ty,
}))
} else { } else {
TyAssocConstItem(generics, ty) TyAssocConstItem(generics, Box::new(ty))
} }
} }
ty::AssocKind::Fn => { ty::AssocKind::Fn => {
@ -1397,7 +1396,7 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
{ {
true true
} }
(GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &c.kind { (GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &**c {
ConstantKind::TyConst { expr } => **expr == *param.name.as_str(), ConstantKind::TyConst { expr } => **expr == *param.name.as_str(),
_ => false, _ => false,
}, },
@ -2744,14 +2743,16 @@ fn clean_maybe_renamed_item<'tcx>(
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id())); let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
cx.with_param_env(def_id, |cx| { cx.with_param_env(def_id, |cx| {
let kind = match item.kind { let kind = match item.kind {
ItemKind::Static(ty, mutability, body_id) => { ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) }) type_: Box::new(clean_ty(ty, cx)),
} mutability,
ItemKind::Const(ty, generics, body_id) => ConstantItem( expr: Some(body_id),
clean_generics(generics, cx), }),
Box::new(clean_ty(ty, cx)), ItemKind::Const(ty, generics, body_id) => ConstantItem(Box::new(Constant {
Constant { kind: ConstantKind::Local { body: body_id, def_id } }, generics: clean_generics(generics, cx),
), type_: clean_ty(ty, cx),
kind: ConstantKind::Local { body: body_id, def_id },
})),
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(), bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
generics: clean_generics(ty.generics, cx), generics: clean_generics(ty.generics, cx),
@ -3109,7 +3110,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
ForeignFunctionItem(Box::new(Function { decl, generics }), safety) ForeignFunctionItem(Box::new(Function { decl, generics }), safety)
} }
hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem( hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem(
Static { type_: clean_ty(ty, cx), mutability, expr: None }, Static { type_: Box::new(clean_ty(ty, cx)), mutability, expr: None },
safety, safety,
), ),
hir::ForeignItemKind::Type => ForeignTypeItem, hir::ForeignItemKind::Type => ForeignTypeItem,

View File

@ -852,9 +852,9 @@ pub(crate) enum ItemKind {
PrimitiveItem(PrimitiveType), PrimitiveItem(PrimitiveType),
/// A required associated constant in a trait declaration. /// A required associated constant in a trait declaration.
TyAssocConstItem(Generics, Box<Type>), TyAssocConstItem(Generics, Box<Type>),
ConstantItem(Generics, Box<Type>, Constant), ConstantItem(Box<Constant>),
/// An associated constant in a trait impl or a provided one in a trait declaration. /// An associated constant in a trait impl or a provided one in a trait declaration.
AssocConstItem(Generics, Box<Type>, ConstantKind), AssocConstItem(Box<Constant>),
/// A required associated type in a trait declaration. /// A required associated type in a trait declaration.
/// ///
/// The bounds may be non-empty if there is a `where` clause. /// The bounds may be non-empty if there is a `where` clause.
@ -888,7 +888,7 @@ pub(crate) fn inner_items(&self) -> impl Iterator<Item = &Item> {
| TypeAliasItem(_) | TypeAliasItem(_)
| OpaqueTyItem(_) | OpaqueTyItem(_)
| StaticItem(_) | StaticItem(_)
| ConstantItem(_, _, _) | ConstantItem(_)
| TraitAliasItem(_) | TraitAliasItem(_)
| TyMethodItem(_) | TyMethodItem(_)
| MethodItem(_, _) | MethodItem(_, _)
@ -922,7 +922,7 @@ pub(crate) fn is_non_assoc(&self) -> bool {
| TypeAliasItem(_) | TypeAliasItem(_)
| OpaqueTyItem(_) | OpaqueTyItem(_)
| StaticItem(_) | StaticItem(_)
| ConstantItem(_, _, _) | ConstantItem(_)
| TraitAliasItem(_) | TraitAliasItem(_)
| ForeignFunctionItem(_, _) | ForeignFunctionItem(_, _)
| ForeignStaticItem(_, _) | ForeignStaticItem(_, _)
@ -2050,7 +2050,7 @@ fn from(prim_ty: hir::PrimTy) -> PrimitiveType {
pub(crate) struct Struct { pub(crate) struct Struct {
pub(crate) ctor_kind: Option<CtorKind>, pub(crate) ctor_kind: Option<CtorKind>,
pub(crate) generics: Generics, pub(crate) generics: Generics,
pub(crate) fields: Vec<Item>, pub(crate) fields: ThinVec<Item>,
} }
impl Struct { impl Struct {
@ -2076,7 +2076,7 @@ pub(crate) fn has_stripped_entries(&self) -> bool {
/// only as a variant in an enum. /// only as a variant in an enum.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct VariantStruct { pub(crate) struct VariantStruct {
pub(crate) fields: Vec<Item>, pub(crate) fields: ThinVec<Item>,
} }
impl VariantStruct { impl VariantStruct {
@ -2110,7 +2110,7 @@ pub(crate) struct Variant {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) enum VariantKind { pub(crate) enum VariantKind {
CLike, CLike,
Tuple(Vec<Item>), Tuple(ThinVec<Item>),
Struct(VariantStruct), Struct(VariantStruct),
} }
@ -2246,7 +2246,7 @@ pub(crate) fn generics(&self) -> Option<Vec<&Type>> {
pub(crate) enum GenericArg { pub(crate) enum GenericArg {
Lifetime(Lifetime), Lifetime(Lifetime),
Type(Type), Type(Type),
Const(Box<Constant>), Const(Box<ConstantKind>),
Infer, Infer,
} }
@ -2359,20 +2359,22 @@ pub(crate) struct BareFunctionDecl {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct Static { pub(crate) struct Static {
pub(crate) type_: Type, pub(crate) type_: Box<Type>,
pub(crate) mutability: Mutability, pub(crate) mutability: Mutability,
pub(crate) expr: Option<BodyId>, pub(crate) expr: Option<BodyId>,
} }
#[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) struct Constant { pub(crate) struct Constant {
pub(crate) generics: Generics,
pub(crate) kind: ConstantKind, pub(crate) kind: ConstantKind,
pub(crate) type_: Type,
} }
#[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) enum Term { pub(crate) enum Term {
Type(Type), Type(Type),
Constant(Constant), Constant(ConstantKind),
} }
impl Term { impl Term {
@ -2594,7 +2596,7 @@ mod size_asserts {
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, 56);
static_assert_size!(ItemKind, 56); 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);
// tidy-alphabetical-end // tidy-alphabetical-end

View File

@ -79,7 +79,7 @@ fn fold_inner_recur(&mut self, kind: ItemKind) -> ItemKind {
| FunctionItem(_) | FunctionItem(_)
| OpaqueTyItem(_) | OpaqueTyItem(_)
| StaticItem(_) | StaticItem(_)
| ConstantItem(_, _, _) | ConstantItem(..)
| TraitAliasItem(_) | TraitAliasItem(_)
| TyMethodItem(_) | TyMethodItem(_)
| MethodItem(_, _) | MethodItem(_, _)

View File

@ -375,7 +375,7 @@ pub(crate) fn print(&self) -> impl Display + '_ {
} }
} }
impl clean::Constant { impl clean::ConstantKind {
pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display + '_ { pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl Display + '_ {
let expr = self.expr(tcx); let expr = self.expr(tcx);
display_fn( display_fn(

View File

@ -1090,22 +1090,26 @@ fn render_assoc_item(
clean::MethodItem(m, _) => { clean::MethodItem(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)
} }
kind @ (clean::TyAssocConstItem(generics, ty) | clean::AssocConstItem(generics, ty, _)) => { clean::TyAssocConstItem(generics, ty) => assoc_const(
assoc_const( w,
w, item,
item, generics,
generics, ty,
ty, None,
match kind { link,
clean::TyAssocConstItem(..) => None, if parent == ItemType::Trait { 4 } else { 0 },
clean::AssocConstItem(.., default) => Some(default), cx,
_ => unreachable!(), ),
}, clean::AssocConstItem(ci) => assoc_const(
link, w,
if parent == ItemType::Trait { 4 } else { 0 }, item,
cx, &ci.generics,
) &ci.type_,
} Some(&ci.kind),
link,
if parent == ItemType::Trait { 4 } else { 0 },
cx,
),
clean::TyAssocTypeItem(ref generics, ref bounds) => assoc_type( clean::TyAssocTypeItem(ref generics, ref bounds) => assoc_type(
w, w,
item, item,
@ -1690,8 +1694,7 @@ fn doc_impl_item(
w.write_str("</h4></section>"); w.write_str("</h4></section>");
} }
} }
kind @ (clean::TyAssocConstItem(generics, ty) clean::TyAssocConstItem(generics, ty) => {
| clean::AssocConstItem(generics, 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}\">");
@ -1706,11 +1709,29 @@ fn doc_impl_item(
item, item,
generics, generics,
ty, ty,
match kind { None,
clean::TyAssocConstItem(..) => None, link.anchor(if trait_.is_some() { &source_id } else { &id }),
clean::AssocConstItem(.., default) => Some(default), 0,
_ => unreachable!(), cx,
}, );
w.write_str("</h4></section>");
}
clean::AssocConstItem(ci) => {
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}\">");
render_rightside(w, cx, item, render_mode);
if trait_.is_some() {
// Anchors are only used on trait impls.
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
}
w.write_str("<h4 class=\"code-header\">");
assoc_const(
w,
item,
&ci.generics,
&ci.type_,
Some(&ci.kind),
link.anchor(if trait_.is_some() { &source_id } else { &id }), link.anchor(if trait_.is_some() { &source_id } else { &id }),
0, 0,
cx, cx,

View File

@ -267,7 +267,7 @@ pub(super) fn print_item(cx: &mut Context<'_>, item: &clean::Item, buf: &mut Buf
clean::PrimitiveItem(_) => item_primitive(buf, cx, item), clean::PrimitiveItem(_) => item_primitive(buf, cx, item),
clean::StaticItem(ref i) => item_static(buf, cx, item, i, None), clean::StaticItem(ref i) => item_static(buf, cx, item, i, None),
clean::ForeignStaticItem(ref i, safety) => item_static(buf, cx, item, i, Some(*safety)), clean::ForeignStaticItem(ref i, safety) => item_static(buf, cx, item, i, Some(*safety)),
clean::ConstantItem(generics, ty, c) => item_constant(buf, cx, item, generics, ty, c), clean::ConstantItem(ci) => item_constant(buf, cx, item, &ci.generics, &ci.type_, &ci.kind),
clean::ForeignTypeItem => item_foreign_type(buf, cx, item), clean::ForeignTypeItem => item_foreign_type(buf, cx, item),
clean::KeywordItem => item_keyword(buf, cx, item), clean::KeywordItem => item_keyword(buf, cx, item),
clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e), clean::OpaqueTyItem(ref e) => item_opaque_ty(buf, cx, item, e),
@ -1841,7 +1841,7 @@ fn item_constant(
it: &clean::Item, it: &clean::Item,
generics: &clean::Generics, generics: &clean::Generics,
ty: &clean::Type, ty: &clean::Type,
c: &clean::Constant, c: &clean::ConstantKind,
) { ) {
wrap_item(w, |w| { wrap_item(w, |w| {
let tcx = cx.tcx(); let tcx = cx.tcx();
@ -1911,7 +1911,7 @@ fn item_fields(
w: &mut Buffer, w: &mut Buffer,
cx: &mut Context<'_>, cx: &mut Context<'_>,
it: &clean::Item, it: &clean::Item,
fields: &Vec<clean::Item>, fields: &[clean::Item],
ctor_kind: Option<CtorKind>, ctor_kind: Option<CtorKind>,
) { ) {
let mut fields = fields let mut fields = fields

View File

@ -188,6 +188,16 @@ fn from_tcx(constant: clean::Constant, tcx: TyCtxt<'_>) -> Self {
} }
} }
impl FromWithTcx<clean::ConstantKind> for Constant {
// FIXME(generic_const_items): Add support for generic const items.
fn from_tcx(constant: clean::ConstantKind, tcx: TyCtxt<'_>) -> Self {
let expr = constant.expr(tcx);
let value = constant.value(tcx);
let is_literal = constant.is_literal(tcx);
Constant { expr, value, is_literal }
}
}
impl FromWithTcx<clean::AssocItemConstraint> for TypeBinding { impl FromWithTcx<clean::AssocItemConstraint> for TypeBinding {
fn from_tcx(constraint: clean::AssocItemConstraint, tcx: TyCtxt<'_>) -> Self { fn from_tcx(constraint: clean::AssocItemConstraint, tcx: TyCtxt<'_>) -> Self {
TypeBinding { TypeBinding {
@ -325,8 +335,8 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_tcx(tcx)), TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_tcx(tcx)),
OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into_tcx(tcx)), OpaqueTyItem(t) => ItemEnum::OpaqueTy(t.into_tcx(tcx)),
// FIXME(generic_const_items): Add support for generic free consts // FIXME(generic_const_items): Add support for generic free consts
ConstantItem(_generics, t, c) => { ConstantItem(ci) => {
ItemEnum::Constant { type_: (*t).into_tcx(tcx), const_: c.into_tcx(tcx) } ItemEnum::Constant { type_: ci.type_.into_tcx(tcx), const_: ci.kind.into_tcx(tcx) }
} }
MacroItem(m) => ItemEnum::Macro(m.source), MacroItem(m) => ItemEnum::Macro(m.source),
ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)), ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_tcx(tcx)),
@ -341,8 +351,8 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
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. // FIXME(generic_const_items): Add support for generic associated consts.
AssocConstItem(_generics, ty, default) => { AssocConstItem(ci) => {
ItemEnum::AssocConst { type_: (*ty).into_tcx(tcx), default: Some(default.expr(tcx)) } ItemEnum::AssocConst { type_: ci.type_.into_tcx(tcx), default: Some(ci.kind.expr(tcx)) }
} }
TyAssocTypeItem(g, b) => ItemEnum::AssocType { TyAssocTypeItem(g, b) => ItemEnum::AssocType {
generics: g.into_tcx(tcx), generics: g.into_tcx(tcx),
@ -829,7 +839,7 @@ fn from_tcx(opaque: clean::OpaqueTy, tcx: TyCtxt<'_>) -> Self {
impl FromWithTcx<clean::Static> for Static { impl FromWithTcx<clean::Static> for Static {
fn from_tcx(stat: clean::Static, tcx: TyCtxt<'_>) -> Self { fn from_tcx(stat: clean::Static, tcx: TyCtxt<'_>) -> Self {
Static { Static {
type_: stat.type_.into_tcx(tcx), type_: (*stat.type_).into_tcx(tcx),
mutable: stat.mutability == ast::Mutability::Mut, mutable: stat.mutability == ast::Mutability::Mut,
expr: stat expr: stat
.expr .expr

View File

@ -62,7 +62,7 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -
| clean::AssocTypeItem(..) | clean::AssocTypeItem(..)
| clean::TypeAliasItem(_) | clean::TypeAliasItem(_)
| clean::StaticItem(_) | clean::StaticItem(_)
| clean::ConstantItem(_, _, _) | clean::ConstantItem(..)
| clean::ExternCrateItem { .. } | clean::ExternCrateItem { .. }
| clean::ImportItem(_) | clean::ImportItem(_)
| clean::PrimitiveItem(_) | clean::PrimitiveItem(_)

View File

@ -28,7 +28,7 @@ fn visit_inner_recur(&mut self, kind: &ItemKind) {
| TypeAliasItem(_) | TypeAliasItem(_)
| OpaqueTyItem(_) | OpaqueTyItem(_)
| StaticItem(_) | StaticItem(_)
| ConstantItem(_, _, _) | ConstantItem(..)
| TraitAliasItem(_) | TraitAliasItem(_)
| TyMethodItem(_) | TyMethodItem(_)
| MethodItem(_, _) | MethodItem(_, _)