@@ -525,7 +525,6 @@ fn clean_generic_param_def<'tcx>(
525525 (
526526 def. name ,
527527 GenericParamDefKind :: Type {
528- did : def. def_id ,
529528 bounds : ThinVec :: new ( ) , // These are filled in from the where-clauses.
530529 default : default. map ( Box :: new) ,
531530 synthetic,
@@ -557,7 +556,7 @@ fn clean_generic_param_def<'tcx>(
557556 ) ,
558557 } ;
559558
560- GenericParamDef { name, kind }
559+ GenericParamDef { name, def_id : def . def_id , kind }
561560}
562561
563562fn clean_generic_param < ' tcx > (
@@ -596,7 +595,6 @@ fn clean_generic_param<'tcx>(
596595 (
597596 param. name . ident ( ) . name ,
598597 GenericParamDefKind :: Type {
599- did : param. def_id . to_def_id ( ) ,
600598 bounds,
601599 default : default. map ( |t| clean_ty ( t, cx) ) . map ( Box :: new) ,
602600 synthetic,
@@ -614,7 +612,7 @@ fn clean_generic_param<'tcx>(
614612 ) ,
615613 } ;
616614
617- GenericParamDef { name, kind }
615+ GenericParamDef { name, def_id : param . def_id . to_def_id ( ) , kind }
618616}
619617
620618/// Synthetic type-parameters are inserted after normal ones.
@@ -646,8 +644,8 @@ pub(crate) fn clean_generics<'tcx>(
646644 let param = clean_generic_param ( cx, Some ( gens) , param) ;
647645 match param. kind {
648646 GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
649- GenericParamDefKind :: Type { did , ref bounds, .. } => {
650- cx. impl_trait_bounds . insert ( did . into ( ) , bounds. to_vec ( ) ) ;
647+ GenericParamDefKind :: Type { ref bounds, .. } => {
648+ cx. impl_trait_bounds . insert ( param . def_id . into ( ) , bounds. to_vec ( ) ) ;
651649 }
652650 GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
653651 }
@@ -1064,8 +1062,11 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib
10641062 match literal. kind {
10651063 ast:: LitKind :: Int ( a, _) => {
10661064 let gen = func. generics . params . remove ( 0 ) ;
1067- if let GenericParamDef { name, kind : GenericParamDefKind :: Const { ty, .. } } =
1068- gen
1065+ if let GenericParamDef {
1066+ name,
1067+ kind : GenericParamDefKind :: Const { ty, .. } ,
1068+ ..
1069+ } = gen
10691070 {
10701071 func. decl
10711072 . inputs
@@ -1169,7 +1170,7 @@ fn clean_fn_decl_with_args<'tcx>(
11691170 FnDecl { inputs : args, output, c_variadic : decl. c_variadic }
11701171}
11711172
1172- fn clean_fn_decl_from_did_and_sig < ' tcx > (
1173+ fn clean_poly_fn_sig < ' tcx > (
11731174 cx : & mut DocContext < ' tcx > ,
11741175 did : Option < DefId > ,
11751176 sig : ty:: PolyFnSig < ' tcx > ,
@@ -1359,16 +1360,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13591360 }
13601361 }
13611362 ty:: AssocKind :: Fn => {
1362- let sig = tcx. fn_sig ( assoc_item. def_id ) . instantiate_identity ( ) ;
1363- let mut generics = clean_ty_generics (
1364- cx,
1365- tcx. generics_of ( assoc_item. def_id ) ,
1366- tcx. explicit_predicates_of ( assoc_item. def_id ) ,
1367- ) ;
1368- // FIXME: This does not place parameters in source order (late-bound ones come last)
1369- generics. params . extend ( clean_bound_vars ( sig. bound_vars ( ) ) ) ;
1370-
1371- let mut decl = clean_fn_decl_from_did_and_sig ( cx, Some ( assoc_item. def_id ) , sig) ;
1363+ let mut item = inline:: build_function ( cx, assoc_item. def_id ) ;
13721364
13731365 if assoc_item. fn_has_self_parameter {
13741366 let self_ty = match assoc_item. container {
@@ -1377,12 +1369,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13771369 }
13781370 ty:: TraitContainer => tcx. types . self_param ,
13791371 } ;
1380- let self_arg_ty = sig. input ( 0 ) . skip_binder ( ) ;
1372+ let self_arg_ty =
1373+ tcx. fn_sig ( assoc_item. def_id ) . instantiate_identity ( ) . input ( 0 ) . skip_binder ( ) ;
13811374 if self_arg_ty == self_ty {
1382- decl. inputs . values [ 0 ] . type_ = Generic ( kw:: SelfUpper ) ;
1375+ item . decl . inputs . values [ 0 ] . type_ = Generic ( kw:: SelfUpper ) ;
13831376 } else if let ty:: Ref ( _, ty, _) = * self_arg_ty. kind ( ) {
13841377 if ty == self_ty {
1385- match decl. inputs . values [ 0 ] . type_ {
1378+ match item . decl . inputs . values [ 0 ] . type_ {
13861379 BorrowedRef { ref mut type_, .. } => * * type_ = Generic ( kw:: SelfUpper ) ,
13871380 _ => unreachable ! ( ) ,
13881381 }
@@ -1399,9 +1392,9 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13991392 ty:: ImplContainer => Some ( assoc_item. defaultness ( tcx) ) ,
14001393 ty:: TraitContainer => None ,
14011394 } ;
1402- MethodItem ( Box :: new ( Function { generics , decl } ) , defaultness)
1395+ MethodItem ( item , defaultness)
14031396 } else {
1404- TyMethodItem ( Box :: new ( Function { generics , decl } ) )
1397+ TyMethodItem ( item )
14051398 }
14061399 }
14071400 ty:: AssocKind :: Type => {
@@ -2109,7 +2102,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
21092102 ty:: FnDef ( ..) | ty:: FnPtr ( _) => {
21102103 // FIXME: should we merge the outer and inner binders somehow?
21112104 let sig = bound_ty. skip_binder ( ) . fn_sig ( cx. tcx ) ;
2112- let decl = clean_fn_decl_from_did_and_sig ( cx, None , sig) ;
2105+ let decl = clean_poly_fn_sig ( cx, None , sig) ;
21132106 let generic_params = clean_bound_vars ( sig. bound_vars ( ) ) ;
21142107
21152108 BareFunction ( Box :: new ( BareFunctionDecl {
@@ -2192,10 +2185,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
21922185 . iter ( )
21932186 . flat_map ( |pred| pred. bound_vars ( ) )
21942187 . filter_map ( |var| match var {
2195- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name) )
2188+ ty:: BoundVariableKind :: Region ( ty:: BrNamed ( def_id , name) )
21962189 if name != kw:: UnderscoreLifetime =>
21972190 {
2198- Some ( GenericParamDef :: lifetime ( name) )
2191+ Some ( GenericParamDef :: lifetime ( def_id , name) )
21992192 }
22002193 _ => None ,
22012194 } )
@@ -3167,20 +3160,22 @@ fn clean_bound_vars<'tcx>(
31673160 bound_vars
31683161 . into_iter ( )
31693162 . filter_map ( |var| match var {
3170- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name) )
3163+ ty:: BoundVariableKind :: Region ( ty:: BrNamed ( def_id , name) )
31713164 if name != kw:: UnderscoreLifetime =>
31723165 {
3173- Some ( GenericParamDef :: lifetime ( name) )
3166+ Some ( GenericParamDef :: lifetime ( def_id, name) )
3167+ }
3168+ ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( def_id, name) ) => {
3169+ Some ( GenericParamDef {
3170+ name,
3171+ def_id,
3172+ kind : GenericParamDefKind :: Type {
3173+ bounds : ThinVec :: new ( ) ,
3174+ default : None ,
3175+ synthetic : false ,
3176+ } ,
3177+ } )
31743178 }
3175- ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( did, name) ) => Some ( GenericParamDef {
3176- name,
3177- kind : GenericParamDefKind :: Type {
3178- did,
3179- bounds : ThinVec :: new ( ) ,
3180- default : None ,
3181- synthetic : false ,
3182- } ,
3183- } ) ,
31843179 // FIXME(non_lifetime_binders): Support higher-ranked const parameters.
31853180 ty:: BoundVariableKind :: Const => None ,
31863181 _ => None ,
0 commit comments