-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax for precise capturing: impl Trait + use<..>
#125836
Comments
We discussed this in the lang design meeting today: The conclusion of the team is that we'll make For now, we will support at most one such bound in a list of bounds, and semantically we'll only support these bounds in the item bounds of RPIT-like We were interested in later extending this so that it could be used in the bounds on associated types and with For RPITIT (i.e. within trait definitions), we defer to implementation work and to stabilization whether to support it or to leave this work to later, e.g. to the point at which we support Note, if we were later to support multiple If the bounds of the opaque type reference generics that are not present in the We found the idea of this being a bound surprisingly appealing, and people liked that this choice allows for putting Thanks to @joshtriplett for proposing this appealing option. We resolved a difficult choice between two good options by finding an even better one. That's Rust at its best. |
Rework `feature(precise_capturing)` to represent `use<...>` as a syntactical bound Reworks `precise_capturing` for a recent lang-team consensus. Specifically: > The conclusion of the team is that we'll make use<..> a bound. That is, we'll support impl use<..> + Trait, impl Trait + use<..>, etc. > For now, we will support at most one such bound in a list of bounds, and semantically we'll only support these bounds in the item bounds of RPIT-like impl Trait opaque types (i.e., in the places discussed in the RFC). Lang decision in favor of this approach: - rust-lang#125836 (comment) Tracking: - rust-lang#123432
impl use<..> Trait
vs use<..> impl Trait
impl Trait + use<..>
Reopening to formally propose FCP on the above change. I think it is a significant enough delta from the RFC that we would be better off doing an FCP and documenting the rationale now, instead of at stabilization time. This FCP resolves the unresolved question in the RFC about syntax. @rfcbot fcp merge |
Team member @tmandry has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
I don't know what our official policy is, but @traviscross , would you mind updating the description to reflect the new proposal from #125836 (comment) ? (Or I guess even just making the line of the description be a link to that comment...) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Also, I do not necessarily agree with "Note, if we were later to support multiple use<..> items in a list of bounds, that use + use would represent a union, and so use + use would not be equivalent to use<T, U>." ; but I do not see us as committing to a union (vs intersection) path via our FCP here, so I'm willing to check my box and not make this a formal concern here. |
@rfcbot reviewed I concur with @pnkfelix and I specifically want us to leave room for different interpretations of To explain the two options, let's start by defining a conceptual bound One option then is to desugar An alternative option is to have a more complex desugaring where I think the second rule is more intuitive but also brings up mild concerns. Specifically we try to avoid "discontinuities" like this, where having no uses is "different" than having one or more uses. These kind of rules can have composability problems, but in this instance it might be that it's more composable. Unclear. Anyway, we don't have to decide this now, but I do want to leave room for it as a possible future direction (which we may never need). |
I've got one concern with the If we make In Edition 2024, the default is to capture everything in scope. So, However, in Edition 2021 and lower, the default is to capture only some things. How does
Neither is particularly great IMO making
I think the
The list of captures is either automatically inferred (with different rules in <=2021 and >=2024), or explicitly specified with Under this mental model, it makes sense for |
The intuition I'd suggest is that, if a bounds list contains a That is, I'd suggest thinking about it in terms of the |
One additional argument that was raised in the meeting, but never really written out as an example, was the use of trait BufferedIterator<A: Arena> {
type Item<'a>: use<'a>;
fn next<'a>(&'a mut self, a: &'a mut A) -> Self::Item<'a>;
} or in use sites: fn foo(iter: impl BufferedIterator<MyArena, for<'a> Item<'a>: use<'a>>) { ... } Obviously this is a pretty niche and advanced feature, but it seems to make sense conceptually. |
I think this is possibly the strongest argument against |
Rework `feature(precise_capturing)` to represent `use<...>` as a syntactical bound Reworks `precise_capturing` for a recent lang-team consensus. Specifically: > The conclusion of the team is that we'll make use<..> a bound. That is, we'll support impl use<..> + Trait, impl Trait + use<..>, etc. > For now, we will support at most one such bound in a list of bounds, and semantically we'll only support these bounds in the item bounds of RPIT-like impl Trait opaque types (i.e., in the places discussed in the RFC). Lang decision in favor of this approach: - rust-lang/rust#125836 (comment) Tracking: - rust-lang/rust#123432
For unions of |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
For precise capturing (#123432), we need to decide which syntax to adopt.
The original two, left as an open question in the RFC, were:
impl use<..> Trait
use<..> impl Trait
(See the alternatives section in the RFC for a detailed comparative analysis of these options. In particular, so as to reduce duplication, please read that section carefully before commenting here.)
However, in the design meeting on 2024-06-05, as described below, we settled on placing
use<..>
within the list of bounds, e.g.:This issue is to track the resolution of the open question on syntax left in the RFC.
Tracking:
precise_capturing
#123432The text was updated successfully, but these errors were encountered: