@@ -2633,47 +2633,62 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2633
2633
Nothing ,
2634
2634
}
2635
2635
let ast_generics = hir. get_generics ( id. owner . def_id ) . unwrap ( ) ;
2636
- let ( sp, mut introducer) = if let Some ( span) =
2637
- ast_generics. bounds_span_for_suggestions ( def_id)
2638
- {
2639
- ( span, Introducer :: Plus )
2640
- } else if let Some ( colon_span) = param. colon_span {
2641
- ( colon_span. shrink_to_hi ( ) , Introducer :: Nothing )
2642
- } else {
2643
- ( param. span . shrink_to_hi ( ) , Introducer :: Colon )
2644
- } ;
2645
- if matches ! (
2646
- param. kind,
2647
- hir:: GenericParamKind :: Type { synthetic: true , .. } ,
2648
- ) {
2649
- introducer = Introducer :: Plus
2650
- }
2651
2636
let trait_def_ids: FxHashSet < DefId > = ast_generics
2652
2637
. bounds_for_param ( def_id)
2653
2638
. flat_map ( |bp| bp. bounds . iter ( ) )
2654
2639
. filter_map ( |bound| bound. trait_ref ( ) ?. trait_def_id ( ) )
2655
2640
. collect ( ) ;
2656
- if !candidates. iter ( ) . any ( |t| trait_def_ids. contains ( & t. def_id ) ) {
2657
- err. span_suggestions (
2658
- sp,
2659
- message ( format ! (
2660
- "restrict type parameter `{}` with" ,
2661
- param. name. ident( ) ,
2662
- ) ) ,
2641
+ if candidates. iter ( ) . any ( |t| trait_def_ids. contains ( & t. def_id ) ) {
2642
+ return ;
2643
+ }
2644
+ let msg = message ( format ! (
2645
+ "restrict type parameter `{}` with" ,
2646
+ param. name. ident( ) ,
2647
+ ) ) ;
2648
+ let bounds_span = ast_generics. bounds_span_for_suggestions ( def_id) ;
2649
+ if rcvr_ty. is_ref ( ) && param. is_impl_trait ( ) && bounds_span. is_some ( ) {
2650
+ err. multipart_suggestions (
2651
+ msg,
2663
2652
candidates. iter ( ) . map ( |t| {
2664
- format ! (
2665
- "{} {}" ,
2666
- match introducer {
2667
- Introducer :: Plus => " +" ,
2668
- Introducer :: Colon => ":" ,
2669
- Introducer :: Nothing => "" ,
2670
- } ,
2671
- self . tcx. def_path_str( t. def_id) ,
2672
- )
2653
+ vec ! [
2654
+ ( param. span. shrink_to_lo( ) , "(" . to_string( ) ) ,
2655
+ (
2656
+ bounds_span. unwrap( ) ,
2657
+ format!( " + {})" , self . tcx. def_path_str( t. def_id) ) ,
2658
+ ) ,
2659
+ ]
2673
2660
} ) ,
2674
2661
Applicability :: MaybeIncorrect ,
2675
2662
) ;
2663
+ return ;
2676
2664
}
2665
+
2666
+ let ( sp, introducer) = if let Some ( span) = bounds_span {
2667
+ ( span, Introducer :: Plus )
2668
+ } else if let Some ( colon_span) = param. colon_span {
2669
+ ( colon_span. shrink_to_hi ( ) , Introducer :: Nothing )
2670
+ } else if param. is_impl_trait ( ) {
2671
+ ( param. span . shrink_to_hi ( ) , Introducer :: Plus )
2672
+ } else {
2673
+ ( param. span . shrink_to_hi ( ) , Introducer :: Colon )
2674
+ } ;
2675
+
2676
+ err. span_suggestions (
2677
+ sp,
2678
+ msg,
2679
+ candidates. iter ( ) . map ( |t| {
2680
+ format ! (
2681
+ "{} {}" ,
2682
+ match introducer {
2683
+ Introducer :: Plus => " +" ,
2684
+ Introducer :: Colon => ":" ,
2685
+ Introducer :: Nothing => "" ,
2686
+ } ,
2687
+ self . tcx. def_path_str( t. def_id)
2688
+ )
2689
+ } ) ,
2690
+ Applicability :: MaybeIncorrect ,
2691
+ ) ;
2677
2692
return ;
2678
2693
}
2679
2694
Node :: Item ( hir:: Item {
0 commit comments