@@ -1001,7 +1001,7 @@ 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, cause, Some ( expression) , expression_ty, expression_diverges, None , false )
10051005 }
10061006
10071007 /// Indicates that one of the inputs is a "forced unit". This
@@ -1019,14 +1019,16 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10191019 pub fn coerce_forced_unit < ' a > ( & mut self ,
10201020 fcx : & FnCtxt < ' a , ' gcx , ' tcx > ,
10211021 cause : & ObligationCause < ' tcx > ,
1022- augment_error : & mut FnMut ( & mut DiagnosticBuilder ) )
1022+ augment_error : & mut FnMut ( & mut DiagnosticBuilder ) ,
1023+ label_unit_as_expected : bool )
10231024 {
10241025 self . coerce_inner ( fcx,
10251026 cause,
10261027 None ,
10271028 fcx. tcx . mk_nil ( ) ,
10281029 Diverges :: Maybe ,
1029- Some ( augment_error) )
1030+ Some ( augment_error) ,
1031+ label_unit_as_expected)
10301032 }
10311033
10321034 /// The inner coercion "engine". If `expression` is `None`, this
@@ -1038,7 +1040,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
10381040 expression : Option < & ' gcx hir:: Expr > ,
10391041 mut expression_ty : Ty < ' tcx > ,
10401042 expression_diverges : Diverges ,
1041- augment_error : Option < & mut FnMut ( & mut DiagnosticBuilder ) > )
1043+ augment_error : Option < & mut FnMut ( & mut DiagnosticBuilder ) > ,
1044+ label_expression_as_expected : bool )
10421045 {
10431046 // Incorporate whatever type inference information we have
10441047 // until now; in principle we might also want to process
@@ -1119,11 +1122,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11191122 }
11201123 }
11211124 Err ( err) => {
1122- let ( expected, found) = if expression. is_none ( ) {
1123- // In the case where this is a "forced unit", like
1124- // `break`, we want to call the `()` "expected"
1125- // since it is implied by the syntax.
1126- assert ! ( expression_ty. is_nil( ) ) ;
1125+ let ( expected, found) = if label_expression_as_expected {
11271126 ( expression_ty, self . final_ty . unwrap_or ( self . expected_ty ) )
11281127 } else {
11291128 // Otherwise, the "expected" type for error
0 commit comments