@@ -785,31 +785,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
785
785
// Get the `hir::Param` to verify whether it already has any bounds.
786
786
// We do this to avoid suggesting code that ends up as `T: FooBar`,
787
787
// instead we suggest `T: Foo + Bar` in that case.
788
- let mut has_bounds = false ;
788
+ let mut has_bounds = None ;
789
789
let mut impl_trait = false ;
790
790
if let Node :: GenericParam ( ref param) = hir. get ( id) {
791
- match param. kind {
792
- hir:: GenericParamKind :: Type { synthetic : Some ( _) , .. } => {
793
- // We've found `fn foo(x: impl Trait)` instead of
794
- // `fn foo<T>(x: T)`. We want to suggest the correct
795
- // `fn foo(x: impl Trait + TraitBound)` instead of
796
- // `fn foo<T: TraitBound>(x: T)`. (#63706)
797
- impl_trait = true ;
798
- has_bounds = param. bounds . len ( ) > 1 ;
799
- }
800
- _ => {
801
- has_bounds = !param. bounds . is_empty ( ) ;
802
- }
791
+ let kind = & param. kind ;
792
+ if let hir:: GenericParamKind :: Type { synthetic : Some ( _) , .. } = kind {
793
+ // We've found `fn foo(x: impl Trait)` instead of
794
+ // `fn foo<T>(x: T)`. We want to suggest the correct
795
+ // `fn foo(x: impl Trait + TraitBound)` instead of
796
+ // `fn foo<T: TraitBound>(x: T)`. (See #63706.)
797
+ impl_trait = true ;
798
+ has_bounds = param. bounds . get ( 1 ) ;
799
+ } else {
800
+ has_bounds = param. bounds . get ( 0 ) ;
803
801
}
804
802
}
805
803
let sp = hir. span ( id) ;
806
- // `sp` only covers `T`, change it so that it covers
807
- // `T:` when appropriate
808
- let sp = if has_bounds {
809
- sp. to ( self . tcx
810
- . sess
811
- . source_map ( )
812
- . next_point ( self . tcx . sess . source_map ( ) . next_point ( sp) ) )
804
+ // `sp` only covers `T`, change it so that it covers `T:` when appropriate.
805
+ let sp = if let Some ( first_bound) = has_bounds {
806
+ sp. until ( first_bound. span ( ) )
813
807
} else {
814
808
sp
815
809
} ;
@@ -825,7 +819,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
825
819
param,
826
820
if impl_trait { " +" } else { ":" } ,
827
821
self . tcx. def_path_str( t. def_id) ,
828
- if has_bounds { " +" } else { "" } ,
822
+ if has_bounds. is_some ( ) { " + " } else { "" } ,
829
823
) ) ,
830
824
Applicability :: MaybeIncorrect ,
831
825
) ;
0 commit comments