@@ -1199,7 +1199,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1199
1199
( self . final_ty . unwrap_or ( self . expected_ty ) , expression_ty)
1200
1200
} ;
1201
1201
1202
- let reason_label = "expected because of this statement" ;
1203
1202
let mut db;
1204
1203
match cause. code {
1205
1204
ObligationCauseCode :: ReturnNoExpression => {
@@ -1244,26 +1243,46 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1244
1243
// as prior return coercions would not be relevant (#57664).
1245
1244
let parent_id = fcx. tcx . hir ( ) . get_parent_node ( blk_id) ;
1246
1245
let parent = fcx. tcx . hir ( ) . get ( fcx. tcx . hir ( ) . get_parent_node ( parent_id) ) ;
1247
- if fcx. get_node_fn_decl ( parent) . is_some ( ) && !pointing_at_return_type {
1246
+ if let ( Some ( ( fn_decl, _, _) ) , false ) = (
1247
+ fcx. get_node_fn_decl ( parent) ,
1248
+ pointing_at_return_type,
1249
+ ) {
1248
1250
if let Some ( sp) = fcx. ret_coercion_span . borrow ( ) . as_ref ( ) {
1249
- db. span_label ( * sp, reason_label) ;
1251
+ db. span_label (
1252
+ fn_decl. output . span ( ) ,
1253
+ "expected because this return type..." ,
1254
+ ) ;
1255
+ db. span_label ( * sp, format ! (
1256
+ "...is found to be `{}` here" ,
1257
+ fcx. resolve_type_vars_with_obligations( expected) ,
1258
+ ) ) ;
1250
1259
}
1251
1260
}
1252
1261
}
1253
1262
ObligationCauseCode :: ReturnType ( _id) => {
1254
1263
db = fcx. report_mismatched_types ( cause, expected, found, err) ;
1255
1264
let _id = fcx. tcx . hir ( ) . get_parent_node ( _id) ;
1256
1265
let mut pointing_at_return_type = false ;
1266
+ let mut return_sp = None ;
1257
1267
if let Some ( ( fn_decl, can_suggest) ) = fcx. get_fn_decl ( _id) {
1258
1268
pointing_at_return_type = fcx. suggest_missing_return_type (
1259
1269
& mut db, & fn_decl, expected, found, can_suggest) ;
1270
+ if !pointing_at_return_type {
1271
+ return_sp = Some ( fn_decl. output . span ( ) ) ; // `impl Trait` return type
1272
+ }
1260
1273
}
1261
1274
if let ( Some ( sp) , false ) = (
1262
1275
fcx. ret_coercion_span . borrow ( ) . as_ref ( ) ,
1263
1276
pointing_at_return_type,
1264
1277
) {
1265
- if !sp. overlaps ( cause. span ) {
1266
- db. span_label ( * sp, reason_label) ;
1278
+ if let Some ( return_sp) = return_sp {
1279
+ db. span_label ( return_sp, "expected because this return type..." ) ;
1280
+ db. span_label ( * sp, format ! (
1281
+ "...is found to be `{}` here" ,
1282
+ fcx. resolve_type_vars_with_obligations( expected) ,
1283
+ ) ) ;
1284
+ } else if !sp. overlaps ( cause. span ) {
1285
+ db. span_label ( * sp, "expected because of this statement" ) ;
1267
1286
}
1268
1287
}
1269
1288
}
0 commit comments