@@ -1868,18 +1868,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1868
1868
// instead we suggest `T: Foo + Bar` in that case.
1869
1869
match hir. get ( id) {
1870
1870
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
+ }
1875
1876
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) =
1877
1878
ast_generics. bounds_span_for_suggestions ( def_id)
1878
1879
{
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 )
1880
1883
} else {
1881
- ( hir . span ( id ) . shrink_to_hi ( ) , false )
1884
+ ( param . span . shrink_to_hi ( ) , Introducer :: Colon )
1882
1885
} ;
1886
+ if matches ! (
1887
+ param. kind,
1888
+ hir:: GenericParamKind :: Type { synthetic: true , .. } ,
1889
+ ) {
1890
+ introducer = Introducer :: Plus
1891
+ }
1883
1892
let trait_def_ids: FxHashSet < DefId > = ast_generics
1884
1893
. bounds_for_param ( def_id)
1885
1894
. flat_map ( |bp| bp. bounds . iter ( ) )
@@ -1895,7 +1904,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1895
1904
candidates. iter ( ) . map ( |t| {
1896
1905
format ! (
1897
1906
"{} {}" ,
1898
- if has_bounds || impl_trait { " +" } else { ":" } ,
1907
+ match introducer {
1908
+ Introducer :: Plus => " +" ,
1909
+ Introducer :: Colon => ":" ,
1910
+ Introducer :: Nothing => "" ,
1911
+ } ,
1899
1912
self . tcx. def_path_str( t. def_id) ,
1900
1913
)
1901
1914
} ) ,
0 commit comments