Skip to content

document Closure capture precision#698

Open
tshepang wants to merge 13 commits intomainfrom
tshepang/capture-precision
Open

document Closure capture precision#698
tshepang wants to merge 13 commits intomainfrom
tshepang/capture-precision

Conversation

@tshepang
Copy link
Copy Markdown
Member

@tshepang tshepang commented Apr 20, 2026

This captures some gaps FLS has compared to Reference, and the content is adjusted from Closure capture precision section.

Comment thread src/types-and-traits.rst Outdated
Co-authored-by: Ana Hobden <operator@hoverbear.org>
@kirtchev-adacore kirtchev-adacore self-requested a review April 21, 2026 07:11
Copy link
Copy Markdown
Contributor

@kirtchev-adacore kirtchev-adacore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is it for now. I will have to revisit the remaining rules once the "place" business has been cleared up. I think we can find better wording/grouping of the remaining rules, as they feel somewhat randomly sprinkled.

View changes since this review

Comment thread src/types-and-traits.rst Outdated

.. _fls_G64vdcIyB2Is:

Closure capture precision
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to rename this section "Capture precision", similar to the Reference, and make it subheading of 6.22. Capturing.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, I missed that 6.22 even existed :hide:

Comment thread src/types-and-traits.rst Outdated
Closure capture precision
^^^^^^^^^^^^^^^^^^^^^^^^^

:dp:`fls_rdDT7jsaOMbs`
Copy link
Copy Markdown
Contributor

@kirtchev-adacore kirtchev-adacore Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph should be swapped with :dp:fls_j9WyKVyOLFon. The FLS avoids forward referencing as much as possible. Here you are using the term "place projection", but you have not defined it yet.

Comment thread src/types-and-traits.rst Outdated
Comment thread src/types-and-traits.rst Outdated
Comment thread src/types-and-traits.rst Outdated
A :dt:`place projection` is a :t:`field access expression`, tuple :t:`field access expression`, :t:`dereference`, array or slice :t:`index expression`, or :t:`pattern` destructuring applied to a variable.

:dp:`fls_TbfUxVf8PKPs`
The closure :t:`[borrow]s` or :t:`moves <by move>` the :t:`capture path`, which may be truncated based on these rules:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

A :t:closure expression :t:[borrow]s or :t:moves <by move> the :t:capture path, as follows:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/types-and-traits.rst Outdated
The closure :t:`[borrow]s` or :t:`moves <by move>` the :t:`capture path`, which may be truncated based on these rules:

- :dp:`fls_4TESOxGpEY2h`
When a :t:`capture path` and one of the ancestors of that path are both captured by a closure, the ancestor path is captured with the highest capture mode among the two captures, using the strict weak ordering: :t:`immutable borrow` < :t:`unique immutable borrow` < :t:`mutable borrow` < :t:`move <by move>`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear what an "ancestor" is. Be careful when using the term "path", because we also have these paths. What the Reference describes is already documented in 6.22:12 The capture mode ....

I would rephrase the paragraph as follows (note that it is part of a list!):

  • When a :t:capture path and an ancestor :t:capture path and both :t:captured, the ancestor :t:capture path is :t:captured with the highest :t:capture mode among the two :t:[capture path]s.

Note that I intentionally dropped "by a closure" because a "capturing expression" is either an async block expression or a closure expression, and I suspect that these rules do apply when the context is an async block expression.

I also dropped the ordering because it is already documented by "capture mode". On a side note, perhaps 6.22:14 should be changed to "1. By immutable reference capture. (lowest precedence)" and 6:22:17 to "4. By value capture. (highest precedence)", or just use a small table similar to expression precedence.

Comment thread src/types-and-traits.rst Outdated
Comment thread src/types-and-traits.rst Outdated
The :t:`capture path` is truncated at the rightmost :t:`dereference` in the capture path if the dereference is applied to a :t:`shared reference`.

:dp:`fls_v8IFXHJnXhez`
A :t:`place` is not captured when an :t:`underscore expression` is used to bind it.
Copy link
Copy Markdown
Contributor

@kirtchev-adacore kirtchev-adacore Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Reference is unclear what "place" refers to - is it a "place projection", a "place expression", or a "place". I suspect the former, but this needs confirmation. Once that is cleared up, there are options to refactor some of the rules below.

tshepang and others added 4 commits April 21, 2026 11:34
Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com>
Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com>
Co-authored-by: Hristian Kirtchev <60669983+kirtchev-adacore@users.noreply.github.com>
@tshepang tshepang force-pushed the tshepang/capture-precision branch from e3ed8e9 to 7be2ad5 Compare April 21, 2026 09:49
@tshepang
Copy link
Copy Markdown
Member Author

tshepang commented Apr 21, 2026

all addressed but #698 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants