@@ -785,31 +785,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
785785 // Get the `hir::Param` to verify whether it already has any bounds.
786786 // We do this to avoid suggesting code that ends up as `T: FooBar`,
787787 // instead we suggest `T: Foo + Bar` in that case.
788- let mut has_bounds = false ;
788+ let mut has_bounds = None ;
789789 let mut impl_trait = false ;
790790 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 ) ;
803801 }
804802 }
805803 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 ( ) )
813807 } else {
814808 sp
815809 } ;
@@ -825,7 +819,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
825819 param,
826820 if impl_trait { " +" } else { ":" } ,
827821 self . tcx. def_path_str( t. def_id) ,
828- if has_bounds { " +" } else { "" } ,
822+ if has_bounds. is_some ( ) { " + " } else { "" } ,
829823 ) ) ,
830824 Applicability :: MaybeIncorrect ,
831825 ) ;
0 commit comments