@@ -287,23 +287,21 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
287287pub(crate) fn clean_const<'tcx>(
288288 constant: &hir::ConstArg<'tcx>,
289289 _cx: &mut DocContext<'tcx>,
290- ) -> Constant {
290+ ) -> ConstantKind {
291291 match &constant.kind {
292292 hir::ConstArgKind::Path(qpath) => {
293- Constant { kind: ConstantKind::Path { path: qpath_to_string(&qpath).into() } }
294- }
295- hir::ConstArgKind::Anon(anon) => {
296- Constant { kind: ConstantKind::Anonymous { body: anon.body } }
293+ ConstantKind::Path { path: qpath_to_string(&qpath).into() }
297294 }
295+ hir::ConstArgKind::Anon(anon) => ConstantKind::Anonymous { body: anon.body },
298296 }
299297}
300298
301299pub(crate) fn clean_middle_const<'tcx>(
302300 constant: ty::Binder<'tcx, ty::Const<'tcx>>,
303301 _cx: &mut DocContext<'tcx>,
304- ) -> Constant {
302+ ) -> ConstantKind {
305303 // FIXME: instead of storing the stringified expression, store `self` directly instead.
306- Constant { kind: ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() } }
304+ ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() }
307305}
308306
309307pub(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
12301228 let local_did = trait_item.owner_id.to_def_id();
12311229 cx.with_param_env(local_did, |cx| {
12321230 let inner = match trait_item.kind {
1233- hir::TraitItemKind::Const(ty, Some(default)) => {
1234- let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
1235- AssocConstItem(
1236- generics,
1237- Box::new(clean_ty(ty, cx)),
1238- ConstantKind::Local { def_id: local_did, body: default },
1239- )
1240- }
1231+ hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(Box::new(Constant {
1232+ generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)),
1233+ kind: ConstantKind::Local { def_id: local_did, body: default },
1234+ type_: clean_ty(ty, cx),
1235+ })),
12411236 hir::TraitItemKind::Const(ty, None) => {
12421237 let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
12431238 TyAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
@@ -1282,11 +1277,11 @@ pub(crate) fn clean_impl_item<'tcx>(
12821277 let local_did = impl_.owner_id.to_def_id();
12831278 cx.with_param_env(local_did, |cx| {
12841279 let inner = match impl_.kind {
1285- hir::ImplItemKind::Const(ty, expr) => {
1286- let generics = clean_generics(impl_.generics, cx);
1287- let default = ConstantKind::Local { def_id: local_did, body: expr };
1288- AssocConstItem(generics, Box::new( clean_ty(ty, cx)), default)
1289- }
1280+ hir::ImplItemKind::Const(ty, expr) => AssocConstItem(Box::new(Constant {
1281+ generics: clean_generics(impl_.generics, cx),
1282+ kind: ConstantKind::Local { def_id: local_did, body: expr },
1283+ type_: clean_ty(ty, cx),
1284+ })),
12901285 hir::ImplItemKind::Fn(ref sig, body) => {
12911286 let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
12921287 let defaultness = cx.tcx.defaultness(impl_.owner_id);
@@ -1320,12 +1315,12 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13201315 let tcx = cx.tcx;
13211316 let kind = match assoc_item.kind {
13221317 ty::AssocKind::Const => {
1323- let ty = Box::new( clean_middle_ty(
1318+ let ty = clean_middle_ty(
13241319 ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()),
13251320 cx,
13261321 Some(assoc_item.def_id),
13271322 None,
1328- )) ;
1323+ );
13291324
13301325 let mut generics = clean_ty_generics(
13311326 cx,
@@ -1339,9 +1334,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13391334 ty::TraitContainer => tcx.defaultness(assoc_item.def_id).has_value(),
13401335 };
13411336 if provided {
1342- AssocConstItem(generics, ty, ConstantKind::Extern { def_id: assoc_item.def_id })
1337+ AssocConstItem(Box::new(Constant {
1338+ generics,
1339+ kind: ConstantKind::Extern { def_id: assoc_item.def_id },
1340+ type_: ty,
1341+ }))
13431342 } else {
1344- TyAssocConstItem(generics, ty )
1343+ TyAssocConstItem(generics, Box::new(ty) )
13451344 }
13461345 }
13471346 ty::AssocKind::Fn => {
@@ -1397,7 +1396,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13971396 {
13981397 true
13991398 }
1400- (GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &c.kind {
1399+ (GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &**c {
14011400 ConstantKind::TyConst { expr } => **expr == *param.name.as_str(),
14021401 _ => false,
14031402 },
@@ -2744,14 +2743,16 @@ fn clean_maybe_renamed_item<'tcx>(
27442743 let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
27452744 cx.with_param_env(def_id, |cx| {
27462745 let kind = match item.kind {
2747- ItemKind::Static(ty, mutability, body_id) => {
2748- StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) })
2749- }
2750- ItemKind::Const(ty, generics, body_id) => ConstantItem(
2751- clean_generics(generics, cx),
2752- Box::new(clean_ty(ty, cx)),
2753- Constant { kind: ConstantKind::Local { body: body_id, def_id } },
2754- ),
2746+ ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
2747+ type_: Box::new(clean_ty(ty, cx)),
2748+ mutability,
2749+ expr: Some(body_id),
2750+ }),
2751+ ItemKind::Const(ty, generics, body_id) => ConstantItem(Box::new(Constant {
2752+ generics: clean_generics(generics, cx),
2753+ type_: clean_ty(ty, cx),
2754+ kind: ConstantKind::Local { body: body_id, def_id },
2755+ })),
27552756 ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
27562757 bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
27572758 generics: clean_generics(ty.generics, cx),
@@ -3109,7 +3110,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31093110 ForeignFunctionItem(Box::new(Function { decl, generics }), safety)
31103111 }
31113112 hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem(
3112- Static { type_: clean_ty(ty, cx), mutability, expr: None },
3113+ Static { type_: Box::new( clean_ty(ty, cx) ), mutability, expr: None },
31133114 safety,
31143115 ),
31153116 hir::ForeignItemKind::Type => ForeignTypeItem,
0 commit comments