@@ -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, did : 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, did : 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 . did . 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
@@ -1365,8 +1366,12 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
13651366 tcx. generics_of ( assoc_item. def_id ) ,
13661367 tcx. explicit_predicates_of ( assoc_item. def_id ) ,
13671368 ) ;
1368- // FIXME: This does not place parameters in source order (late-bound ones come last)
13691369 generics. params . extend ( clean_bound_vars ( sig. bound_vars ( ) ) ) ;
1370+ // FIXME(fmease): Does this work in the presence of synthetic params (impl-Trait, host effect)?
1371+ // FIXME(fmease): Optimization: Don't call def_ident_span on non-lifetime params!
1372+ if !sig. bound_vars ( ) . is_empty ( ) {
1373+ generics. params . sort_by_key ( |param| tcx. def_ident_span ( param. did ) . unwrap ( ) ) ;
1374+ }
13701375
13711376 let mut decl = clean_fn_decl_from_did_and_sig ( cx, Some ( assoc_item. def_id ) , sig) ;
13721377
@@ -2192,10 +2197,10 @@ pub(crate) fn clean_middle_ty<'tcx>(
21922197 . iter ( )
21932198 . flat_map ( |pred| pred. bound_vars ( ) )
21942199 . filter_map ( |var| match var {
2195- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name) )
2200+ ty:: BoundVariableKind :: Region ( ty:: BrNamed ( did , name) )
21962201 if name != kw:: UnderscoreLifetime =>
21972202 {
2198- Some ( GenericParamDef :: lifetime ( name) )
2203+ Some ( GenericParamDef :: lifetime ( did , name) )
21992204 }
22002205 _ => None ,
22012206 } )
@@ -3167,15 +3172,15 @@ fn clean_bound_vars<'tcx>(
31673172 bound_vars
31683173 . into_iter ( )
31693174 . filter_map ( |var| match var {
3170- ty:: BoundVariableKind :: Region ( ty:: BrNamed ( _ , name) )
3175+ ty:: BoundVariableKind :: Region ( ty:: BrNamed ( did , name) )
31713176 if name != kw:: UnderscoreLifetime =>
31723177 {
3173- Some ( GenericParamDef :: lifetime ( name) )
3178+ Some ( GenericParamDef :: lifetime ( did , name) )
31743179 }
31753180 ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( did, name) ) => Some ( GenericParamDef {
31763181 name,
3182+ did,
31773183 kind : GenericParamDefKind :: Type {
3178- did,
31793184 bounds : ThinVec :: new ( ) ,
31803185 default : None ,
31813186 synthetic : false ,
0 commit comments