@@ -1868,18 +1868,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18681868 // instead we suggest `T: Foo + Bar` in that case.
18691869 match hir. get ( id) {
18701870 Node :: GenericParam ( param) => {
1871- let impl_trait = matches ! (
1872- param. kind,
1873- hir:: GenericParamKind :: Type { synthetic: true , .. } ,
1874- ) ;
1871+ enum Introducer {
1872+ Plus ,
1873+ Colon ,
1874+ Nothing ,
1875+ }
18751876 let ast_generics = hir. get_generics ( id. owner ) . unwrap ( ) ;
1876- let ( sp, has_bounds ) = if let Some ( span) =
1877+ let ( sp, mut introducer ) = if let Some ( span) =
18771878 ast_generics. bounds_span_for_suggestions ( def_id)
18781879 {
1879- ( span, true )
1880+ ( span, Introducer :: Plus )
1881+ } else if let Some ( colon_span) = param. colon_span {
1882+ ( colon_span. shrink_to_hi ( ) , Introducer :: Nothing )
18801883 } else {
1881- ( hir . span ( id ) . shrink_to_hi ( ) , false )
1884+ ( param . span . shrink_to_hi ( ) , Introducer :: Colon )
18821885 } ;
1886+ if matches ! (
1887+ param. kind,
1888+ hir:: GenericParamKind :: Type { synthetic: true , .. } ,
1889+ ) {
1890+ introducer = Introducer :: Plus
1891+ }
18831892 let trait_def_ids: FxHashSet < DefId > = ast_generics
18841893 . bounds_for_param ( def_id)
18851894 . flat_map ( |bp| bp. bounds . iter ( ) )
@@ -1895,7 +1904,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18951904 candidates. iter ( ) . map ( |t| {
18961905 format ! (
18971906 "{} {}" ,
1898- if has_bounds || impl_trait { " +" } else { ":" } ,
1907+ match introducer {
1908+ Introducer :: Plus => " +" ,
1909+ Introducer :: Colon => ":" ,
1910+ Introducer :: Nothing => "" ,
1911+ } ,
18991912 self . tcx. def_path_str( t. def_id) ,
19001913 )
19011914 } ) ,
0 commit comments