Skip to content

Commit 90ea425

Browse files
Clarify the ?for<'a> weirdness
1 parent 86fc14a commit 90ea425

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

text/3668-async-closure.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,10 @@ This RFC specifies the modification to the _TraitBound_ nonterminal in the gramm
250250

251251
> **<sup>Syntax</sup>**
252252
> _TraitBound_ :
253-
> &nbsp;&nbsp;&nbsp;&nbsp;`?`<sup>?</sup> _ForLifetimes_<sup>?</sup> `async`<sup>?</sup> _TypePath_\
254-
> &nbsp;&nbsp;| `(` `?`<sup>?</sup> _ForLifetimes_<sup>?</sup> `async`<sup>?</sup> _TypePath_ `)`
253+
> &nbsp;&nbsp;&nbsp;&nbsp;`async`<sup>?</sup> `?`<sup>?</sup> _ForLifetimes_<sup>?</sup> _TypePath_\
254+
> &nbsp;&nbsp;| `(` `async`<sup>?</sup> `?`<sup>?</sup> _ForLifetimes_<sup>?</sup> _TypePath_ `)`
255+
256+
**note**: The grammar specifies that any `for<'a>` higher-ranked lifetimes come *after* the `?` trait polarity. This seems inconsistent, but should be changed independently from this RFC. There's an open question about how to deal with the ordering problem of `?`, `for<'a>`, and `async`, or we want to separate `async` traits into their own production rule.
255257

256258
Since the grammar doesn't distinguish parenthesized and angle-bracketed generics in `_TypePath_`, `async` as a trait bound modifier will be **accepted** in all trait bounds at _parsing_ time, but it will be **denied** by the compiler _post-expansion_ if it's not attached to a parenthesized `Fn()` trait bound.
257259

@@ -583,7 +585,15 @@ Fixing this is a follow-up goal that we're interested in pursuing in the near fu
583585
# Unresolved questions
584586
[unresolved-questions]: #unresolved-questions
585587

586-
We leave no language questions unresolved in this RFC.
588+
### `? for<'a>` and its interaction with `async`
589+
590+
Currently on nightly, we parse the `async` trait bound modifier along with `?` (called polarity) *before* the `for<'a>` lifetime binders. This probably should get fixed so that the binder occurs on the *outside* of the trait, like so:
591+
592+
```
593+
where T: for<'a> async ?Trait
594+
```
595+
596+
(Which is semantically invalid but syntactically valid.) This is currently proposed in [rust-lang/rust#127054](https://github.com/rust-lang/rust/pull/127054), which should be decided before stabilization, and the stabilization report can re-confirm the correct ordering of `for<'a>` and `async`.
587597

588598
# Future possibilities
589599
[future-possibilities]: #future-possibilities

0 commit comments

Comments
 (0)