@@ -1095,15 +1095,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1095
1095
let sp = hir. span ( id) ;
1096
1096
// `sp` only covers `T`, change it so that it covers
1097
1097
// `T:` when appropriate
1098
- let sp = if has_bounds {
1098
+ let is_impl_trait = bound_kind. to_string ( ) . starts_with ( "impl " ) ;
1099
+ let sp = if has_bounds && !is_impl_trait {
1099
1100
sp. to ( self . tcx
1100
1101
. sess
1101
1102
. source_map ( )
1102
1103
. next_point ( self . tcx . sess . source_map ( ) . next_point ( sp) ) )
1103
1104
} else {
1104
1105
sp
1105
1106
} ;
1106
- ( sp, has_bounds)
1107
+ ( sp, has_bounds, is_impl_trait )
1107
1108
} )
1108
1109
} else {
1109
1110
None
@@ -1136,25 +1137,33 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1136
1137
1137
1138
fn binding_suggestion < ' tcx , S : fmt:: Display > (
1138
1139
err : & mut DiagnosticBuilder < ' tcx > ,
1139
- type_param_span : Option < ( Span , bool ) > ,
1140
+ type_param_span : Option < ( Span , bool , bool ) > ,
1140
1141
bound_kind : GenericKind < ' tcx > ,
1141
1142
sub : S ,
1142
1143
) {
1143
- let consider = & format ! (
1144
- "consider adding an explicit lifetime bound `{}: {}`..." ,
1145
- bound_kind, sub
1144
+ let consider = format ! (
1145
+ "consider adding an explicit lifetime bound {}" ,
1146
+ if type_param_span. map( |( _, _, is_impl_trait) | is_impl_trait) . unwrap_or( false ) {
1147
+ format!( " `{}` to `{}`..." , sub, bound_kind)
1148
+ } else {
1149
+ format!( "`{}: {}`..." , bound_kind, sub)
1150
+ } ,
1146
1151
) ;
1147
- if let Some ( ( sp, has_lifetimes) ) = type_param_span {
1148
- let tail = if has_lifetimes { " + " } else { "" } ;
1149
- let suggestion = format ! ( "{}: {}{}" , bound_kind, sub, tail) ;
1152
+ if let Some ( ( sp, has_lifetimes, is_impl_trait) ) = type_param_span {
1153
+ let suggestion = if is_impl_trait {
1154
+ format ! ( "{} + {}" , bound_kind, sub)
1155
+ } else {
1156
+ let tail = if has_lifetimes { " + " } else { "" } ;
1157
+ format ! ( "{}: {}{}" , bound_kind, sub, tail)
1158
+ } ;
1150
1159
err. span_suggestion_short_with_applicability (
1151
1160
sp,
1152
- consider,
1161
+ & consider,
1153
1162
suggestion,
1154
1163
Applicability :: MaybeIncorrect , // Issue #41966
1155
1164
) ;
1156
1165
} else {
1157
- err. help ( consider) ;
1166
+ err. help ( & consider) ;
1158
1167
}
1159
1168
}
1160
1169
0 commit comments