@@ -232,8 +232,7 @@ fn missing_items_err(
232
232
} ;
233
233
234
234
// Obtain the level of indentation ending in `sugg_sp`.
235
- let padding =
236
- tcx. sess . source_map ( ) . indentation_before ( sugg_sp) . unwrap_or_else ( || String :: new ( ) ) ;
235
+ let padding = tcx. sess . source_map ( ) . indentation_before ( sugg_sp) . unwrap_or_else ( String :: new) ;
237
236
let ( mut missing_trait_item, mut missing_trait_item_none, mut missing_trait_item_label) =
238
237
( Vec :: new ( ) , Vec :: new ( ) , Vec :: new ( ) ) ;
239
238
@@ -330,6 +329,7 @@ fn default_body_is_unstable(
330
329
fn bounds_from_generic_predicates < ' tcx > (
331
330
tcx : TyCtxt < ' tcx > ,
332
331
predicates : impl IntoIterator < Item = ( ty:: Clause < ' tcx > , Span ) > ,
332
+ assoc : Option < ty:: AssocItem > ,
333
333
) -> ( String , String ) {
334
334
let mut types: FxIndexMap < Ty < ' tcx > , Vec < DefId > > = FxIndexMap :: default ( ) ;
335
335
let mut projections = vec ! [ ] ;
@@ -354,8 +354,14 @@ fn bounds_from_generic_predicates<'tcx>(
354
354
355
355
let mut where_clauses = vec ! [ ] ;
356
356
let mut types_str = vec ! [ ] ;
357
- for ( ty, bounds) in types {
357
+ let generics = assoc. map ( |a| tcx. generics_of ( a. def_id ) ) . map ( |g| ( g. own_counts ( ) . types , g) ) ;
358
+ for ( idx, ( ty, bounds) ) in types. into_iter ( ) . enumerate ( ) {
358
359
if let ty:: Param ( _) = ty. kind ( ) {
360
+ if generics. is_some_and ( |( count, g) | {
361
+ idx + 1 <= count && g. param_at ( idx + 1 , tcx) . kind . is_synthetic ( )
362
+ } ) {
363
+ continue ;
364
+ }
359
365
let mut bounds_str = vec ! [ ] ;
360
366
for bound in bounds {
361
367
let mut projections_str = vec ! [ ] ;
@@ -472,10 +478,10 @@ fn fn_sig_suggestion<'tcx>(
472
478
let output = if !output. is_unit ( ) { format ! ( " -> {output}" ) } else { String :: new ( ) } ;
473
479
474
480
let safety = sig. safety . prefix_str ( ) ;
475
- let ( generics, where_clauses) = bounds_from_generic_predicates ( tcx, predicates) ;
481
+ let ( generics, where_clauses) = bounds_from_generic_predicates ( tcx, predicates, Some ( assoc ) ) ;
476
482
477
483
// FIXME: this is not entirely correct, as the lifetimes from borrowed params will
478
- // not be present in the `fn` definition, not will we account for renamed
484
+ // not be present in the `fn` definition, nor will we account for renamed
479
485
// lifetimes between the `impl` and the `trait`, but this should be good enough to
480
486
// fill in a significant portion of the missing code, and other subsequent
481
487
// suggestions can help the user fix the code.
@@ -511,6 +517,7 @@ fn suggestion_signature<'tcx>(
511
517
let ( generics, where_clauses) = bounds_from_generic_predicates (
512
518
tcx,
513
519
tcx. predicates_of ( assoc. def_id ) . instantiate_own ( tcx, args) ,
520
+ None ,
514
521
) ;
515
522
format ! ( "type {}{generics} = /* Type */{where_clauses};" , assoc. name( ) )
516
523
}
0 commit comments