From e02fef2d4d5ee3e6821b68a9d85b16bfe3c84414 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Sun, 7 Dec 2025 07:57:44 +0900 Subject: [PATCH 01/28] feat: add first draft of drop order in or patterns clarification --- src/glossary.rst | 13 +++++++++ src/ownership-and-deconstruction.rst | 40 ++++++++++++++++++++++++++++ src/patterns.rst | 14 ++++++++-- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/glossary.rst b/src/glossary.rst index 9a66eb66..a912c165 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4713,6 +4713,19 @@ opt-out trait bound An :dt:`opt-out trait bound` is a :t:`trait bound` with :s:`Punctuation` ``?`` that nullifies an implicitly added :t:`trait bound`. + +.. _fls_LnPDQW3bnNUw: + +or pattern +^^^^^^^^^^ + +:dp:`fls_LnPDQW3bnNUw` +An :dt:`or pattern` is a :t:`pattern` that matches on one of two or more +:t:`[pattern-without-alternation]s`. + +:dp:`fls_urIJ5JNHLhm6` +See :s:`Pattern`. + .. _fls_gllzixm9yt9w: outer attribute diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index f8351cf2..c2b376aa 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -697,6 +697,11 @@ When a :t:`drop scope` is left, all :t:`[value]s` associated with that * :dp:`fls_g07zq3n55094` :t:`[Binding]s` are :t:`dropped` in reverse declaration order. +* :dp:`fls_W2S2FrkuedYC` + For the purpose of drop order, an :t:`[Or Pattern]` declares its + :t:`[Binding]s` in the order given by its first + :t:`[Pattern Without Alternation]`. + * :dp:`fls_a5tmilqxdb6f` :t:`Temporaries ` are :t:`dropped` in reverse creation order. @@ -748,3 +753,38 @@ proceeds as follows: } let c = PrintOnDrop("2"); +:dp:`fls_THzA0QFdMMJB` +When an :t:`or pattern` is used, the drop order of :t:`[Binding]s` is +determined by the first :t:`pattern-without-alternation`, regardless of which +alternative matches at runtime. + +.. code-block:: rust + + // Drops `x` before `y`. + fn or_pattern_drop_order( + (Ok([x, y]) | Err([y, x])): Result<[T; 2], [T; 2]> + // ^^^^^^^^^^ ^^^^^^^^^^^ This is the second pattern-without-alternation. + // | + // This is the first pattern-without-alternation. + // + // In the first pattern-without-alternation, `x` is declared before `y`. + // Since it is the first pattern-without-alternation, that is the order + // used even if the second pattern-without-alternation, where the bindings + // are declared in the opposite order, is matched. + ) {} + + // Here we match the first pattern-without-alternation, and the drops happen + // according to the declaration order in the first pattern-without-alternation. + or_pattern_drop_order(Ok([ + PrintOnDrop("Declared first, dropped last"), + PrintOnDrop("Declared last, dropped first"), + ])); + + // Here we match the second pattern-without-alternation, and the drops still + // happen according to the declaration order in the first + // pattern-without-alternation. + or_pattern_drop_order(Err([ + PrintOnDrop("Declared last, dropped first"), + PrintOnDrop("Declared first, dropped last"), + ])); + diff --git a/src/patterns.rst b/src/patterns.rst index 2ef1297c..0b2c689e 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -65,9 +65,19 @@ of a :t:`pattern-without-range`, except for when the :t:`pattern` is ``&mut`` :s:`Identifier`. Such a :t:`pattern` is interpreted as a :t:`reference pattern` with :t:`keyword` ``mut`` containing an :t:`identifier pattern`. +:dp:`fls_72JHo343O7jp` +An :t:`or pattern` is a :t:`pattern` that matches on one of two or more +:t:`[pattern-without-alternation]s`. An :t:`or pattern` can nest arbitrarily. +Syntactically, :t:`[or pattern]s` are allowed in any of the places where other +:t:`[pattern]s` are allowed, with the exception of :t:`[let statement]s`, +:t:`[function parameter]s`, and :t:`[closure parameter]s`. + +:dp:`fls_VQMmveZUfNTn` +An :t:`or pattern` uses character 0x7C (vertical line) between the +:t:`[pattern-without-alternation]s`. + :dp:`fls_8luyomzppck` -Any two :t:`[pattern-without-alternation]s` that are or-ed using character 0x7C -(vertical line) are subject to the following restrictions: +An :t:`or pattern` is subject to the following restrictions: * :dp:`fls_rpvdfmy3n05a` The :t:`[type]s` of the two :t:`[pattern-without-alternation]s` shall be From efeedc92ef54d88be37fa3a24d0f288ab8bfdb0b Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Fri, 12 Dec 2025 21:12:08 +0900 Subject: [PATCH 02/28] fix: revise based on feedback --- src/glossary.rst | 2 +- src/ownership-and-deconstruction.rst | 8 ++--- src/patterns.rst | 50 ++++++++++++++++++++-------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/glossary.rst b/src/glossary.rst index a912c165..369e0d63 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4716,7 +4716,7 @@ that nullifies an implicitly added :t:`trait bound`. .. _fls_LnPDQW3bnNUw: -or pattern +or-pattern ^^^^^^^^^^ :dp:`fls_LnPDQW3bnNUw` diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index c2b376aa..164b1449 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -695,12 +695,12 @@ When a :t:`drop scope` is left, all :t:`[value]s` associated with that :t:`drop scope` are :t:`dropped` as follows: * :dp:`fls_g07zq3n55094` - :t:`[Binding]s` are :t:`dropped` in reverse declaration order. + All other :t:`bindings` are :t:`dropped` in reverse declaration order. * :dp:`fls_W2S2FrkuedYC` - For the purpose of drop order, an :t:`[Or Pattern]` declares its - :t:`[Binding]s` in the order given by its first - :t:`[Pattern Without Alternation]`. + :t:`[Binding]s` introduced by an :t:`or-pattern` are dropped in reverse + declaration order, where the declaration order is defined by the first + :t:`subpattern`. * :dp:`fls_a5tmilqxdb6f` :t:`Temporaries ` are :t:`dropped` in reverse creation order. diff --git a/src/patterns.rst b/src/patterns.rst index 0b2c689e..5d6a5bfb 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -41,6 +41,10 @@ Patterns A :t:`pattern` is a :t:`construct` that matches a :t:`value` which satisfies all the criteria of the :t:`pattern`. +:dp:`fls_VQMmveZUfNTn` +An :t:`or-pattern` is a :t:`pattern` which or-s two or more :t:`[subpattern]s` using +character 0x7C (vertical line). + :dp:`fls_mp6i4blzexnu` A :t:`pattern-without-alternation` is a :t:`pattern` that cannot be alternated. @@ -66,27 +70,23 @@ of a :t:`pattern-without-range`, except for when the :t:`pattern` is ``&mut`` with :t:`keyword` ``mut`` containing an :t:`identifier pattern`. :dp:`fls_72JHo343O7jp` -An :t:`or pattern` is a :t:`pattern` that matches on one of two or more -:t:`[pattern-without-alternation]s`. An :t:`or pattern` can nest arbitrarily. -Syntactically, :t:`[or pattern]s` are allowed in any of the places where other -:t:`[pattern]s` are allowed, with the exception of :t:`[let statement]s`, -:t:`[function parameter]s`, and :t:`[closure parameter]s`. - -:dp:`fls_VQMmveZUfNTn` -An :t:`or pattern` uses character 0x7C (vertical line) between the -:t:`[pattern-without-alternation]s`. +An or-pattern shall not appear in the :t:`pattern-without-alternation` of a +:t:`closure parameter`, a :t:`function parameter`, or a :t:`let statement`. :dp:`fls_8luyomzppck` -An :t:`or pattern` is subject to the following restrictions: +Any two :t:`[subpattern]s` of an :t:`or-pattern` are subject to the following +restrictions: * :dp:`fls_rpvdfmy3n05a` - The :t:`[type]s` of the two :t:`[pattern-without-alternation]s` shall be + The :t:`[type]s` of the two :t:`[subpattern]s` shall be :t:`unifiable`. +* :dp:`fls_YDVgFaTQwcL8` + The set of :t:`[binding]s` introduced by the two :t:`[pattern]s` shall be distinct. + * :dp:`fls_kv533rntni1x` - The :t:`[binding]s` of the two :t:`[pattern-without-alternation]s` shall - be the same, shall have :t:`[unifiable type]s`, and shall have the same - :t:`[binding mode]s`. + Any two :t:`[binding]s` with the same name in the two :t:`[pattern]s` shall have + :t:`[unifiable type]s` and shall have the same :t:`[binding mode]s`. .. _fls_uh76pw6ykd57: @@ -1306,6 +1306,9 @@ Pattern Matching :t:`Pattern matching` that involves a :t:`pattern` and a context :t:`value` proceeds as follows: +#. :dp:`fls_tZJgZDWVChJV` + If the pattern is an :t:`or-pattern`, then perform or-pattern matching. + #. :dp:`fls_67ajub7d2b4c` For each :t:`pattern-without-alternation` of the :t:`pattern`: @@ -1360,6 +1363,25 @@ proceeds as follows: Only the :t:`[binding]s` of a matched :t:`pattern-without-alternation` are introduced into a :t:`binding scope`. + +.. _fls_VsBXBj4AqCj1: + +Or-pattern Matching +~~~~~~~~~~~~~~~~~~~ + + +:dp:`fls_njpiXkgi8Ryb` +Or-pattern matching of an :t:`or-pattern` of the form `constructor(or-pattern, rest)`, +where `constructor` is an arbitrary constructor, `or-pattern` is the :t:`or-pattern`, +and `rest` is optionally a remaining pattern, proceeds as follows: + +#. :dp:`fls_nE7qZpHy9TPu` + Perform pattern matching of the form `constructor(subpattern, rest)`, where + `subpattern` is a :t:`subpattern` of the :t:`or-pattern`, starting from the + first such :t:`subpattern` and proceeding in declarative order. +#. :dp:`fls_P8yB2b5enpw7` + Otherwise pattern matching fails. + .. _fls_vnai6ag4qrdb: Identifier Pattern Matching From e38db7a55aeafcee62e86165d29fb4da7cb2ef37 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Wed, 17 Dec 2025 04:28:58 +0900 Subject: [PATCH 03/28] fix: move definition of or-pattern to glossary and then copy to patterns.rst --- src/glossary.rst | 3 +-- src/patterns.rst | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/glossary.rst b/src/glossary.rst index 369e0d63..50ea59a8 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4720,8 +4720,7 @@ or-pattern ^^^^^^^^^^ :dp:`fls_LnPDQW3bnNUw` -An :dt:`or pattern` is a :t:`pattern` that matches on one of two or more -:t:`[pattern-without-alternation]s`. +An :dt:`or pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s two or more :t:`[subpattern]s` using character 0x7C (vertical line). :dp:`fls_urIJ5JNHLhm6` See :s:`Pattern`. diff --git a/src/patterns.rst b/src/patterns.rst index 5d6a5bfb..30645975 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -42,8 +42,7 @@ A :t:`pattern` is a :t:`construct` that matches a :t:`value` which satisfies all the criteria of the :t:`pattern`. :dp:`fls_VQMmveZUfNTn` -An :t:`or-pattern` is a :t:`pattern` which or-s two or more :t:`[subpattern]s` using -character 0x7C (vertical line). +An :t:`or pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s two or more :t:`[subpattern]s` using character 0x7C (vertical line). :dp:`fls_mp6i4blzexnu` A :t:`pattern-without-alternation` is a :t:`pattern` that cannot be alternated. From a1231b7cf1953192251c10e9c35483764295b90e Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Tue, 16 Dec 2025 14:32:02 -0500 Subject: [PATCH 04/28] fix: pattern => subpattern --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index 30645975..5b84d696 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -84,7 +84,7 @@ restrictions: The set of :t:`[binding]s` introduced by the two :t:`[pattern]s` shall be distinct. * :dp:`fls_kv533rntni1x` - Any two :t:`[binding]s` with the same name in the two :t:`[pattern]s` shall have + Any two :t:`[binding]s` with the same name in the two :t:`[subpattern]s` shall have :t:`[unifiable type]s` and shall have the same :t:`[binding mode]s`. .. _fls_uh76pw6ykd57: From fba2b6039a56358c01b41861dfcec5a47e86972c Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Tue, 16 Dec 2025 14:32:12 -0500 Subject: [PATCH 05/28] fix: pattern => subpattern --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index 5b84d696..295c624b 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -81,7 +81,7 @@ restrictions: :t:`unifiable`. * :dp:`fls_YDVgFaTQwcL8` - The set of :t:`[binding]s` introduced by the two :t:`[pattern]s` shall be distinct. + The set of :t:`[binding]s` introduced by the two :t:`[subpattern]s` shall be the same. * :dp:`fls_kv533rntni1x` Any two :t:`[binding]s` with the same name in the two :t:`[subpattern]s` shall have From 793d198fbbc2ce9229f884782db74cd4ad5fee55 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Tue, 16 Dec 2025 14:34:50 -0500 Subject: [PATCH 06/28] fix: let statement => let binding --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index 295c624b..dafa0378 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -70,7 +70,7 @@ with :t:`keyword` ``mut`` containing an :t:`identifier pattern`. :dp:`fls_72JHo343O7jp` An or-pattern shall not appear in the :t:`pattern-without-alternation` of a -:t:`closure parameter`, a :t:`function parameter`, or a :t:`let statement`. +:t:`closure parameter`, a :t:`function parameter`, or a :t:`let binding`. :dp:`fls_8luyomzppck` Any two :t:`[subpattern]s` of an :t:`or-pattern` are subject to the following From eaf467d4918f1e4e0043db6d1c5e93d8fbaf2bd8 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Wed, 17 Dec 2025 04:55:15 +0900 Subject: [PATCH 07/28] docs: add definition of let binding --- src/glossary.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/glossary.rst b/src/glossary.rst index 50ea59a8..4c5efb31 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -3741,6 +3741,15 @@ tests for a less-than-or-equals relationship. :dp:`fls_ft5aeo4ilgwc` See :s:`LessThanOrEqualsExpression`. + +.. _fls_DdZ1ZwjLZTeG: + +let binding +^^^^^^^^^^^ + +:dp:`fls_sw6HrsxsnG2y` +A :dt:`let binding` is a :t:`construct` that introduces :t:`[binding]s` by matching a :t:`value` against a :t:`pattern` using the keyword ``let``. :t:`[let binding]s` appear in :t:`[let statement]s`, :t:`[if let expression]s`, :t:`[while let loop expression]s`, and :t:`[let initializer]s`. + .. _fls_hqj80jHcxEBB: let initializer From 4d7a0dbaf23a43ee077b03ff0217373e32dc844c Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Wed, 17 Dec 2025 06:11:04 +0900 Subject: [PATCH 08/28] fix: rework example to be more in line with FLS style --- src/ownership-and-deconstruction.rst | 49 +++++++++++----------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index 164b1449..f1d5d7b7 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -754,37 +754,26 @@ proceeds as follows: let c = PrintOnDrop("2"); :dp:`fls_THzA0QFdMMJB` -When an :t:`or pattern` is used, the drop order of :t:`[Binding]s` is -determined by the first :t:`pattern-without-alternation`, regardless of which -alternative matches at runtime. +When an :t:`or pattern` is used, the drop order of :t:`[binding]s` is determined by the first :t:`pattern-without-alternation`, regardless of which matches at runtime. + +:dp:`fls_dhfIPP4yR3Tt` +In the following example, the drop order is ``b``, ``a`` for both calls. +Dropping proceeds as follows: + +#. :dp:`fls_zxFM7EoE2Xq8` + The first :t:`pattern-without-alternation` ``Ok([a, b])`` declares ``a`` before ``b``. + +#. :dp:`fls_zxFM7EoE2Xq8` + When the first call matches ``Ok([a, b])``, the :t:`[binding]s` are dropped in reverse declaration order: ``b`` then ``a``. + +#. :dp:`fls_gNWXh61ZXXt8` + When the second call matches ``Err([b, a])``, the drop order remains ``b`` then ``a``, determined by the first :t:`pattern-without-alternation`. .. code-block:: rust - // Drops `x` before `y`. - fn or_pattern_drop_order( - (Ok([x, y]) | Err([y, x])): Result<[T; 2], [T; 2]> - // ^^^^^^^^^^ ^^^^^^^^^^^ This is the second pattern-without-alternation. - // | - // This is the first pattern-without-alternation. - // - // In the first pattern-without-alternation, `x` is declared before `y`. - // Since it is the first pattern-without-alternation, that is the order - // used even if the second pattern-without-alternation, where the bindings - // are declared in the opposite order, is matched. - ) {} - - // Here we match the first pattern-without-alternation, and the drops happen - // according to the declaration order in the first pattern-without-alternation. - or_pattern_drop_order(Ok([ - PrintOnDrop("Declared first, dropped last"), - PrintOnDrop("Declared last, dropped first"), - ])); - - // Here we match the second pattern-without-alternation, and the drops still - // happen according to the declaration order in the first - // pattern-without-alternation. - or_pattern_drop_order(Err([ - PrintOnDrop("Declared last, dropped first"), - PrintOnDrop("Declared first, dropped last"), - ])); + fn drop_order((Ok([a, b]) | Err([b, a])): Result<[T; 2], [T; 2]>) {} + + drop_order(Ok([PrintOnDrop("1"), PrintOnDrop("2")])); + + drop_order(Err([PrintOnDrop("2"), PrintOnDrop("1")])); From 693b00da773898a258f90f6cca021ba487d9e0eb Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Wed, 17 Dec 2025 06:14:16 +0900 Subject: [PATCH 09/28] fix: duplicated FLS IDs --- src/ownership-and-deconstruction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index f1d5d7b7..33006002 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -763,7 +763,7 @@ Dropping proceeds as follows: #. :dp:`fls_zxFM7EoE2Xq8` The first :t:`pattern-without-alternation` ``Ok([a, b])`` declares ``a`` before ``b``. -#. :dp:`fls_zxFM7EoE2Xq8` +#. :dp:`fls_093YxG6YXQz2` When the first call matches ``Ok([a, b])``, the :t:`[binding]s` are dropped in reverse declaration order: ``b`` then ``a``. #. :dp:`fls_gNWXh61ZXXt8` From 44da942ddd8910f740d8dce33e7ffe2c760fd82f Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:56:10 -0500 Subject: [PATCH 10/28] subpattern => pattern-without-alternation Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glossary.rst b/src/glossary.rst index 4c5efb31..d600a2ad 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4729,7 +4729,7 @@ or-pattern ^^^^^^^^^^ :dp:`fls_LnPDQW3bnNUw` -An :dt:`or pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s two or more :t:`[subpattern]s` using character 0x7C (vertical line). +An :dt:`or pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s them using character 0x7C (vertical line). :dp:`fls_urIJ5JNHLhm6` See :s:`Pattern`. From 4a72aed14c660ceb9e8eb2f3b16342f7eeb720d5 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:56:27 -0500 Subject: [PATCH 11/28] subpattern => pattern-without-alternation Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/ownership-and-deconstruction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index 33006002..257c8f01 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -700,7 +700,7 @@ When a :t:`drop scope` is left, all :t:`[value]s` associated with that * :dp:`fls_W2S2FrkuedYC` :t:`[Binding]s` introduced by an :t:`or-pattern` are dropped in reverse declaration order, where the declaration order is defined by the first - :t:`subpattern`. + :t:`pattern-without-alternation`. * :dp:`fls_a5tmilqxdb6f` :t:`Temporaries ` are :t:`dropped` in reverse creation order. From 725a628c9e3cea125b9cd3bb089b81298ab7b673 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:57:03 -0500 Subject: [PATCH 12/28] subpattern => pattern-without-alternation Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index dafa0378..e4391f6b 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -77,7 +77,7 @@ Any two :t:`[subpattern]s` of an :t:`or-pattern` are subject to the following restrictions: * :dp:`fls_rpvdfmy3n05a` - The :t:`[type]s` of the two :t:`[subpattern]s` shall be + The :t:`[type]s` of the two :t:`[pattern-without-alternation]s` shall be :t:`unifiable`. * :dp:`fls_YDVgFaTQwcL8` From 5ab4587db254f5988856a01a2cccb6dd4bda5a74 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:57:13 -0500 Subject: [PATCH 13/28] subpattern => pattern-without-alternation Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index e4391f6b..7958f2a3 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -81,7 +81,7 @@ restrictions: :t:`unifiable`. * :dp:`fls_YDVgFaTQwcL8` - The set of :t:`[binding]s` introduced by the two :t:`[subpattern]s` shall be the same. + The set of :t:`[binding]s` introduced by the two :t:`[pattern-without-alternation]s` shall be the same. * :dp:`fls_kv533rntni1x` Any two :t:`[binding]s` with the same name in the two :t:`[subpattern]s` shall have From 18f32b4617289003ca3379dd5ebd2f7884c88479 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:57:35 -0500 Subject: [PATCH 14/28] subpattern => pattern-without-alternation Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index 7958f2a3..d804848d 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -84,7 +84,7 @@ restrictions: The set of :t:`[binding]s` introduced by the two :t:`[pattern-without-alternation]s` shall be the same. * :dp:`fls_kv533rntni1x` - Any two :t:`[binding]s` with the same name in the two :t:`[subpattern]s` shall have + Any two :t:`[binding]s` with the same name in the two :t:`[pattern-without-alternation]s` shall have :t:`[unifiable type]s` and shall have the same :t:`[binding mode]s`. .. _fls_uh76pw6ykd57: From 47da2d428a91d0b69d3cc4632c3eaadfa4fbe72b Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:58:01 -0500 Subject: [PATCH 15/28] add links Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/patterns.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/patterns.rst b/src/patterns.rst index d804848d..559fc776 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1306,7 +1306,7 @@ Pattern Matching proceeds as follows: #. :dp:`fls_tZJgZDWVChJV` - If the pattern is an :t:`or-pattern`, then perform or-pattern matching. + If the :t:`pattern` is an :t:`or-pattern`, then perform :t:`or-pattern matching`. #. :dp:`fls_67ajub7d2b4c` For each :t:`pattern-without-alternation` of the :t:`pattern`: From fd81fdd8b0445e1552f1863c59eb5a2aceae9800 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:58:37 -0500 Subject: [PATCH 16/28] add definition of term Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/patterns.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/patterns.rst b/src/patterns.rst index 559fc776..153f06cc 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1368,9 +1368,8 @@ introduced into a :t:`binding scope`. Or-pattern Matching ~~~~~~~~~~~~~~~~~~~ - :dp:`fls_njpiXkgi8Ryb` -Or-pattern matching of an :t:`or-pattern` of the form `constructor(or-pattern, rest)`, +:dt:`Or-pattern matching` of an :t:`or-pattern` of the form `constructor(or-pattern, rest)`, where `constructor` is an arbitrary constructor, `or-pattern` is the :t:`or-pattern`, and `rest` is optionally a remaining pattern, proceeds as follows: From 3de5e61b5904f1feee70696d0cce4c109c90479c Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Mon, 29 Dec 2025 09:59:52 -0500 Subject: [PATCH 17/28] insert whitespace to make source clearer Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/patterns.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/src/patterns.rst b/src/patterns.rst index 153f06cc..571f6150 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1377,6 +1377,7 @@ and `rest` is optionally a remaining pattern, proceeds as follows: Perform pattern matching of the form `constructor(subpattern, rest)`, where `subpattern` is a :t:`subpattern` of the :t:`or-pattern`, starting from the first such :t:`subpattern` and proceeding in declarative order. + #. :dp:`fls_P8yB2b5enpw7` Otherwise pattern matching fails. From ddf668a00087b83940483124483793e4beb95d07 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Tue, 30 Dec 2025 00:05:10 +0900 Subject: [PATCH 18/28] fix: align glossary and patterns chapter definition of or-pattern --- src/glossary.rst | 2 +- src/patterns.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/glossary.rst b/src/glossary.rst index d600a2ad..59e069b8 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4729,7 +4729,7 @@ or-pattern ^^^^^^^^^^ :dp:`fls_LnPDQW3bnNUw` -An :dt:`or pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s them using character 0x7C (vertical line). +An :dt:`or-pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s them using character 0x7C (vertical line). :dp:`fls_urIJ5JNHLhm6` See :s:`Pattern`. diff --git a/src/patterns.rst b/src/patterns.rst index 571f6150..b52167d1 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -42,7 +42,7 @@ A :t:`pattern` is a :t:`construct` that matches a :t:`value` which satisfies all the criteria of the :t:`pattern`. :dp:`fls_VQMmveZUfNTn` -An :t:`or pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s two or more :t:`[subpattern]s` using character 0x7C (vertical line). +An :t:`or-pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s them using character 0x7C (vertical line). :dp:`fls_mp6i4blzexnu` A :t:`pattern-without-alternation` is a :t:`pattern` that cannot be alternated. From ecb73764889649de74a8ee6ab6256322438a0da7 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Tue, 30 Dec 2025 00:11:14 +0900 Subject: [PATCH 19/28] fix: correct definition of let binding --- src/glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glossary.rst b/src/glossary.rst index 59e069b8..d5d53748 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -3748,7 +3748,7 @@ let binding ^^^^^^^^^^^ :dp:`fls_sw6HrsxsnG2y` -A :dt:`let binding` is a :t:`construct` that introduces :t:`[binding]s` by matching a :t:`value` against a :t:`pattern` using the keyword ``let``. :t:`[let binding]s` appear in :t:`[let statement]s`, :t:`[if let expression]s`, :t:`[while let loop expression]s`, and :t:`[let initializer]s`. +A :dt:`let binding` is the :t:`binding` introduced by a :t:`let statement`, an :t:`if let expression`, or a :t:`while let loop expression`. .. _fls_hqj80jHcxEBB: From a9c8d2aed3565736d93c472845915fb5525c90a2 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Fri, 9 Jan 2026 09:23:02 -0500 Subject: [PATCH 20/28] fix: move "or pattern" to "or-pattern" Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/ownership-and-deconstruction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index 257c8f01..b9fa9ac4 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -754,7 +754,7 @@ proceeds as follows: let c = PrintOnDrop("2"); :dp:`fls_THzA0QFdMMJB` -When an :t:`or pattern` is used, the drop order of :t:`[binding]s` is determined by the first :t:`pattern-without-alternation`, regardless of which matches at runtime. +When an :t:`or-pattern` is used, the drop order of :t:`[binding]s` is determined by the first :t:`pattern-without-alternation`, regardless of which matches at runtime. :dp:`fls_dhfIPP4yR3Tt` In the following example, the drop order is ``b``, ``a`` for both calls. From fa4b11393439289caa29dc36cf8965a984555ba6 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Fri, 9 Jan 2026 09:23:33 -0500 Subject: [PATCH 21/28] fix: reword for clarity Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com> --- src/ownership-and-deconstruction.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index b9fa9ac4..11bcdfd8 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -767,7 +767,7 @@ Dropping proceeds as follows: When the first call matches ``Ok([a, b])``, the :t:`[binding]s` are dropped in reverse declaration order: ``b`` then ``a``. #. :dp:`fls_gNWXh61ZXXt8` - When the second call matches ``Err([b, a])``, the drop order remains ``b`` then ``a``, determined by the first :t:`pattern-without-alternation`. + When the second call matches ``Err([b, a])``, the drop order remains ``b`` then ``a`` since it is determined by the first :t:`pattern-without-alternation`. .. code-block:: rust From aa7dec88eb4b2c01c644013ecbc4939f62d7c493 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Fri, 9 Jan 2026 23:28:58 +0900 Subject: [PATCH 22/28] fix: add vertical line / pipe literal as used in or-patterns --- src/glossary.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glossary.rst b/src/glossary.rst index d5d53748..412d036a 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4729,7 +4729,7 @@ or-pattern ^^^^^^^^^^ :dp:`fls_LnPDQW3bnNUw` -An :dt:`or-pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s them using character 0x7C (vertical line). +An :dt:`or-pattern` is a :t:`pattern` that matches on one of two or more :t:`[pattern-without-alternation]s` and or-s them using character 0x7C (vertical line, i.e. ``|``). :dp:`fls_urIJ5JNHLhm6` See :s:`Pattern`. From 89157cd7aaa8e81ad45f72b308a042fdea67f4a9 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Sat, 10 Jan 2026 04:31:39 +0900 Subject: [PATCH 23/28] fix: move mention of other bindings to be at the bottom --- src/ownership-and-deconstruction.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index 11bcdfd8..0debd0e1 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -694,9 +694,6 @@ Drop Order When a :t:`drop scope` is left, all :t:`[value]s` associated with that :t:`drop scope` are :t:`dropped` as follows: -* :dp:`fls_g07zq3n55094` - All other :t:`bindings` are :t:`dropped` in reverse declaration order. - * :dp:`fls_W2S2FrkuedYC` :t:`[Binding]s` introduced by an :t:`or-pattern` are dropped in reverse declaration order, where the declaration order is defined by the first @@ -705,6 +702,9 @@ When a :t:`drop scope` is left, all :t:`[value]s` associated with that * :dp:`fls_a5tmilqxdb6f` :t:`Temporaries ` are :t:`dropped` in reverse creation order. +* :dp:`fls_g07zq3n55094` + All other :t:`bindings` are :t:`dropped` in reverse declaration order. + :dp:`fls_zQGkVGWIzMQ7` When a :t:`drop scope` of a :t:`function` is left, then each :t:`function parameter` is :t:`dropped` from right to left as follows: From 1c91489616270fbf5ff77982757475157ad99b14 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Sat, 10 Jan 2026 04:33:40 +0900 Subject: [PATCH 24/28] fix: remove duplicate specification of or-pattern drop order --- src/ownership-and-deconstruction.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ownership-and-deconstruction.rst b/src/ownership-and-deconstruction.rst index 0debd0e1..a36a28f2 100644 --- a/src/ownership-and-deconstruction.rst +++ b/src/ownership-and-deconstruction.rst @@ -753,9 +753,6 @@ proceeds as follows: } let c = PrintOnDrop("2"); -:dp:`fls_THzA0QFdMMJB` -When an :t:`or-pattern` is used, the drop order of :t:`[binding]s` is determined by the first :t:`pattern-without-alternation`, regardless of which matches at runtime. - :dp:`fls_dhfIPP4yR3Tt` In the following example, the drop order is ``b``, ``a`` for both calls. Dropping proceeds as follows: From b4c6b2015cfe754af92738e97d7879b7c04ff6aa Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Sat, 10 Jan 2026 06:15:48 +0900 Subject: [PATCH 25/28] fix: attempt to add structure to the pattern matching --- src/patterns.rst | 123 ++++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 56 deletions(-) diff --git a/src/patterns.rst b/src/patterns.rst index b52167d1..6070be8d 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1302,84 +1302,95 @@ Pattern Matching .. rubric:: Legality Rules :dp:`fls_tlwr4u7bjhh5` -:t:`Pattern matching` that involves a :t:`pattern` and a context :t:`value` -proceeds as follows: +:t:`Pattern matching` that involves a :t:`pattern` and a context :t:`value` proceeds as follows: #. :dp:`fls_tZJgZDWVChJV` - If the :t:`pattern` is an :t:`or-pattern`, then perform :t:`or-pattern matching`. + If the :t:`pattern` consists of an :t:`or-pattern`, then perform :t:`or-pattern matching`. -#. :dp:`fls_67ajub7d2b4c` - For each :t:`pattern-without-alternation` of the :t:`pattern`: +#. :dp:`fls_6gPnwXNiNx7i` + Otherwise, perform :t:`pattern-without-alternation matching` on the single :t:`pattern-without-alternation`. - #. :dp:`fls_62626ws222op` - If the :t:`pattern-without-alternation` is an :t:`identifier pattern`, - then perform :t:`identifier pattern matching`. +#. :dp:`fls_wh201rmh6u6d` + Otherwise :t:`pattern matching` fails. - #. :dp:`fls_q0z46h1gnzez` - If the :t:`pattern-without-alternation` is a :t:`literal pattern`, then - perform :t:`literal pattern matching`. +:dp:`fls_vstdqifqipbh` +Only the :t:`[binding]s` of a matched :t:`pattern-without-alternation` are +introduced into a :t:`binding scope`. - #. :dp:`fls_1r0vm6rg13o9` - If the :t:`pattern-without-alternation` is a :t:`parenthesized pattern`, - then perform :t:`parenthesized pattern matching`. - #. :dp:`fls_am5h8r887bz5` - If the :t:`pattern-without-alternation` is a :t:`path pattern`, then - perform :t:`path pattern matching`. +.. _fls_VsBXBj4AqCj1: - #. :dp:`fls_eppmiloh7bgg` - If the :t:`pattern-without-alternation` is a :t:`range pattern`, then - perform :t:`range pattern matching`. +Or-pattern Matching +~~~~~~~~~~~~~~~~~~~ - #. :dp:`fls_gwc08xayno7q` - If the :t:`pattern-without-alternation` is a :t:`reference pattern`, then - perform :t:`reference pattern matching`. +.. rubric:: Legality Rules - #. :dp:`fls_19iygu12s315` - If the :t:`pattern-without-alternation` is a :t:`slice pattern`, then - perform :t:`slice pattern matching`. +:dp:`fls_L6RWHeZYRarm` +:dt:`Or-pattern matching` of an :t:`or-pattern` against a :t:`value` proceeds as follows: - #. :dp:`fls_r307spfk6cs9` - If the :t:`pattern-without-alternation` is a :t:`record struct pattern`, - then perform :t:`record struct pattern matching`. +#. :dp:`fls_EQSJHpB6PwUi` + Perform :t:`pattern-without-alternation matching` with each :t:`pattern-without-alternation` and the :t:`value`. - #. :dp:`fls_qhdofvbso3gl` - If the :t:`pattern-without-alternation` is a :t:`tuple struct pattern`, - then perform :t:`tuple struct pattern matching`. +#. :dp:`fls_x8vS9EzkIA3k` + If matching succeeds, then :t:`or-pattern matching` succeeds. - #. :dp:`fls_drb114dtvlpt` - If the :t:`pattern-without-alternation` is a :t:`tuple pattern`, then - perform :t:`tuple pattern matching`. +#. :dp:`fls_t5u8w8DUIhf5` + Otherwise :t:`or-pattern matching` fails. - #. :dp:`fls_uxysntb3u03j` - If the :t:`pattern-without-alternation` is an :t:`underscore pattern`, - then perform :t:`underscore pattern matching`. - #. :dp:`fls_wh201rmh6u6d` - Otherwise :t:`pattern matching` fails. +:dp:`fls_UzO6gTNd55d1` +The :t:`[binding]s` introduced are those of a successful :t:`pattern-without-alternation`. -:dp:`fls_vstdqifqipbh` -Only the :t:`[binding]s` of a matched :t:`pattern-without-alternation` are -introduced into a :t:`binding scope`. +.. _fls_UvfF8JDpX9Ps: +Pattern-without-alternation Matching +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. _fls_VsBXBj4AqCj1: +.. rubric:: Legality Rules -Or-pattern Matching -~~~~~~~~~~~~~~~~~~~ +:dp:`fls_UzO6gTNd55d1` +:dt:`Pattern-without-alternation matching` of a :t:`pattern-without-alternation` +against a :t:`value` proceeds based on its kind: + +#. :dp:`fls_62626ws222op` + If the :t:`pattern-without-alternation` is an :t:`identifier pattern`, then perform :t:`identifier pattern matching`. + +#. :dp:`fls_q0z46h1gnzez` + If the :t:`pattern-without-alternation` is a :t:`literal pattern`, then perform :t:`literal pattern matching`. + +#. :dp:`fls_1r0vm6rg13o9` + If the :t:`pattern-without-alternation` is a :t:`parenthesized pattern`, then perform :t:`parenthesized pattern matching`. + +#. :dp:`fls_am5h8r887bz5` + If the :t:`pattern-without-alternation` is a :t:`path pattern`, then perform :t:`path pattern matching`. + +#. :dp:`fls_eppmiloh7bgg` + If the :t:`pattern-without-alternation` is a :t:`range pattern`, then perform :t:`range pattern matching`. + +#. :dp:`fls_gwc08xayno7q` + If the :t:`pattern-without-alternation` is a :t:`reference pattern`, then perform :t:`reference pattern matching`. + +#. :dp:`fls_19iygu12s315` + If the :t:`pattern-without-alternation` is a :t:`slice pattern`, then perform :t:`slice pattern matching`. + +#. :dp:`fls_r307spfk6cs9` + If the :t:`pattern-without-alternation` is a :t:`record struct pattern`, then perform :t:`record struct pattern matching`. + +#. :dp:`fls_qhdofvbso3gl` + If the :t:`pattern-without-alternation` is a :t:`tuple struct pattern`, then perform :t:`tuple struct pattern matching`. + +#. :dp:`fls_drb114dtvlpt` + If the :t:`pattern-without-alternation` is a :t:`tuple pattern`, then perform :t:`tuple pattern matching`. + +#. :dp:`fls_uxysntb3u03j` + If the :t:`pattern-without-alternation` is an :t:`underscore pattern`, then perform :t:`underscore pattern matching`. -:dp:`fls_njpiXkgi8Ryb` -:dt:`Or-pattern matching` of an :t:`or-pattern` of the form `constructor(or-pattern, rest)`, -where `constructor` is an arbitrary constructor, `or-pattern` is the :t:`or-pattern`, -and `rest` is optionally a remaining pattern, proceeds as follows: +#. :dp:`fls_wh201rmh6u6d` + Otherwise :t:`Pattern-without-alternation matching` fails. -#. :dp:`fls_nE7qZpHy9TPu` - Perform pattern matching of the form `constructor(subpattern, rest)`, where - `subpattern` is a :t:`subpattern` of the :t:`or-pattern`, starting from the - first such :t:`subpattern` and proceeding in declarative order. -#. :dp:`fls_P8yB2b5enpw7` - Otherwise pattern matching fails. +:dp:`fls_P8yB2b5enpw7` +The :t:`[binding]s` introduced are those of a successful :t:`pattern-without-alternation`. .. _fls_vnai6ag4qrdb: From bf9e7fce57ef9c8632a4f4d8675125e3c51998a7 Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Sat, 10 Jan 2026 06:44:39 +0900 Subject: [PATCH 26/28] fix: deduplicate FLS IDs --- src/patterns.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/patterns.rst b/src/patterns.rst index 6070be8d..a4a488ee 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1348,7 +1348,7 @@ Pattern-without-alternation Matching .. rubric:: Legality Rules -:dp:`fls_UzO6gTNd55d1` +:dp:`fls_ERSSAOpYwghf` :dt:`Pattern-without-alternation matching` of a :t:`pattern-without-alternation` against a :t:`value` proceeds based on its kind: @@ -1385,7 +1385,7 @@ against a :t:`value` proceeds based on its kind: #. :dp:`fls_uxysntb3u03j` If the :t:`pattern-without-alternation` is an :t:`underscore pattern`, then perform :t:`underscore pattern matching`. -#. :dp:`fls_wh201rmh6u6d` +#. :dp:`fls_VOfEVPdtTvPN` Otherwise :t:`Pattern-without-alternation matching` fails. From 12db09ddc5d7feba536ed4be282ff20c6a16825e Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Sat, 17 Jan 2026 08:33:24 +0900 Subject: [PATCH 27/28] fix: reworked pattern matching to be recursive Removed the extra sections for or-pattern matching and pattern-without-alternation and instead made this a flat list of operations which recurses into itself. Required changing the various pattern-without-alternation mentions into pattern mentions. --- src/patterns.rst | 83 ++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 63 deletions(-) diff --git a/src/patterns.rst b/src/patterns.rst index a4a488ee..d8a3b4cb 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1302,95 +1302,52 @@ Pattern Matching .. rubric:: Legality Rules :dp:`fls_tlwr4u7bjhh5` -:t:`Pattern matching` that involves a :t:`pattern` and a context :t:`value` proceeds as follows: +:t:`Pattern matching` that involves a :t:`pattern` and a context :t:`value` +proceeds as follows: #. :dp:`fls_tZJgZDWVChJV` - If the :t:`pattern` consists of an :t:`or-pattern`, then perform :t:`or-pattern matching`. - -#. :dp:`fls_6gPnwXNiNx7i` - Otherwise, perform :t:`pattern-without-alternation matching` on the single :t:`pattern-without-alternation`. - -#. :dp:`fls_wh201rmh6u6d` - Otherwise :t:`pattern matching` fails. - -:dp:`fls_vstdqifqipbh` -Only the :t:`[binding]s` of a matched :t:`pattern-without-alternation` are -introduced into a :t:`binding scope`. - - -.. _fls_VsBXBj4AqCj1: - -Or-pattern Matching -~~~~~~~~~~~~~~~~~~~ - -.. rubric:: Legality Rules - -:dp:`fls_L6RWHeZYRarm` -:dt:`Or-pattern matching` of an :t:`or-pattern` against a :t:`value` proceeds as follows: - -#. :dp:`fls_EQSJHpB6PwUi` - Perform :t:`pattern-without-alternation matching` with each :t:`pattern-without-alternation` and the :t:`value`. - -#. :dp:`fls_x8vS9EzkIA3k` - If matching succeeds, then :t:`or-pattern matching` succeeds. - -#. :dp:`fls_t5u8w8DUIhf5` - Otherwise :t:`or-pattern matching` fails. - - -:dp:`fls_UzO6gTNd55d1` -The :t:`[binding]s` introduced are those of a successful :t:`pattern-without-alternation`. - -.. _fls_UvfF8JDpX9Ps: - -Pattern-without-alternation Matching -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. rubric:: Legality Rules - -:dp:`fls_ERSSAOpYwghf` -:dt:`Pattern-without-alternation matching` of a :t:`pattern-without-alternation` -against a :t:`value` proceeds based on its kind: + If the :t:`pattern` is an :t:`or-pattern`, then perform :t:`pattern matching` with each :t:`pattern-without-alternation` of the :t:`or-pattern` and the :t:`value`. If any such :t:`pattern matching` succeeds, then the overall :t:`pattern matching` succeeds. #. :dp:`fls_62626ws222op` - If the :t:`pattern-without-alternation` is an :t:`identifier pattern`, then perform :t:`identifier pattern matching`. + If the :t:`pattern` is an :t:`identifier pattern`, then perform :t:`identifier pattern matching`. #. :dp:`fls_q0z46h1gnzez` - If the :t:`pattern-without-alternation` is a :t:`literal pattern`, then perform :t:`literal pattern matching`. + If the :t:`pattern` is a :t:`literal pattern`, then perform :t:`literal pattern matching`. + #. :dp:`fls_1r0vm6rg13o9` - If the :t:`pattern-without-alternation` is a :t:`parenthesized pattern`, then perform :t:`parenthesized pattern matching`. + If the :t:`pattern` is a :t:`parenthesized pattern`, then perform :t:`parenthesized pattern matching`. #. :dp:`fls_am5h8r887bz5` - If the :t:`pattern-without-alternation` is a :t:`path pattern`, then perform :t:`path pattern matching`. + If the :t:`pattern` is a :t:`path pattern`, then perform :t:`path pattern matching`. #. :dp:`fls_eppmiloh7bgg` - If the :t:`pattern-without-alternation` is a :t:`range pattern`, then perform :t:`range pattern matching`. + If the :t:`pattern` is a :t:`range pattern`, then perform :t:`range pattern matching`. #. :dp:`fls_gwc08xayno7q` - If the :t:`pattern-without-alternation` is a :t:`reference pattern`, then perform :t:`reference pattern matching`. + If the :t:`pattern` is a :t:`reference pattern`, then perform :t:`reference pattern matching`. #. :dp:`fls_19iygu12s315` - If the :t:`pattern-without-alternation` is a :t:`slice pattern`, then perform :t:`slice pattern matching`. + If the :t:`pattern` is a :t:`slice pattern`, then perform :t:`slice pattern matching`. #. :dp:`fls_r307spfk6cs9` - If the :t:`pattern-without-alternation` is a :t:`record struct pattern`, then perform :t:`record struct pattern matching`. + If the :t:`pattern` is a :t:`record struct pattern`, then perform :t:`record struct pattern matching`. #. :dp:`fls_qhdofvbso3gl` - If the :t:`pattern-without-alternation` is a :t:`tuple struct pattern`, then perform :t:`tuple struct pattern matching`. + If the :t:`pattern` is a :t:`tuple struct pattern`, then perform :t:`tuple struct pattern matching`. #. :dp:`fls_drb114dtvlpt` - If the :t:`pattern-without-alternation` is a :t:`tuple pattern`, then perform :t:`tuple pattern matching`. + If the :t:`pattern` is a :t:`tuple pattern`, then perform :t:`tuple pattern matching`. #. :dp:`fls_uxysntb3u03j` - If the :t:`pattern-without-alternation` is an :t:`underscore pattern`, then perform :t:`underscore pattern matching`. - -#. :dp:`fls_VOfEVPdtTvPN` - Otherwise :t:`Pattern-without-alternation matching` fails. + If the :t:`pattern` is an :t:`underscore pattern`, then perform :t:`underscore pattern matching`. +#. :dp:`fls_wh201rmh6u6d` + Otherwise :t:`pattern matching` fails. -:dp:`fls_P8yB2b5enpw7` -The :t:`[binding]s` introduced are those of a successful :t:`pattern-without-alternation`. +:dp:`fls_vstdqifqipbh` +Only the :t:`[binding]s` of the matched :t:`pattern` are +introduced into a :t:`binding scope`. .. _fls_vnai6ag4qrdb: From 614b9f8bfd79477fcdb16dd0228ae8af07e3ab8f Mon Sep 17 00:00:00 2001 From: Pete LeVasseur Date: Wed, 21 Jan 2026 03:46:05 +0900 Subject: [PATCH 28/28] chore: move pattern matching definition out of glossary Move `pattern matching` definition to the Patterns chapter and then make that the definition, i.e. `:dt:`, while making the glossary entry refer to the entry in the Patterns chapter --- src/glossary.rst | 3 +-- src/patterns.rst | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/glossary.rst b/src/glossary.rst index 412d036a..e0a142c8 100644 --- a/src/glossary.rst +++ b/src/glossary.rst @@ -4990,8 +4990,7 @@ pattern matching ^^^^^^^^^^^^^^^^ :dp:`fls_y3oputy9e0sz` -:dt:`Pattern matching` is the process of matching a :t:`pattern` against a -:t:`value`. +:t:`Pattern matching` is the process of matching a :t:`pattern` against a :t:`value`. .. _fls_cptagvgpgnze: diff --git a/src/patterns.rst b/src/patterns.rst index d8a3b4cb..adfb2688 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -1299,6 +1299,9 @@ follows: Pattern Matching ---------------- +:dp:`fls_zv73CR8rplIa` +:dt:`Pattern matching` is the process of matching a :t:`pattern` against a :t:`value`. + .. rubric:: Legality Rules :dp:`fls_tlwr4u7bjhh5`