@@ -1001,7 +1001,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1001
1001
expression_ty : Ty < ' tcx > ,
1002
1002
expression_diverges : Diverges )
1003
1003
{
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 )
1005
1005
}
1006
1006
1007
1007
/// 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>
1019
1019
pub fn coerce_forced_unit < ' a > ( & mut self ,
1020
1020
fcx : & FnCtxt < ' a , ' gcx , ' tcx > ,
1021
1021
cause : & ObligationCause < ' tcx > ,
1022
- augment_error : & mut FnMut ( & mut DiagnosticBuilder ) )
1022
+ augment_error : & mut FnMut ( & mut DiagnosticBuilder ) ,
1023
+ label_unit_as_expected : bool )
1023
1024
{
1024
1025
self . coerce_inner ( fcx,
1025
1026
cause,
1026
1027
None ,
1027
1028
fcx. tcx . mk_nil ( ) ,
1028
1029
Diverges :: Maybe ,
1029
- Some ( augment_error) )
1030
+ Some ( augment_error) ,
1031
+ label_unit_as_expected)
1030
1032
}
1031
1033
1032
1034
/// The inner coercion "engine". If `expression` is `None`, this
@@ -1038,7 +1040,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1038
1040
expression : Option < & ' gcx hir:: Expr > ,
1039
1041
mut expression_ty : Ty < ' tcx > ,
1040
1042
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 )
1042
1045
{
1043
1046
// Incorporate whatever type inference information we have
1044
1047
// until now; in principle we might also want to process
@@ -1119,11 +1122,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1119
1122
}
1120
1123
}
1121
1124
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 {
1127
1126
( expression_ty, self . final_ty . unwrap_or ( self . expected_ty ) )
1128
1127
} else {
1129
1128
// Otherwise, the "expected" type for error
0 commit comments