@@ -1218,7 +1218,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1218
1218
self . pushed += 1 ;
1219
1219
}
1220
1220
}
1221
- Err ( err ) => {
1221
+ Err ( coercion_error ) => {
1222
1222
let ( expected, found) = if label_expression_as_expected {
1223
1223
// In the case where this is a "forced unit", like
1224
1224
// `break`, we want to call the `()` "expected"
@@ -1234,41 +1234,42 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1234
1234
( self . final_ty . unwrap_or ( self . expected_ty ) , expression_ty)
1235
1235
} ;
1236
1236
1237
- let mut db ;
1237
+ let mut err ;
1238
1238
match cause. code {
1239
1239
ObligationCauseCode :: ReturnNoExpression => {
1240
- db = struct_span_err ! (
1240
+ err = struct_span_err ! (
1241
1241
fcx. tcx. sess, cause. span, E0069 ,
1242
1242
"`return;` in a function whose return type is not `()`" ) ;
1243
- db . span_label ( cause. span , "return type is not `()`" ) ;
1243
+ err . span_label ( cause. span , "return type is not `()`" ) ;
1244
1244
}
1245
1245
ObligationCauseCode :: BlockTailExpression ( blk_id) => {
1246
1246
let parent_id = fcx. tcx . hir ( ) . get_parent_node ( blk_id) ;
1247
- db = self . report_return_mismatched_types (
1247
+ err = self . report_return_mismatched_types (
1248
1248
cause,
1249
1249
expected,
1250
1250
found,
1251
- err ,
1251
+ coercion_error ,
1252
1252
fcx,
1253
1253
parent_id,
1254
1254
expression. map ( |expr| ( expr, blk_id) ) ,
1255
1255
) ;
1256
1256
}
1257
1257
ObligationCauseCode :: ReturnValue ( id) => {
1258
- db = self . report_return_mismatched_types (
1259
- cause, expected, found, err , fcx, id, None ) ;
1258
+ err = self . report_return_mismatched_types (
1259
+ cause, expected, found, coercion_error , fcx, id, None ) ;
1260
1260
}
1261
1261
_ => {
1262
- db = fcx. report_mismatched_types ( cause, expected, found, err ) ;
1262
+ err = fcx. report_mismatched_types ( cause, expected, found, coercion_error ) ;
1263
1263
}
1264
1264
}
1265
1265
1266
1266
if let Some ( augment_error) = augment_error {
1267
- augment_error ( & mut db ) ;
1267
+ augment_error ( & mut err ) ;
1268
1268
}
1269
1269
1270
1270
// Error possibly reported in `check_assign` so avoid emitting error again.
1271
- 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 ( ) ) ;
1272
1273
1273
1274
self . final_ty = Some ( fcx. tcx . types . err ) ;
1274
1275
}
@@ -1280,12 +1281,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1280
1281
cause : & ObligationCause < ' tcx > ,
1281
1282
expected : Ty < ' tcx > ,
1282
1283
found : Ty < ' tcx > ,
1283
- err : TypeError < ' tcx > ,
1284
+ ty_err : TypeError < ' tcx > ,
1284
1285
fcx : & FnCtxt < ' a , ' tcx > ,
1285
1286
id : hir:: HirId ,
1286
1287
expression : Option < ( & ' tcx hir:: Expr , hir:: HirId ) > ,
1287
1288
) -> DiagnosticBuilder < ' a > {
1288
- let mut db = fcx. report_mismatched_types ( cause, expected, found, err ) ;
1289
+ let mut err = fcx. report_mismatched_types ( cause, expected, found, ty_err ) ;
1289
1290
1290
1291
let mut pointing_at_return_type = false ;
1291
1292
let mut return_sp = None ;
@@ -1296,7 +1297,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1296
1297
let parent_id = fcx. tcx . hir ( ) . get_parent_node ( id) ;
1297
1298
let fn_decl = if let Some ( ( expr, blk_id) ) = expression {
1298
1299
pointing_at_return_type = fcx. suggest_mismatched_types_on_tail (
1299
- & mut db ,
1300
+ & mut err ,
1300
1301
expr,
1301
1302
expected,
1302
1303
found,
@@ -1310,8 +1311,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1310
1311
pointing_at_return_type,
1311
1312
) {
1312
1313
if match_expr. span . desugaring_kind ( ) . is_none ( ) {
1313
- db . span_label ( match_expr. span , "expected this to be `()`" ) ;
1314
- db . span_suggestion_short (
1314
+ err . span_laber ( match_expr. span , "expected this to be `()`" ) ;
1315
+ err . span_suggestion_short (
1315
1316
match_expr. span . shrink_to_hi ( ) ,
1316
1317
"consider using a semicolon here" ,
1317
1318
";" . to_string ( ) ,
@@ -1327,20 +1328,20 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
1327
1328
if let ( Some ( ( fn_decl, can_suggest) ) , _) = ( fn_decl, pointing_at_return_type) {
1328
1329
if expression. is_none ( ) {
1329
1330
pointing_at_return_type |= fcx. suggest_missing_return_type (
1330
- & mut db , & fn_decl, expected, found, can_suggest) ;
1331
+ & mut err , & fn_decl, expected, found, can_suggest) ;
1331
1332
}
1332
1333
if !pointing_at_return_type {
1333
1334
return_sp = Some ( fn_decl. output . span ( ) ) ; // `impl Trait` return type
1334
1335
}
1335
1336
}
1336
1337
if let ( Some ( sp) , Some ( return_sp) ) = ( fcx. ret_coercion_span . borrow ( ) . as_ref ( ) , return_sp) {
1337
- db . span_label ( return_sp, "expected because this return type..." ) ;
1338
- db . span_label ( * sp, format ! (
1338
+ err . span_label ( return_sp, "expected because this return type..." ) ;
1339
+ err . span_label ( * sp, format ! (
1339
1340
"...is found to be `{}` here" ,
1340
1341
fcx. resolve_type_vars_with_obligations( expected) ,
1341
1342
) ) ;
1342
1343
}
1343
- db
1344
+ err
1344
1345
}
1345
1346
1346
1347
pub fn complete < ' a > ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Ty < ' tcx > {
0 commit comments