@@ -523,7 +523,6 @@ fn clean_generic_param_def<'tcx>(
523523 (
524524 def. name ,
525525 GenericParamDefKind :: Type {
526- did : def. def_id ,
527526 bounds : ThinVec :: new ( ) , // These are filled in from the where-clauses.
528527 default : default. map ( Box :: new) ,
529528 synthetic,
@@ -555,7 +554,7 @@ fn clean_generic_param_def<'tcx>(
555554 ) ,
556555 } ;
557556
558- GenericParamDef { name, kind }
557+ GenericParamDef { name, def_id : def . def_id , kind }
559558}
560559
561560fn clean_generic_param < ' tcx > (
@@ -594,7 +593,6 @@ fn clean_generic_param<'tcx>(
594593 (
595594 param. name . ident ( ) . name ,
596595 GenericParamDefKind :: Type {
597- did : param. def_id . to_def_id ( ) ,
598596 bounds,
599597 default : default. map ( |t| clean_ty ( t, cx) ) . map ( Box :: new) ,
600598 synthetic,
@@ -612,7 +610,7 @@ fn clean_generic_param<'tcx>(
612610 ) ,
613611 } ;
614612
615- GenericParamDef { name, kind }
613+ GenericParamDef { name, def_id : param . def_id . to_def_id ( ) , kind }
616614}
617615
618616/// Synthetic type-parameters are inserted after normal ones.
@@ -644,8 +642,8 @@ pub(crate) fn clean_generics<'tcx>(
644642 let param = clean_generic_param ( cx, Some ( gens) , param) ;
645643 match param. kind {
646644 GenericParamDefKind :: Lifetime { .. } => unreachable ! ( ) ,
647- GenericParamDefKind :: Type { did , ref bounds, .. } => {
648- cx. impl_trait_bounds . insert ( did . into ( ) , bounds. to_vec ( ) ) ;
645+ GenericParamDefKind :: Type { ref bounds, .. } => {
646+ cx. impl_trait_bounds . insert ( param . def_id . into ( ) , bounds. to_vec ( ) ) ;
649647 }
650648 GenericParamDefKind :: Const { .. } => unreachable ! ( ) ,
651649 }
@@ -1062,8 +1060,11 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[ast::Attrib
10621060 match literal. kind {
10631061 ast:: LitKind :: Int ( a, _) => {
10641062 let gen = func. generics . params . remove ( 0 ) ;
1065- if let GenericParamDef { name, kind : GenericParamDefKind :: Const { ty, .. } } =
1066- gen
1063+ if let GenericParamDef {
1064+ name,
1065+ kind : GenericParamDefKind :: Const { ty, .. } ,
1066+ ..
1067+ } = gen
10671068 {
10681069 func. decl
10691070 . inputs
@@ -1167,7 +1168,7 @@ fn clean_fn_decl_with_args<'tcx>(
11671168 FnDecl { inputs : args, output, c_variadic : decl. c_variadic }
11681169}
11691170
1170- fn clean_fn_decl_from_did_and_sig < ' tcx > (
1171+ fn clean_poly_fn_sig < ' tcx > (
11711172 cx : & mut DocContext < ' tcx > ,
11721173 did : Option < DefId > ,
11731174 sig : ty:: PolyFnSig < ' tcx > ,
@@ -1357,16 +1358,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13571358 }
13581359 }
13591360 ty:: AssocKind :: Fn => {
1360- let sig = tcx. fn_sig ( assoc_item. def_id ) . instantiate_identity ( ) ;
1361- let mut generics = clean_ty_generics (
1362- cx,
1363- tcx. generics_of ( assoc_item. def_id ) ,
1364- tcx. explicit_predicates_of ( assoc_item. def_id ) ,
1365- ) ;
1366- // FIXME: This does not place parameters in source order (late-bound ones come last)
1367- generics. params . extend ( clean_bound_vars ( sig. bound_vars ( ) ) ) ;
1368-
1369- let mut decl = clean_fn_decl_from_did_and_sig ( cx, Some ( assoc_item. def_id ) , sig) ;
1361+ let mut item = inline:: build_function ( cx, assoc_item. def_id ) ;
13701362
13711363 if assoc_item. fn_has_self_parameter {
13721364 let self_ty = match assoc_item. container {
@@ -1375,12 +1367,13 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13751367 }
13761368 ty:: TraitContainer => tcx. types . self_param ,
13771369 } ;
1378- let self_arg_ty = sig. input ( 0 ) . skip_binder ( ) ;
1370+ let self_arg_ty =
1371+ tcx. fn_sig ( assoc_item. def_id ) . instantiate_identity ( ) . input ( 0 ) . skip_binder ( ) ;
13791372 if self_arg_ty == self_ty {
1380- decl. inputs . values [ 0 ] . type_ = Generic ( kw:: SelfUpper ) ;
1373+ item . decl . inputs . values [ 0 ] . type_ = Generic ( kw:: SelfUpper ) ;
13811374 } else if let ty:: Ref ( _, ty, _) = * self_arg_ty. kind ( ) {
13821375 if ty == self_ty {
1383- match decl. inputs . values [ 0 ] . type_ {
1376+ match item . decl . inputs . values [ 0 ] . type_ {
13841377 BorrowedRef { ref mut type_, .. } => * * type_ = Generic ( kw:: SelfUpper ) ,
13851378 _ => unreachable ! ( ) ,
13861379 }
@@ -1397,9 +1390,9 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13971390 ty:: ImplContainer => Some ( assoc_item. defaultness ( tcx) ) ,
13981391 ty:: TraitContainer => None ,
13991392 } ;
1400- MethodItem ( Box :: new ( Function { generics , decl } ) , defaultness)
1393+ MethodItem ( item , defaultness)
14011394 } else {
1402- TyMethodItem ( Box :: new ( Function { generics , decl } ) )
1395+ TyMethodItem ( item )
14031396 }
14041397 }
14051398 ty:: AssocKind :: Type => {
@@ -2083,7 +2076,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
20832076 ty:: FnDef ( ..) | ty:: FnPtr ( _) => {
20842077 // FIXME: should we merge the outer and inner binders somehow?
20852078 let sig = bound_ty. skip_binder ( ) . fn_sig ( cx. tcx ) ;
2086- let decl = clean_fn_decl_from_did_and_sig ( cx, None , sig) ;
2079+ let decl = clean_poly_fn_sig ( cx, None , sig) ;
20872080 let generic_params = clean_bound_vars ( sig. bound_vars ( ) ) ;
20882081
20892082 BareFunction ( Box :: new ( BareFunctionDecl {
@@ -2166,10 +2159,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
21662159 . iter ( )
21672160 . flat_map ( |pred| pred. bound_vars ( ) )
21682161 . filter_map ( |var| match var {
2169- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name) )
2162+ ty:: BoundVariableKind :: Region ( ty:: BrNamed ( def_id , name) )
21702163 if name != kw:: UnderscoreLifetime =>
21712164 {
2172- Some ( GenericParamDef :: lifetime ( name) )
2165+ Some ( GenericParamDef :: lifetime ( def_id , name) )
21732166 }
21742167 _ => None ,
21752168 } )
@@ -3141,20 +3134,22 @@ fn clean_bound_vars<'tcx>(
31413134 bound_vars
31423135 . into_iter ( )
31433136 . filter_map ( |var| match var {
3144- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name) )
3137+ ty:: BoundVariableKind :: Region ( ty:: BrNamed ( def_id , name) )
31453138 if name != kw:: UnderscoreLifetime =>
31463139 {
3147- Some ( GenericParamDef :: lifetime ( name) )
3140+ Some ( GenericParamDef :: lifetime ( def_id, name) )
3141+ }
3142+ ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( def_id, name) ) => {
3143+ Some ( GenericParamDef {
3144+ name,
3145+ def_id,
3146+ kind : GenericParamDefKind :: Type {
3147+ bounds : ThinVec :: new ( ) ,
3148+ default : None ,
3149+ synthetic : false ,
3150+ } ,
3151+ } )
31483152 }
3149- ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( did, name) ) => Some ( GenericParamDef {
3150- name,
3151- kind : GenericParamDefKind :: Type {
3152- did,
3153- bounds : ThinVec :: new ( ) ,
3154- default : None ,
3155- synthetic : false ,
3156- } ,
3157- } ) ,
31583153 // FIXME(non_lifetime_binders): Support higher-ranked const parameters.
31593154 ty:: BoundVariableKind :: Const => None ,
31603155 _ => None ,
0 commit comments