@@ -1163,18 +1163,20 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1163
1163
fcx. try_coerce ( expression, expression_ty, self . expected_ty , AllowTwoPhase :: No )
1164
1164
} else {
1165
1165
match self . expressions {
1166
- Expressions :: Dynamic ( ref exprs) =>
1167
- fcx. try_find_coercion_lub ( cause,
1168
- exprs,
1169
- self . merged_ty ( ) ,
1170
- expression,
1171
- expression_ty) ,
1172
- Expressions :: UpFront ( ref coercion_sites) =>
1173
- fcx. try_find_coercion_lub ( cause,
1174
- & coercion_sites[ 0 ..self . pushed ] ,
1175
- self . merged_ty ( ) ,
1176
- expression,
1177
- expression_ty) ,
1166
+ Expressions :: Dynamic ( ref exprs) => fcx. try_find_coercion_lub (
1167
+ cause,
1168
+ exprs,
1169
+ self . merged_ty ( ) ,
1170
+ expression,
1171
+ expression_ty,
1172
+ ) ,
1173
+ Expressions :: UpFront ( ref coercion_sites) => fcx. try_find_coercion_lub (
1174
+ cause,
1175
+ & coercion_sites[ 0 ..self . pushed ] ,
1176
+ self . merged_ty ( ) ,
1177
+ expression,
1178
+ expression_ty,
1179
+ ) ,
1178
1180
}
1179
1181
}
1180
1182
} else {
@@ -1216,7 +1218,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1216
1218
self . pushed += 1 ;
1217
1219
}
1218
1220
}
1219
- Err ( err ) => {
1221
+ Err ( coercion_error ) => {
1220
1222
let ( expected, found) = if label_expression_as_expected {
1221
1223
// In the case where this is a "forced unit", like
1222
1224
// `break`, we want to call the `()` "expected"
@@ -1232,41 +1234,42 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1232
1234
( self . final_ty . unwrap_or ( self . expected_ty ) , expression_ty)
1233
1235
} ;
1234
1236
1235
- let mut db ;
1237
+ let mut err ;
1236
1238
match cause. code {
1237
1239
ObligationCauseCode :: ReturnNoExpression => {
1238
- db = struct_span_err ! (
1240
+ err = struct_span_err ! (
1239
1241
fcx. tcx. sess, cause. span, E0069 ,
1240
1242
"`return;` in a function whose return type is not `()`" ) ;
1241
- db . span_label ( cause. span , "return type is not `()`" ) ;
1243
+ err . span_label ( cause. span , "return type is not `()`" ) ;
1242
1244
}
1243
1245
ObligationCauseCode :: BlockTailExpression ( blk_id) => {
1244
1246
let parent_id = fcx. tcx . hir ( ) . get_parent_node ( blk_id) ;
1245
- db = self . report_return_mismatched_types (
1247
+ err = self . report_return_mismatched_types (
1246
1248
cause,
1247
1249
expected,
1248
1250
found,
1249
- err ,
1251
+ coercion_error ,
1250
1252
fcx,
1251
1253
parent_id,
1252
1254
expression. map ( |expr| ( expr, blk_id) ) ,
1253
1255
) ;
1254
1256
}
1255
1257
ObligationCauseCode :: ReturnValue ( id) => {
1256
- db = self . report_return_mismatched_types (
1257
- cause, expected, found, err , fcx, id, None ) ;
1258
+ err = self . report_return_mismatched_types (
1259
+ cause, expected, found, coercion_error , fcx, id, None ) ;
1258
1260
}
1259
1261
_ => {
1260
- db = fcx. report_mismatched_types ( cause, expected, found, err ) ;
1262
+ err = fcx. report_mismatched_types ( cause, expected, found, coercion_error ) ;
1261
1263
}
1262
1264
}
1263
1265
1264
1266
if let Some ( augment_error) = augment_error {
1265
- augment_error ( & mut db ) ;
1267
+ augment_error ( & mut err ) ;
1266
1268
}
1267
1269
1268
1270
// Error possibly reported in `check_assign` so avoid emitting error again.
1269
- db. emit_unless ( expression. filter ( |e| fcx. is_assign_to_bool ( e, expected) ) . is_some ( ) ) ;
1271
+ err. emit_unless ( expression. filter ( |e| fcx. is_assign_to_bool ( e, expected) )
1272
+ . is_some ( ) ) ;
1270
1273
1271
1274
self . final_ty = Some ( fcx. tcx . types . err ) ;
1272
1275
}
@@ -1278,12 +1281,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1278
1281
cause : & ObligationCause < ' tcx > ,
1279
1282
expected : Ty < ' tcx > ,
1280
1283
found : Ty < ' tcx > ,
1281
- err : TypeError < ' tcx > ,
1284
+ ty_err : TypeError < ' tcx > ,
1282
1285
fcx : & FnCtxt < ' a , ' tcx > ,
1283
1286
id : hir:: HirId ,
1284
1287
expression : Option < ( & ' tcx hir:: Expr , hir:: HirId ) > ,
1285
1288
) -> DiagnosticBuilder < ' a > {
1286
- let mut db = fcx. report_mismatched_types ( cause, expected, found, err ) ;
1289
+ let mut err = fcx. report_mismatched_types ( cause, expected, found, ty_err ) ;
1287
1290
1288
1291
let mut pointing_at_return_type = false ;
1289
1292
let mut return_sp = None ;
@@ -1294,14 +1297,24 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1294
1297
let parent_id = fcx. tcx . hir ( ) . get_parent_node ( id) ;
1295
1298
let fn_decl = if let Some ( ( expr, blk_id) ) = expression {
1296
1299
pointing_at_return_type = fcx. suggest_mismatched_types_on_tail (
1297
- & mut db ,
1300
+ & mut err ,
1298
1301
expr,
1299
1302
expected,
1300
1303
found,
1301
1304
cause. span ,
1302
1305
blk_id,
1303
1306
) ;
1304
1307
let parent = fcx. tcx . hir ( ) . get ( parent_id) ;
1308
+ if let ( Some ( match_expr) , true , false ) = (
1309
+ fcx. tcx . hir ( ) . get_match_if_cause ( expr. hir_id ) ,
1310
+ expected. is_unit ( ) ,
1311
+ pointing_at_return_type,
1312
+ ) {
1313
+ if match_expr. span . desugaring_kind ( ) . is_none ( ) {
1314
+ err. span_label ( match_expr. span , "expected this to be `()`" ) ;
1315
+ fcx. suggest_semicolon_at_end ( match_expr. span , & mut err) ;
1316
+ }
1317
+ }
1305
1318
fcx. get_node_fn_decl ( parent) . map ( |( fn_decl, _, is_main) | ( fn_decl, is_main) )
1306
1319
} else {
1307
1320
fcx. get_fn_decl ( parent_id)
@@ -1310,20 +1323,20 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1310
1323
if let ( Some ( ( fn_decl, can_suggest) ) , _) = ( fn_decl, pointing_at_return_type) {
1311
1324
if expression. is_none ( ) {
1312
1325
pointing_at_return_type |= fcx. suggest_missing_return_type (
1313
- & mut db , & fn_decl, expected, found, can_suggest) ;
1326
+ & mut err , & fn_decl, expected, found, can_suggest) ;
1314
1327
}
1315
1328
if !pointing_at_return_type {
1316
1329
return_sp = Some ( fn_decl. output . span ( ) ) ; // `impl Trait` return type
1317
1330
}
1318
1331
}
1319
1332
if let ( Some ( sp) , Some ( return_sp) ) = ( fcx. ret_coercion_span . borrow ( ) . as_ref ( ) , return_sp) {
1320
- db . span_label ( return_sp, "expected because this return type..." ) ;
1321
- db . span_label ( * sp, format ! (
1333
+ err . span_label ( return_sp, "expected because this return type..." ) ;
1334
+ err . span_label ( * sp, format ! (
1322
1335
"...is found to be `{}` here" ,
1323
1336
fcx. resolve_type_vars_with_obligations( expected) ,
1324
1337
) ) ;
1325
1338
}
1326
- db
1339
+ err
1327
1340
}
1328
1341
1329
1342
pub fn complete < ' a > ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Ty < ' tcx > {
0 commit comments