@@ -809,31 +809,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
809
809
// Get the `hir::Param` to verify whether it already has any bounds.
810
810
// We do this to avoid suggesting code that ends up as `T: FooBar`,
811
811
// instead we suggest `T: Foo + Bar` in that case.
812
- let mut has_bounds = false ;
812
+ let mut has_bounds = None ;
813
813
let mut impl_trait = false ;
814
814
if let Node :: GenericParam ( ref param) = hir. get ( id) {
815
- match param. kind {
816
- hir:: GenericParamKind :: Type { synthetic : Some ( _) , .. } => {
817
- // We've found `fn foo(x: impl Trait)` instead of
818
- // `fn foo<T>(x: T)`. We want to suggest the correct
819
- // `fn foo(x: impl Trait + TraitBound)` instead of
820
- // `fn foo<T: TraitBound>(x: T)`. (#63706)
821
- impl_trait = true ;
822
- has_bounds = param. bounds . len ( ) > 1 ;
823
- }
824
- _ => {
825
- has_bounds = !param. bounds . is_empty ( ) ;
826
- }
815
+ let kind = & param. kind ;
816
+ if let hir:: GenericParamKind :: Type { synthetic : Some ( _) , .. } = kind {
817
+ // We've found `fn foo(x: impl Trait)` instead of
818
+ // `fn foo<T>(x: T)`. We want to suggest the correct
819
+ // `fn foo(x: impl Trait + TraitBound)` instead of
820
+ // `fn foo<T: TraitBound>(x: T)`. (See #63706.)
821
+ impl_trait = true ;
822
+ has_bounds = param. bounds . get ( 1 ) ;
823
+ } else {
824
+ has_bounds = param. bounds . get ( 0 ) ;
827
825
}
828
826
}
829
827
let sp = hir. span ( id) ;
830
- // `sp` only covers `T`, change it so that it covers
831
- // `T:` when appropriate
832
- let sp = if has_bounds {
833
- sp. to ( self . tcx
834
- . sess
835
- . source_map ( )
836
- . next_point ( self . tcx . sess . source_map ( ) . next_point ( sp) ) )
828
+ // `sp` only covers `T`, change it so that it covers `T:` when appropriate.
829
+ let sp = if let Some ( first_bound) = has_bounds {
830
+ sp. until ( first_bound. span ( ) )
837
831
} else {
838
832
sp
839
833
} ;
@@ -849,7 +843,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
849
843
param,
850
844
if impl_trait { " +" } else { ":" } ,
851
845
self . tcx. def_path_str( t. def_id) ,
852
- if has_bounds { " +" } else { "" } ,
846
+ if has_bounds. is_some ( ) { " + " } else { "" } ,
853
847
) ) ,
854
848
Applicability :: MaybeIncorrect ,
855
849
) ;
0 commit comments