@@ -1001,7 +1001,12 @@ 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,
1005
+ cause,
1006
+ Some ( expression) ,
1007
+ expression_ty,
1008
+ expression_diverges,
1009
+ None , false )
1005
1010
}
1006
1011
1007
1012
/// 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>
1019
1024
pub fn coerce_forced_unit < ' a > ( & mut self ,
1020
1025
fcx : & FnCtxt < ' a , ' gcx , ' tcx > ,
1021
1026
cause : & ObligationCause < ' tcx > ,
1022
- augment_error : & mut FnMut ( & mut DiagnosticBuilder ) )
1027
+ augment_error : & mut FnMut ( & mut DiagnosticBuilder ) ,
1028
+ label_unit_as_expected : bool )
1023
1029
{
1024
1030
self . coerce_inner ( fcx,
1025
1031
cause,
1026
1032
None ,
1027
1033
fcx. tcx . mk_nil ( ) ,
1028
1034
Diverges :: Maybe ,
1029
- Some ( augment_error) )
1035
+ Some ( augment_error) ,
1036
+ label_unit_as_expected)
1030
1037
}
1031
1038
1032
1039
/// The inner coercion "engine". If `expression` is `None`, this
@@ -1038,7 +1045,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1038
1045
expression : Option < & ' gcx hir:: Expr > ,
1039
1046
mut expression_ty : Ty < ' tcx > ,
1040
1047
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 )
1042
1050
{
1043
1051
// Incorporate whatever type inference information we have
1044
1052
// until now; in principle we might also want to process
@@ -1096,7 +1104,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1096
1104
// Another example is `break` with no argument expression.
1097
1105
assert ! ( expression_ty. is_nil( ) ) ;
1098
1106
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 ( ) )
1100
1108
. map ( |infer_ok| {
1101
1109
fcx. register_infer_ok_obligations ( infer_ok) ;
1102
1110
expression_ty
@@ -1119,11 +1127,11 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
1119
1127
}
1120
1128
}
1121
1129
Err ( err) => {
1122
- let ( expected, found) = if expression . is_none ( ) {
1130
+ let ( expected, found) = if label_expression_as_expected {
1123
1131
// In the case where this is a "forced unit", like
1124
1132
// `break`, we want to call the `()` "expected"
1125
1133
// since it is implied by the syntax.
1126
- assert ! ( expression_ty . is_nil ( ) ) ;
1134
+ // (Note: not all force-units work this way.)"
1127
1135
( expression_ty, self . final_ty . unwrap_or ( self . expected_ty ) )
1128
1136
} else {
1129
1137
// Otherwise, the "expected" type for error
0 commit comments