@@ -306,24 +306,23 @@ pub(crate) fn clean_precise_capturing_arg(
306306 }
307307}
308308
309- pub ( crate ) fn clean_const < ' tcx > (
310- constant : & hir:: ConstArg < ' tcx > ,
311- // Used for mgca representation of const item bodies.
312- parent_if_item_body : Option < DefId > ,
313- _cx : & mut DocContext < ' tcx > ,
309+ pub ( crate ) fn clean_const_item_rhs < ' tcx > (
310+ ct_rhs : hir:: ConstItemRhs < ' tcx > ,
311+ parent : DefId ,
314312) -> ConstantKind {
313+ match ct_rhs {
314+ hir:: ConstItemRhs :: Body ( body) => ConstantKind :: Local { def_id : parent, body } ,
315+ hir:: ConstItemRhs :: TypeConst ( ct) => clean_const ( ct) ,
316+ }
317+ }
318+
319+ pub ( crate ) fn clean_const < ' tcx > ( constant : & hir:: ConstArg < ' tcx > ) -> ConstantKind {
315320 match & constant. kind {
316321 hir:: ConstArgKind :: Path ( qpath) => {
317322 ConstantKind :: Path { path : qpath_to_string ( qpath) . into ( ) }
318323 }
319- hir:: ConstArgKind :: Anon ( anon) => {
320- if let Some ( def_id) = parent_if_item_body {
321- ConstantKind :: Local { def_id, body : anon. body }
322- } else {
323- ConstantKind :: Anonymous { body : anon. body }
324- }
325- }
326- hir:: ConstArgKind :: Infer ( ..) => ConstantKind :: Infer ,
324+ hir:: ConstArgKind :: Anon ( anon) => ConstantKind :: Anonymous { body : anon. body } ,
325+ hir:: ConstArgKind :: Infer ( ..) | hir:: ConstArgKind :: Error ( ..) => ConstantKind :: Infer ,
327326 }
328327}
329328
@@ -1202,7 +1201,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
12021201 hir:: TraitItemKind :: Const ( ty, Some ( default) ) => {
12031202 ProvidedAssocConstItem ( Box :: new ( Constant {
12041203 generics : enter_impl_trait ( cx, |cx| clean_generics ( trait_item. generics , cx) ) ,
1205- kind : clean_const ( default, Some ( local_did) , cx ) ,
1204+ kind : clean_const_item_rhs ( default, local_did) ,
12061205 type_ : clean_ty ( ty, cx) ,
12071206 } ) )
12081207 }
@@ -1252,7 +1251,7 @@ pub(crate) fn clean_impl_item<'tcx>(
12521251 let inner = match impl_. kind {
12531252 hir:: ImplItemKind :: Const ( ty, expr) => ImplAssocConstItem ( Box :: new ( Constant {
12541253 generics : clean_generics ( impl_. generics , cx) ,
1255- kind : clean_const ( expr, Some ( local_did) , cx ) ,
1254+ kind : clean_const_item_rhs ( expr, local_did) ,
12561255 type_ : clean_ty ( ty, cx) ,
12571256 } ) ) ,
12581257 hir:: ImplItemKind :: Fn ( ref sig, body) => {
@@ -1807,7 +1806,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18071806 // results in an ICE while manually constructing the constant and using `eval`
18081807 // does nothing for `ConstKind::Param`.
18091808 let length = match const_arg. kind {
1810- hir:: ConstArgKind :: Infer ( ..) => "_" . to_string ( ) ,
1809+ hir:: ConstArgKind :: Infer ( ..) | hir :: ConstArgKind :: Error ( .. ) => "_" . to_string ( ) ,
18111810 hir:: ConstArgKind :: Anon ( hir:: AnonConst { def_id, .. } ) => {
18121811 let ct = lower_const_arg_for_rustdoc ( cx. tcx , const_arg, FeedConstTy :: No ) ;
18131812 let typing_env = ty:: TypingEnv :: post_analysis ( cx. tcx , * def_id) ;
@@ -2524,7 +2523,7 @@ fn clean_generic_args<'tcx>(
25242523 hir:: GenericArg :: Lifetime ( _) => GenericArg :: Lifetime ( Lifetime :: elided ( ) ) ,
25252524 hir:: GenericArg :: Type ( ty) => GenericArg :: Type ( clean_ty ( ty. as_unambig_ty ( ) , cx) ) ,
25262525 hir:: GenericArg :: Const ( ct) => {
2527- GenericArg :: Const ( Box :: new ( clean_const ( ct. as_unambig_ct ( ) , None , cx ) ) )
2526+ GenericArg :: Const ( Box :: new ( clean_const ( ct. as_unambig_ct ( ) ) ) )
25282527 }
25292528 hir:: GenericArg :: Infer ( _inf) => GenericArg :: Infer ,
25302529 } )
@@ -2796,7 +2795,7 @@ fn clean_maybe_renamed_item<'tcx>(
27962795 ItemKind :: Const ( _, generics, ty, body) => ConstantItem ( Box :: new ( Constant {
27972796 generics : clean_generics ( generics, cx) ,
27982797 type_ : clean_ty ( ty, cx) ,
2799- kind : clean_const ( body, Some ( def_id) , cx ) ,
2798+ kind : clean_const_item_rhs ( body, def_id) ,
28002799 } ) ) ,
28012800 ItemKind :: TyAlias ( _, generics, ty) => {
28022801 * cx. current_type_aliases . entry ( def_id) . or_insert ( 0 ) += 1 ;
0 commit comments