@@ -1001,7 +1001,12 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10011001 expression_ty : Ty < ' tcx > ,
10021002 expression_diverges : Diverges )
10031003 {
1004- self . coerce_inner ( fcx, cause, Some ( expression) , expression_ty, expression_diverges, None )
1004+ self . coerce_inner ( fcx,
1005+ cause,
1006+ Some ( expression) ,
1007+ expression_ty,
1008+ expression_diverges,
1009+ None , false )
10051010 }
10061011
10071012 /// Indicates that one of the inputs is a "forced unit". This
@@ -1019,14 +1024,16 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10191024 pub fn coerce_forced_unit < ' a > ( & mut self ,
10201025 fcx : & FnCtxt < ' a , ' gcx , ' tcx > ,
10211026 cause : & ObligationCause < ' tcx > ,
1022- augment_error : & mut FnMut ( & mut DiagnosticBuilder ) )
1027+ augment_error : & mut FnMut ( & mut DiagnosticBuilder ) ,
1028+ label_unit_as_expected : bool )
10231029 {
10241030 self . coerce_inner ( fcx,
10251031 cause,
10261032 None ,
10271033 fcx. tcx . mk_nil ( ) ,
10281034 Diverges :: Maybe ,
1029- Some ( augment_error) )
1035+ Some ( augment_error) ,
1036+ label_unit_as_expected)
10301037 }
10311038
10321039 /// The inner coercion "engine". If `expression` is `None`, this
@@ -1038,7 +1045,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10381045 expression : Option < & ' gcx hir:: Expr > ,
10391046 mut expression_ty : Ty < ' tcx > ,
10401047 expression_diverges : Diverges ,
1041- augment_error : Option < & mut FnMut ( & mut DiagnosticBuilder ) > )
1048+ augment_error : Option < & mut FnMut ( & mut DiagnosticBuilder ) > ,
1049+ label_expression_as_expected : bool )
10421050 {
10431051 // Incorporate whatever type inference information we have
10441052 // until now; in principle we might also want to process
@@ -1096,7 +1104,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10961104 // Another example is `break` with no argument expression.
10971105 assert ! ( expression_ty. is_nil( ) ) ;
10981106 assert ! ( expression_ty. is_nil( ) , "if let hack without unit type" ) ;
1099- fcx. eq_types ( true , cause, expression_ty, self . merged_ty ( ) )
1107+ fcx. eq_types ( label_expression_as_expected , cause, expression_ty, self . merged_ty ( ) )
11001108 . map ( |infer_ok| {
11011109 fcx. register_infer_ok_obligations ( infer_ok) ;
11021110 expression_ty
@@ -1119,11 +1127,11 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11191127 }
11201128 }
11211129 Err ( err) => {
1122- let ( expected, found) = if expression . is_none ( ) {
1130+ let ( expected, found) = if label_expression_as_expected {
11231131 // In the case where this is a "forced unit", like
11241132 // `break`, we want to call the `()` "expected"
11251133 // since it is implied by the syntax.
1126- assert ! ( expression_ty . is_nil ( ) ) ;
1134+ // (Note: not all force-units work this way.)"
11271135 ( expression_ty, self . final_ty . unwrap_or ( self . expected_ty ) )
11281136 } else {
11291137 // Otherwise, the "expected" type for error
0 commit comments