@@ -466,11 +466,23 @@ fn clean_middle_term<'tcx>(
466466 }
467467}
468468
469- fn clean_hir_term < ' tcx > ( term : & hir:: Term < ' tcx > , cx : & mut DocContext < ' tcx > ) -> Term {
469+ fn clean_hir_term < ' tcx > (
470+ assoc_item : Option < DefId > ,
471+ term : & hir:: Term < ' tcx > ,
472+ span : rustc_span:: Span ,
473+ cx : & mut DocContext < ' tcx > ,
474+ ) -> Term {
470475 match term {
471476 hir:: Term :: Ty ( ty) => Term :: Type ( clean_ty ( ty, cx) ) ,
472477 hir:: Term :: Const ( c) => {
473- let ct = lower_const_arg_for_rustdoc ( cx. tcx , c, FeedConstTy :: No ) ;
478+ let ty = if let Some ( assoc_item) = assoc_item {
479+ // FIXME(generic_const_items): this should instantiate with the alias item's args
480+ cx. tcx . type_of ( assoc_item) . instantiate_identity ( )
481+ } else {
482+ Ty :: new_error_with_message ( cx. tcx , span, "cannot find the associated constant" )
483+ } ;
484+
485+ let ct = lower_const_arg_for_rustdoc ( cx. tcx , c, FeedConstTy :: WithTy ( ty) ) ;
474486 Term :: Constant ( clean_middle_const ( ty:: Binder :: dummy ( ct) , cx) )
475487 }
476488 }
@@ -647,7 +659,14 @@ fn clean_generic_param<'tcx>(
647659 GenericParamDefKind :: Const {
648660 ty : Box :: new ( clean_ty ( ty, cx) ) ,
649661 default : default. map ( |ct| {
650- Box :: new ( lower_const_arg_for_rustdoc ( cx. tcx , ct, FeedConstTy :: No ) . to_string ( ) )
662+ Box :: new (
663+ lower_const_arg_for_rustdoc (
664+ cx. tcx ,
665+ ct,
666+ FeedConstTy :: WithTy ( lower_ty ( cx. tcx , ty) ) ,
667+ )
668+ . to_string ( ) ,
669+ )
651670 } ) ,
652671 } ,
653672 ) ,
@@ -1528,7 +1547,7 @@ fn first_non_private_clean_path<'tcx>(
15281547 && path_last. args . is_some ( )
15291548 {
15301549 assert ! ( new_path_last. args. is_empty( ) ) ;
1531- new_path_last. args = clean_generic_args ( path_last_args, cx) ;
1550+ new_path_last. args = clean_generic_args ( None , path_last_args, cx) ;
15321551 }
15331552 new_clean_path
15341553}
@@ -1809,7 +1828,11 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18091828 let length = match const_arg. kind {
18101829 hir:: ConstArgKind :: Infer ( ..) | hir:: ConstArgKind :: Error ( ..) => "_" . to_string ( ) ,
18111830 hir:: ConstArgKind :: Anon ( hir:: AnonConst { def_id, .. } ) => {
1812- let ct = lower_const_arg_for_rustdoc ( cx. tcx , const_arg, FeedConstTy :: No ) ;
1831+ let ct = lower_const_arg_for_rustdoc (
1832+ cx. tcx ,
1833+ const_arg,
1834+ FeedConstTy :: WithTy ( cx. tcx . types . usize ) ,
1835+ ) ;
18131836 let typing_env = ty:: TypingEnv :: post_analysis ( cx. tcx , * def_id) ;
18141837 let ct = cx. tcx . normalize_erasing_regions ( typing_env, ct) ;
18151838 print_const ( cx, ct)
@@ -1819,7 +1842,11 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18191842 | hir:: ConstArgKind :: TupleCall ( ..)
18201843 | hir:: ConstArgKind :: Tup ( ..)
18211844 | hir:: ConstArgKind :: Literal ( ..) => {
1822- let ct = lower_const_arg_for_rustdoc ( cx. tcx , const_arg, FeedConstTy :: No ) ;
1845+ let ct = lower_const_arg_for_rustdoc (
1846+ cx. tcx ,
1847+ const_arg,
1848+ FeedConstTy :: WithTy ( cx. tcx . types . usize ) ,
1849+ ) ;
18231850 print_const ( cx, ct)
18241851 }
18251852 } ;
@@ -2512,6 +2539,7 @@ fn clean_path<'tcx>(path: &hir::Path<'tcx>, cx: &mut DocContext<'tcx>) -> Path {
25122539}
25132540
25142541fn clean_generic_args < ' tcx > (
2542+ trait_did : Option < DefId > ,
25152543 generic_args : & hir:: GenericArgs < ' tcx > ,
25162544 cx : & mut DocContext < ' tcx > ,
25172545) -> GenericArgs {
@@ -2535,7 +2563,13 @@ fn clean_generic_args<'tcx>(
25352563 let constraints = generic_args
25362564 . constraints
25372565 . iter ( )
2538- . map ( |c| clean_assoc_item_constraint ( c, cx) )
2566+ . map ( |c| {
2567+ clean_assoc_item_constraint (
2568+ trait_did. expect ( "only trait ref has constraints" ) ,
2569+ c,
2570+ cx,
2571+ )
2572+ } )
25392573 . collect :: < ThinVec < _ > > ( ) ;
25402574 GenericArgs :: AngleBracketed { args, constraints }
25412575 }
@@ -2558,7 +2592,9 @@ fn clean_path_segment<'tcx>(
25582592 path : & hir:: PathSegment < ' tcx > ,
25592593 cx : & mut DocContext < ' tcx > ,
25602594) -> PathSegment {
2561- PathSegment { name : path. ident . name , args : clean_generic_args ( path. args ( ) , cx) }
2595+ let trait_did =
2596+ if let hir:: def:: Res :: Def ( DefKind :: Trait , did) = path. res { Some ( did) } else { None } ;
2597+ PathSegment { name : path. ident . name , args : clean_generic_args ( trait_did, path. args ( ) , cx) }
25622598}
25632599
25642600fn clean_bare_fn_ty < ' tcx > (
@@ -3122,17 +3158,29 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
31223158}
31233159
31243160fn clean_assoc_item_constraint < ' tcx > (
3161+ trait_did : DefId ,
31253162 constraint : & hir:: AssocItemConstraint < ' tcx > ,
31263163 cx : & mut DocContext < ' tcx > ,
31273164) -> AssocItemConstraint {
31283165 AssocItemConstraint {
31293166 assoc : PathSegment {
31303167 name : constraint. ident . name ,
3131- args : clean_generic_args ( constraint. gen_args , cx) ,
3168+ args : clean_generic_args ( None , constraint. gen_args , cx) ,
31323169 } ,
31333170 kind : match constraint. kind {
31343171 hir:: AssocItemConstraintKind :: Equality { ref term } => {
3135- AssocItemConstraintKind :: Equality { term : clean_hir_term ( term, cx) }
3172+ let assoc_tag = match term {
3173+ hir:: Term :: Ty ( _) => ty:: AssocTag :: Type ,
3174+ hir:: Term :: Const ( _) => ty:: AssocTag :: Const ,
3175+ } ;
3176+ let assoc_item = cx
3177+ . tcx
3178+ . associated_items ( trait_did)
3179+ . find_by_ident_and_kind ( cx. tcx , constraint. ident , assoc_tag, trait_did)
3180+ . map ( |item| item. def_id ) ;
3181+ AssocItemConstraintKind :: Equality {
3182+ term : clean_hir_term ( assoc_item, term, constraint. span , cx) ,
3183+ }
31363184 }
31373185 hir:: AssocItemConstraintKind :: Bound { bounds } => AssocItemConstraintKind :: Bound {
31383186 bounds : bounds. iter ( ) . filter_map ( |b| clean_generic_bound ( b, cx) ) . collect ( ) ,
0 commit comments