@@ -1163,18 +1163,20 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
11631163 fcx. try_coerce ( expression, expression_ty, self . expected_ty , AllowTwoPhase :: No )
11641164 } else {
11651165 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+ ) ,
11781180 }
11791181 }
11801182 } else {
@@ -1216,7 +1218,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
12161218 self . pushed += 1 ;
12171219 }
12181220 }
1219- Err ( err ) => {
1221+ Err ( coercion_error ) => {
12201222 let ( expected, found) = if label_expression_as_expected {
12211223 // In the case where this is a "forced unit", like
12221224 // `break`, we want to call the `()` "expected"
@@ -1232,41 +1234,42 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
12321234 ( self . final_ty . unwrap_or ( self . expected_ty ) , expression_ty)
12331235 } ;
12341236
1235- let mut db ;
1237+ let mut err ;
12361238 match cause. code {
12371239 ObligationCauseCode :: ReturnNoExpression => {
1238- db = struct_span_err ! (
1240+ err = struct_span_err ! (
12391241 fcx. tcx. sess, cause. span, E0069 ,
12401242 "`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 `()`" ) ;
12421244 }
12431245 ObligationCauseCode :: BlockTailExpression ( blk_id) => {
12441246 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 (
12461248 cause,
12471249 expected,
12481250 found,
1249- err ,
1251+ coercion_error ,
12501252 fcx,
12511253 parent_id,
12521254 expression. map ( |expr| ( expr, blk_id) ) ,
12531255 ) ;
12541256 }
12551257 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 ) ;
12581260 }
12591261 _ => {
1260- db = fcx. report_mismatched_types ( cause, expected, found, err ) ;
1262+ err = fcx. report_mismatched_types ( cause, expected, found, coercion_error ) ;
12611263 }
12621264 }
12631265
12641266 if let Some ( augment_error) = augment_error {
1265- augment_error ( & mut db ) ;
1267+ augment_error ( & mut err ) ;
12661268 }
12671269
12681270 // 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 ( ) ) ;
12701273
12711274 self . final_ty = Some ( fcx. tcx . types . err ) ;
12721275 }
@@ -1278,12 +1281,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
12781281 cause : & ObligationCause < ' tcx > ,
12791282 expected : Ty < ' tcx > ,
12801283 found : Ty < ' tcx > ,
1281- err : TypeError < ' tcx > ,
1284+ ty_err : TypeError < ' tcx > ,
12821285 fcx : & FnCtxt < ' a , ' tcx > ,
12831286 id : hir:: HirId ,
12841287 expression : Option < ( & ' tcx hir:: Expr , hir:: HirId ) > ,
12851288 ) -> 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 ) ;
12871290
12881291 let mut pointing_at_return_type = false ;
12891292 let mut return_sp = None ;
@@ -1294,14 +1297,24 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
12941297 let parent_id = fcx. tcx . hir ( ) . get_parent_node ( id) ;
12951298 let fn_decl = if let Some ( ( expr, blk_id) ) = expression {
12961299 pointing_at_return_type = fcx. suggest_mismatched_types_on_tail (
1297- & mut db ,
1300+ & mut err ,
12981301 expr,
12991302 expected,
13001303 found,
13011304 cause. span ,
13021305 blk_id,
13031306 ) ;
13041307 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+ }
13051318 fcx. get_node_fn_decl ( parent) . map ( |( fn_decl, _, is_main) | ( fn_decl, is_main) )
13061319 } else {
13071320 fcx. get_fn_decl ( parent_id)
@@ -1310,20 +1323,20 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
13101323 if let ( Some ( ( fn_decl, can_suggest) ) , _) = ( fn_decl, pointing_at_return_type) {
13111324 if expression. is_none ( ) {
13121325 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) ;
13141327 }
13151328 if !pointing_at_return_type {
13161329 return_sp = Some ( fn_decl. output . span ( ) ) ; // `impl Trait` return type
13171330 }
13181331 }
13191332 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 ! (
13221335 "...is found to be `{}` here" ,
13231336 fcx. resolve_type_vars_with_obligations( expected) ,
13241337 ) ) ;
13251338 }
1326- db
1339+ err
13271340 }
13281341
13291342 pub fn complete < ' a > ( self , fcx : & FnCtxt < ' a , ' tcx > ) -> Ty < ' tcx > {
0 commit comments