diff --git a/src/expressions.rst b/src/expressions.rst index 4f36bef2..42da59d0 100644 --- a/src/expressions.rst +++ b/src/expressions.rst @@ -3624,10 +3624,25 @@ A :t:`closure parameter` is a :t:`construct` that yields a set of :t:`[binding]s` that bind matched input :t:`[value]s` to :t:`[name]s` at the site of a :t:`call expression` or a :t:`method call expression`. +:dp:`fls_81KOEXwps2HS` +The :t:`type` of a :t:`closure parameter` is determined as follows: + +* :dp:`fls_XWJ9SFggdVeH` + If the :t:`closure parameter` lacks a :s:`TypeSpecification`, the :t:`type` is inferred form the usage of the :t:`closure parameter`. + +* :dp:`fls_mPWkIxTJErqx` + Otherwise the :t:`type` is the specified :t:`type`. + +:dp:`fls_MeLJqy28J4jr` +The :t:`type` of a :t:`closure parameter` is the :t:`type` of the :t:`closure parameter`. + :dp:`fls_r6gWLoNR7JMR` The :t:`pattern` of a :t:`closure parameter` shall be an :t:`irrefutable pattern`. +:dp:`fls_zsaTK9snhXs0` +The :t:`expected type` of the :t:`pattern` of a :t:`closure parameter` is the :t:`type` of the :t:`closure parameter`. + :dp:`fls_qPeOL6ZhXsgH` The :t:`[binding]s` of all :t:`[pattern]s` of all :t:`[closure parameter]s` of a :t:`closure expression` shall not shadow another. @@ -3731,6 +3746,9 @@ its :t:`loop body` as long as its :t:`subject expression` yields a :t:`value`. The :t:`type` of a :t:`subject expression` shall implement the :std:`core::iter::IntoIterator` :t:`trait`. +:dp:`fls_fo6Aa6Td6rMA` +The :t:`expected type` of the :t:`pattern` is the :t:`associated type` :std:`core::iter::IntoIterator::Item` of the :t:`subject expression`'s :std:`core::iter::IntoIterator` implementation. + :dp:`fls_bmTjhKdpfgCB` The :t:`type` of an :t:`for loop expression` is the :t:`unit type`. @@ -3924,6 +3942,9 @@ A :t:`while let loop expression` is a :t:`loop expression` that continues to evaluate its :t:`loop body` as long as its :t:`subject let expression` yields a :t:`value` that can be matched against its :t:`pattern`. +:dp:`fls_bC60ZSC9yUOI` +The :t:`expected type` of the :t:`pattern` is the :t:`type` of the :t:`subject let expression`. + :dp:`fls_gTfSLePwHTES` The :t:`type` of an :t:`while let loop expression` is the :t:`unit type`. @@ -4409,6 +4430,9 @@ An :t:`if let expression` is an :t:`expression` that evaluates either a :t:`block expression` or an :t:`else expression` depending on whether its :t:`pattern` can be matched against its :t:`subject let expression`. +:dp:`fls_okVOYzTT6fBK` +The :t:`expected type` of the :t:`pattern` is the :t:`type` of the :t:`subject let expression`. + :dp:`fls_4vyrufo4qdeg` The :t:`type` of an :t:`if let expression` is the :t:`type` of its :t:`block expression`. @@ -4526,6 +4550,9 @@ A :t:`final match arm` is the last :t:`match arm` of a :t:`match expression`. A :t:`match arm matcher` is a :t:`construct` that consists of a :t:`pattern` and a :t:`match arm guard`. +:dp:`fls_zJQ4LecT1HYd` +The :t:`expected type` of the :t:`pattern` of the :t:`match arm matcher` is the :t:`type` of the :t:`subject expression`. + :dp:`fls_8wjdichfxp0y` A :t:`match arm body` is the :t:`operand` of a :t:`match arm`. @@ -4555,7 +4582,7 @@ The :t:`type` of a :t:`match expression` is the :t:`unified type` of the :dp:`fls_g6xyz0beps3o` A :t:`match arm` is selected when its :t:`pattern` matches the -:t:`subject expression` and its :t:`match arm guard` (if any) evaluates to +:t:`value` of the :t:`subject expression` and its :t:`match arm guard` (if any) evaluates to ``true``. :dp:`fls_8dba4o5qg8js` diff --git a/src/functions.rst b/src/functions.rst index d4f4a2fc..57976a35 100644 --- a/src/functions.rst +++ b/src/functions.rst @@ -75,17 +75,38 @@ A :t:`self parameter` is a :t:`function parameter` expressed by :t:`keyword` A :t:`function` shall not specify a :t:`self parameter` unless it is an :t:`associated function`. -:dp:`fls_icdzs1mjh0n4` -A :t:`function` shall not specify a :s:`FunctionParameterVariadicPart` unless -it is an :t:`external function`. +:dp:`fls_AAYJDCNMJgTq` +The :t:`type` of a :t:`parameter` is determined as follows: + +* :dp:`fls_PGtp39f6gJwU` + If the :t:`parameter` is a :t:`self parameter` without a :s:`TypeSpecification`: + + * :dp:`fls_yZ2yIXxmy2ri` + And the :t:`self parameter` has token ``&`` and :t:`keyword` ``mut``, then the :t:`type` is ``&mut Self``. + + * :dp:`fls_35aSvBxBnIzm` + And the :t:`self parameter` has token ``&`` and lacks :t:`keyword` ``mut``, then the :t:`type` is ``&Self``. + + * :dp:`fls_Ogziu8S01qPQ` + And the :t:`self parameter` lacks token ``&`` and :t:`keyword` ``mut``, then the :t:`type` is ``Self``. + +* :dp:`fls_xCSsxYUZUFed` + Otherwise the :t:`type` is the specified :t:`type`. :dp:`fls_lxzinvqveuqh` The :t:`pattern` of a :t:`function parameter` shall be an :t:`irrefutable pattern`. +:dp:`fls_kcAbTPZXQ5Y8` +The :t:`expected type` of the :t:`pattern` of a :t:`function parameter` is the :t:`type` of the :t:`function parameter`. + :dp:`fls_PGDKWK7nPvgw` The :t:`[binding]s` of all :t:`[pattern]s` of all :t:`[function parameter]s` of a :t:`function` shall not shadow another. +:dp:`fls_icdzs1mjh0n4` +A :t:`function` shall not specify a :s:`FunctionParameterVariadicPart` unless +it is an :t:`external function`. + :dp:`fls_vljy4mm0zca2` A :t:`return type` is the :t:`type` of the result a :t:`function`, :t:`closure type` or :t:`function pointer type` returns. diff --git a/src/patterns.rst b/src/patterns.rst index 586d4680..ec52d1a3 100644 --- a/src/patterns.rst +++ b/src/patterns.rst @@ -57,8 +57,7 @@ it is not the inner :t:`pattern` of a :t:`slice pattern` or the :t:`pattern` of a possibly nested :t:`identifier pattern` of a :t:`slice pattern`\ ``.`` :dp:`fls_cma5t8waon0x` -The :t:`expected type` of a :t:`pattern` is the :t:`type` of the :t:`value` the -:t:`pattern` is being matched against. +The :t:`expected type` of a :t:`pattern` is the :t:`type` the :t:`pattern` is being matched against. :dp:`fls_TUanRT7WU14E` It is a static error when :t:`[lexical element]s` match multiple alternations @@ -1255,7 +1254,7 @@ follows: Pattern Matching ---------------- -.. rubric:: Dynamic Semantics +.. rubric:: Legality Rules :dp:`fls_tlwr4u7bjhh5` :t:`Pattern matching` that involves a :t:`pattern` and a context :t:`value` diff --git a/src/statements.rst b/src/statements.rst index 1e84ceba..0b500d58 100644 --- a/src/statements.rst +++ b/src/statements.rst @@ -75,6 +75,18 @@ alternatively executes a :t:`block expression`. If a :t:`let statement` lacks a :t:`block expression`, then the :t:`pattern` of the :t:`let statement` shall be an :t:`irrefutable pattern`. +:dp:`fls_iB25BeFys0j8` +The :t:`expected type` of the :t:`pattern` of the :t:`let statement` is determined as follows: + +* :dp:`fls_zObyLdya4DYc` + If the :t:`let statement` lacks a :t:`type ascription` and a :t:`let initializer, then the :t:`expected type` is the :t:`inferred type`. + +* :dp:`fls_r38TXWKQPjxv` + If the :t:`let statement` lacks a :t:`type ascription`, then the :t:`expected type` is the :t:`type` of the :t:`let initializer`. + +* :dp:`fls_6QSdwF4pzjoe` + Otherwise the :t:`expected type` is the :t:`type` specified by the :t:`type ascription`. + :dp:`fls_1prqh1trybwz` The :t:`type` of a :t:`binding` introduced by a :t:`let statement` is determined as follows: @@ -195,4 +207,3 @@ The following expression statement is not an index expression. .. code-block:: rust [42]; -