@@ -11,15 +11,15 @@ use crate::errors::{
1111 ComparisonOrShiftInterpretedAsGenericSugg , DoCatchSyntaxRemoved , DotDotDot , EqFieldInit ,
1212 ExpectedElseBlock , ExpectedEqForLetExpr , ExpectedExpressionFoundLet ,
1313 FieldExpressionWithGeneric , FloatLiteralRequiresIntegerPart , FoundExprWouldBeStmt ,
14- IfExpressionMissingCondition , IfExpressionMissingThenBlock , IfExpressionMissingThenBlockSub ,
15- InvalidBlockMacroSegment , InvalidComparisonOperator , InvalidComparisonOperatorSub ,
16- InvalidInterpolatedExpression , InvalidLiteralSuffixOnTupleIndex , InvalidLogicalOperator ,
17- InvalidLogicalOperatorSub , LabeledLoopInBreak , LeadingPlusNotSupported , LeftArrowOperator ,
18- LifetimeInBorrowExpression , MacroInvocationWithQualifiedPath , MalformedLoopLabel ,
19- MatchArmBodyWithoutBraces , MatchArmBodyWithoutBracesSugg , MissingCommaAfterMatchArm ,
20- MissingDotDot , MissingInInForLoop , MissingInInForLoopSub , MissingSemicolonBeforeArray ,
21- NoFieldsForFnCall , NotAsNegationOperator , NotAsNegationOperatorSub ,
22- OuterAttributeNotAllowedOnIfElse , ParenthesesWithStructFields ,
14+ IfExpressionLetSomeSub , IfExpressionMissingCondition , IfExpressionMissingThenBlock ,
15+ IfExpressionMissingThenBlockSub , InvalidBlockMacroSegment , InvalidComparisonOperator ,
16+ InvalidComparisonOperatorSub , InvalidInterpolatedExpression , InvalidLiteralSuffixOnTupleIndex ,
17+ InvalidLogicalOperator , InvalidLogicalOperatorSub , LabeledLoopInBreak , LeadingPlusNotSupported ,
18+ LeftArrowOperator , LifetimeInBorrowExpression , MacroInvocationWithQualifiedPath ,
19+ MalformedLoopLabel , MatchArmBodyWithoutBraces , MatchArmBodyWithoutBracesSugg ,
20+ MissingCommaAfterMatchArm , MissingDotDot , MissingInInForLoop , MissingInInForLoopSub ,
21+ MissingSemicolonBeforeArray , NoFieldsForFnCall , NotAsNegationOperator ,
22+ NotAsNegationOperatorSub , OuterAttributeNotAllowedOnIfElse , ParenthesesWithStructFields ,
2323 RequireColonAfterLabeledExpression , ShiftInterpretedAsGeneric , StructLiteralNotAllowedHere ,
2424 StructLiteralNotAllowedHereSugg , TildeAsUnaryOperator , UnexpectedIfWithIf ,
2525 UnexpectedTokenAfterLabel , UnexpectedTokenAfterLabelSugg , WrapExpressionInParentheses ,
@@ -2251,9 +2251,10 @@ impl<'a> Parser<'a> {
22512251 if let ExprKind :: Block ( _, None ) = right. kind => {
22522252 self . sess . emit_err ( IfExpressionMissingThenBlock {
22532253 if_span : lo,
2254- sub : IfExpressionMissingThenBlockSub :: UnfinishedCondition (
2255- cond_span. shrink_to_lo ( ) . to ( * binop_span)
2256- ) ,
2254+ missing_then_block_sub :
2255+ IfExpressionMissingThenBlockSub :: UnfinishedCondition ( cond_span. shrink_to_lo ( ) . to ( * binop_span) ) ,
2256+ let_else_sub : None ,
2257+
22572258 } ) ;
22582259 std:: mem:: replace ( right, this. mk_expr_err ( binop_span. shrink_to_hi ( ) ) )
22592260 } ,
@@ -2279,9 +2280,15 @@ impl<'a> Parser<'a> {
22792280 if let Some ( block) = recover_block_from_condition ( self ) {
22802281 block
22812282 } else {
2283+ let let_else_sub = matches ! ( cond. kind, ExprKind :: Let ( ..) )
2284+ . then ( || IfExpressionLetSomeSub { if_span : lo } ) ;
2285+
22822286 self . sess . emit_err ( IfExpressionMissingThenBlock {
22832287 if_span : lo,
2284- sub : IfExpressionMissingThenBlockSub :: AddThenBlock ( cond_span. shrink_to_hi ( ) ) ,
2288+ missing_then_block_sub : IfExpressionMissingThenBlockSub :: AddThenBlock (
2289+ cond_span. shrink_to_hi ( ) ,
2290+ ) ,
2291+ let_else_sub,
22852292 } ) ;
22862293 self . mk_block_err ( cond_span. shrink_to_hi ( ) )
22872294 }
0 commit comments