Reorder trait bound modifiers after for<...>
binder in trait bounds by compiler-errors · Pull Request #127054 · rust-lang/rust (original) (raw)
This PR suggests changing the grammar of trait bounds from:
[CONSTNESS] [ASYNCNESS] [?] [BINDER] [TRAIT_PATH]
const async ? for<'a> Sized
to
([BINDER] [CONSTNESS] [ASYNCNESS] | [?]) [TRAIT_PATH]
i.e., either
or
for<'a> const async Sized
(but not both)
Why?
I think it's strange that the binder applies "more tightly" than the ?
trait polarity. This becomes even weirder when considering that we (or at least, I) want to have async
trait bounds expressed like:
where T: for<'a> async Fn(&'a ()) -> i32,
and not:
where T: async for<'a> Fn(&'a ()) -> i32,
Fallout
No crates on crater use this syntax, presumably because it's literally useless. This will require modifying the reference grammar, though.
Alternatives
If this is not desirable, then we can alternatively keep parsing for<'a>
after the ?
but deprecate it with either an FCW (or an immediate hard error), and begin parsing for<'a>
before the ?
.