diff --git a/src/changelog.rst b/src/changelog.rst index 09c9ae55..c2a4aa78 100644 --- a/src/changelog.rst +++ b/src/changelog.rst @@ -23,6 +23,31 @@ Language changes in Rust 1.95.0 ------------------------------- - `Stabilize if let guards on match arms `_ + + Changed syntax: :s:`MatchArmGuard` + + New syntax: + + - :s:`MatchArmGuardChain` + - :s:`MatchArmGuardCondition` + - :s:`MatchArmGuardExpression` + - :s:`MatchArmGuardLetPattern` + + New paragraphs: + + - :p:`fls_UlxLrpyPlVmv` + - :p:`fls_XADcpJBUxSfv` + - :p:`fls_gfHe2Cy6WXsK` + - :p:`fls_QQep7FKA1EQX` + - :p:`fls_Wepy5R7FZQPU` + - :p:`fls_imEIc7PUUO1x` + - :p:`fls_fs4ZpXjt0Wqt` + - :p:`fls_DT4N2rr6wpvZ` + - :p:`fls_AAuyKfxLgJ43` + - :p:`fls_uCDQMkWx5OMS` + + Removed paragraph: :p:`fls_sbtx1l6n2tp2` + - `irrefutable_let_patterns lint no longer lints on let chains `_ - Lints are outside the scope of the FLS. diff --git a/src/expressions.rst b/src/expressions.rst index 848fb111..627a138e 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4645,7 +4645,35 @@ Match Expressions OuterAttributeOrDoc* Pattern MatchArmGuard? MatchArmGuard ::= - $$if$$ Operand + $$if$$ (Operand | MatchArmGuardChain) + + MatchArmGuardChain ::= + MatchArmGuardCondition ($$&&$$ MatchArmGuardCondition)* + + MatchArmGuardCondition ::= + (MatchArmGuardExpression | OuterAttributeOrDoc* MatchArmGuardLetPattern) + + MatchArmGuardLetPattern ::= + $$let$$ Pattern $$=$$ MatchArmGuardExpression + + MatchArmGuardExpression ::= + Expression + +:dp:`fls_UlxLrpyPlVmv` +A :dt:`match arm guard expression` is any :t:`expression` in category :s:`Expression`, except: + +- :dp:`fls_XADcpJBUxSfv` + :s:`AssignmentExpression` +- :dp:`fls_gfHe2Cy6WXsK` + :s:`CompoundAssignmentExpression` +- :dp:`fls_QQep7FKA1EQX` + :s:`LazyBooleanExpression` +- :dp:`fls_Wepy5R7FZQPU` + :s:`RangeFromExpression` +- :dp:`fls_imEIc7PUUO1x` + :s:`RangeFromToExpression` +- :dp:`fls_fs4ZpXjt0Wqt` + :s:`RangeInclusiveExpression` .. rubric:: Legality Rules @@ -4679,6 +4707,9 @@ A :t:`match arm body` is the :t:`operand` of a :t:`match arm`. A :t:`match arm guard` is a :t:`construct` that provides additional filtering to a :t:`match arm matcher`. +:dp:`fls_DT4N2rr6wpvZ` +A :dt:`match arm guard chain` is a set of conditions that must each evaluate to ``true`` in the case of :t:`[match arm guard expression]s`, or must each produce a positive match in the case of a :t:`[match arm guard let pattern]s` for the :t:`match arm` to be selected. + :dp:`fls_RPMOAaZ6lflI` :t:`[Binding]s` introduced in the :t:`pattern` of a :t:`match arm matcher` are :t:`immutable` in the :t:`match arm guard`. @@ -4715,6 +4746,12 @@ match the :t:`[subject expression]'s` :t:`type`. The :t:`value` of a :t:`match expression` is the :t:`value` of the :t:`operand` of the selected :t:`match arm`. +:dp:`fls_AAuyKfxLgJ43` +A :dt:`match arm guard let pattern` is evaluated when its :t:`match arm guard expression` matches the specified :t:`pattern`. + +:dp:`fls_uCDQMkWx5OMS` +Each :t:`let binding` introduced in a :t:`match arm guard let pattern` is :t:`in scope` for the rest of the :t:`match arm guard` as well as the :t:`match arm body`. + .. rubric:: Dynamic Semantics :dp:`fls_g551l8r8yh6d` @@ -4767,11 +4804,6 @@ The :t:`evaluation` of a :t:`match arm matcher` proceeds as follows: #. :dp:`fls_yk8l9zjh7i0d` Otherwise the :t:`match arm matcher` fails. -:dp:`fls_sbtx1l6n2tp2` -The :t:`evaluation` of a :t:`match arm guard` evaluates its :t:`operand`. A -:t:`match arm guard` evaluates to ``true`` when its :t:`operand` evaluates to -``true``, otherwise it evaluates to ``false``. - .. rubric:: Examples .. code-block:: rust