From a9d24165dad9f5193c29026b71ff3032ca0108b7 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 14 Apr 2026 20:16:20 +0200 Subject: [PATCH 1/7] document if-let guards --- src/changelog.rst | 17 +++++++++++++++++ src/expressions.rst | 26 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/changelog.rst b/src/changelog.rst index 09c9ae55..43c22f0e 100644 --- a/src/changelog.rst +++ b/src/changelog.rst @@ -23,6 +23,23 @@ Language changes in Rust 1.95.0 ------------------------------- - `Stabilize if let guards on match arms `_ + + Changed syntax: :s:`MatchArmGuard` + + New syntax: + + - :s:`MatchGuardChain` + - :s:`MatchGuardCondition` + - :s:`MatchGuardExpression` + - :s:`MatchGuardLetPattern` + + New paragraphs: + + - :p:`fls_UlxLrpyPlVmv` + - :p:`fls_DT4N2rr6wpvZ` + - :p:`fls_AAuyKfxLgJ43` + - :p:`fls_uCDQMkWx5OMS` + - `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..0097cbf1 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4645,7 +4645,22 @@ Match Expressions OuterAttributeOrDoc* Pattern MatchArmGuard? MatchArmGuard ::= - $$if$$ Operand + $$if$$ (Operand | MatchGuardChain) + + MatchGuardChain ::= + MatchGuardCondition ($$&&$$ MatchGuardCondition)* + + MatchGuardCondition ::= + (MatchGuardExpression | OuterAttributeOrDoc* MatchGuardLetPattern) + + MatchGuardLetPattern ::= + $$let$$ Pattern $$=$$ MatchGuardExpression + + MatchGuardExpression ::= + Expression + +:dp:`fls_UlxLrpyPlVmv` +A :dt:`match guard expression` is any expression in category :s:`Expression`, except :s:`LazyBooleanExpression`, :s:`RangeFromToExpression`, :s:`RangeFromExpression`, :s:`RangeInclusiveExpression`, :s:`AssignmentExpression`, and :s:`CompoundAssignmentExpression`. .. rubric:: Legality Rules @@ -4715,6 +4730,15 @@ 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_DT4N2rr6wpvZ` +A :dt:`match guard chain` is a set of conditions that should each evaluate to ``true`` in the case of :t:`[match guard expression]s` or have a positive match in the case of a :t:`[match guard let pattern]s` for the :t:`match arm` to be selected. + +:dp:`fls_AAuyKfxLgJ43` +A :dt:`match guard let pattern` is a construct that evaluates if a :t:`match guard expression` matches the specified :t:`pattern`. + +:dp:`fls_uCDQMkWx5OMS` +Each :t:`let binding` in a :t:`match guard let pattern` is 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` From 79c291048f0ffdbcc74b745439d468be99436e97 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 14 Apr 2026 20:26:19 +0200 Subject: [PATCH 2/7] remove redundant paragraph --- src/changelog.rst | 2 ++ src/expressions.rst | 5 ----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/changelog.rst b/src/changelog.rst index 43c22f0e..2933cdfb 100644 --- a/src/changelog.rst +++ b/src/changelog.rst @@ -40,6 +40,8 @@ Language changes in Rust 1.95.0 - :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 0097cbf1..ada6e171 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4791,11 +4791,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 From 695990cb699aaf52573bbe9f550af9bbf169b591 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 21 Apr 2026 16:35:49 +0200 Subject: [PATCH 3/7] use a list to ease reading Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/changelog.rst | 6 ++++++ src/expressions.rst | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/changelog.rst b/src/changelog.rst index 2933cdfb..524f596d 100644 --- a/src/changelog.rst +++ b/src/changelog.rst @@ -36,6 +36,12 @@ Language changes in Rust 1.95.0 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` diff --git a/src/expressions.rst b/src/expressions.rst index ada6e171..ecffe91d 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4660,7 +4660,20 @@ Match Expressions Expression :dp:`fls_UlxLrpyPlVmv` -A :dt:`match guard expression` is any expression in category :s:`Expression`, except :s:`LazyBooleanExpression`, :s:`RangeFromToExpression`, :s:`RangeFromExpression`, :s:`RangeInclusiveExpression`, :s:`AssignmentExpression`, and :s:`CompoundAssignmentExpression`. +A :dt:`match 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 From 9045712f19a91762e23760a55ece8991eca76579 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 21 Apr 2026 16:41:12 +0200 Subject: [PATCH 4/7] reoder --- src/expressions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/expressions.rst b/src/expressions.rst index ecffe91d..5994bc00 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4707,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 guard chain` is a set of conditions that should each evaluate to ``true`` in the case of :t:`[match guard expression]s` or have a positive match in the case of a :t:`[match 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`. @@ -4743,9 +4746,6 @@ 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_DT4N2rr6wpvZ` -A :dt:`match guard chain` is a set of conditions that should each evaluate to ``true`` in the case of :t:`[match guard expression]s` or have a positive match in the case of a :t:`[match guard let pattern]s` for the :t:`match arm` to be selected. - :dp:`fls_AAuyKfxLgJ43` A :dt:`match guard let pattern` is a construct that evaluates if a :t:`match guard expression` matches the specified :t:`pattern`. From d44f6c2a06f9ec3ef3fdd6536769920f9a917d11 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 21 Apr 2026 16:59:47 +0200 Subject: [PATCH 5/7] use a consistent and more complete prefix --- src/changelog.rst | 8 ++++---- src/expressions.rst | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/changelog.rst b/src/changelog.rst index 524f596d..c2a4aa78 100644 --- a/src/changelog.rst +++ b/src/changelog.rst @@ -28,10 +28,10 @@ Language changes in Rust 1.95.0 New syntax: - - :s:`MatchGuardChain` - - :s:`MatchGuardCondition` - - :s:`MatchGuardExpression` - - :s:`MatchGuardLetPattern` + - :s:`MatchArmGuardChain` + - :s:`MatchArmGuardCondition` + - :s:`MatchArmGuardExpression` + - :s:`MatchArmGuardLetPattern` New paragraphs: diff --git a/src/expressions.rst b/src/expressions.rst index 5994bc00..a9bed2cb 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4645,22 +4645,22 @@ Match Expressions OuterAttributeOrDoc* Pattern MatchArmGuard? MatchArmGuard ::= - $$if$$ (Operand | MatchGuardChain) + $$if$$ (Operand | MatchArmGuardChain) - MatchGuardChain ::= - MatchGuardCondition ($$&&$$ MatchGuardCondition)* + MatchArmGuardChain ::= + MatchArmGuardCondition ($$&&$$ MatchArmGuardCondition)* - MatchGuardCondition ::= - (MatchGuardExpression | OuterAttributeOrDoc* MatchGuardLetPattern) + MatchArmGuardCondition ::= + (MatchArmGuardExpression | OuterAttributeOrDoc* MatchArmGuardLetPattern) - MatchGuardLetPattern ::= - $$let$$ Pattern $$=$$ MatchGuardExpression + MatchArmGuardLetPattern ::= + $$let$$ Pattern $$=$$ MatchArmGuardExpression - MatchGuardExpression ::= + MatchArmGuardExpression ::= Expression :dp:`fls_UlxLrpyPlVmv` -A :dt:`match guard expression` is any :t:`expression` in category :s:`Expression`, except: +A :dt:`match arm guard expression` is any :t:`expression` in category :s:`Expression`, except: - :dp:`fls_XADcpJBUxSfv` :s:`AssignmentExpression` @@ -4708,7 +4708,7 @@ 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 guard chain` is a set of conditions that should each evaluate to ``true`` in the case of :t:`[match guard expression]s` or have a positive match in the case of a :t:`[match guard let pattern]s` for the :t:`match arm` to be selected. +A :dt:`match arm guard chain` is a set of conditions that should each evaluate to ``true`` in the case of :t:`[match arm guard expression]s` or have 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 @@ -4747,10 +4747,10 @@ 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 guard let pattern` is a construct that evaluates if a :t:`match guard expression` matches the specified :t:`pattern`. +A :dt:`match arm guard let pattern` is a construct that evaluates if a :t:`match arm guard expression` matches the specified :t:`pattern`. :dp:`fls_uCDQMkWx5OMS` -Each :t:`let binding` in a :t:`match guard let pattern` is in scope for the rest of the :t:`match arm guard` as well as the :t:`match arm body`. +Each :t:`let binding` in a :t:`match arm guard let pattern` is in scope for the rest of the :t:`match arm guard` as well as the :t:`match arm body`. .. rubric:: Dynamic Semantics From f2bef9fdee38e69294baf575f86e7b6c50b32b12 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 21 Apr 2026 17:03:14 +0200 Subject: [PATCH 6/7] clarity --- src/expressions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expressions.rst b/src/expressions.rst index a9bed2cb..63844609 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4708,7 +4708,7 @@ 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 should each evaluate to ``true`` in the case of :t:`[match arm guard expression]s` or have a positive match in the case of a :t:`[match arm guard let pattern]s` for the :t:`match arm` to be selected. +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 From eba53099764a6a3411e3aadf1cbb9f8496c81300 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Tue, 21 Apr 2026 17:05:28 +0200 Subject: [PATCH 7/7] be more crisp, and add a link --- src/expressions.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/expressions.rst b/src/expressions.rst index 63844609..627a138e 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -4747,10 +4747,10 @@ 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 a construct that evaluates if a :t:`match arm guard expression` matches the specified :t:`pattern`. +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` in a :t:`match arm guard let pattern` is in scope for the rest of the :t:`match arm guard` as well as the :t:`match arm body`. +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