Uh oh!
There was an error while loading. Please reload this page.
parser: recover on for<'a> |...| body closures - #70209
Conversation
There was a problem hiding this comment.
I guess what I was worried about is this any early exist from here resulting in a for loop successfully parsing but I guess that's not possible.
There was a problem hiding this comment.
I wonder if the language here could be more focused on the present rather than sounding absolute. Like "not yet supported" but maybe not suggesting future support is certain?
There was a problem hiding this comment.
We tend to shy away from "not yet" so as to not suggest that it will happen; "cannot" is a fairly standard start of a diagnostic message in the compiler.
eddyb
commented
Mar 21, 2020
cc @petrochenkov@nikomatsakis I don't want to unilaterally approve this, but I've been wanting make sure we don't paint ourselves into a corner wrt generic closure syntax (i.e. by it being ambiguous with |
622dbc5 to
13eb4dfComparepetrochenkov
commented
Mar 21, 2020
I'm mildly skeptical about this, the syntax is unlikely to be written accidentally, so there's not much motivation for doing this for recovery. Regarding future proofing, we already have ambiguities " |
13eb4df to
4d30b92CompareCentril
commented
Mar 21, 2020
Switched over to As for the for-loop thing. Keeping in mind that these must be irrefutable patterns using |
petrochenkov
commented
Mar 21, 2020
@bors r+ |
bors
commented
Mar 21, 2020
📌 Commit 4d30b92 has been approved by |
…trochenkov parser: recover on `for<'a> |...| body` closures When encountering `for` and `<` is 1 token ahead, interpret this as an explicitly quantified generic closure and recover, rather than attempting to parse a `for` loop. This provides both improved diagnostics as well as an insurance policy for the ability to use this as the syntax for generic closures in the future. As requested by r? @eddyb
Rollup of 10 pull requests Successful merges: - rust-lang#68099 (Amend Rc/Arc::from_raw() docs regarding unsafety) - rust-lang#70172 (parse/lexer: support `StringReader::retokenize` called on external files.) - rust-lang#70209 (parser: recover on `for<'a> |...| body` closures) - rust-lang#70223 (fix type of const params in associated types.) - rust-lang#70229 (more clippy fixes) - rust-lang#70240 (Return NonZeroU64 from ThreadId::as_u64.) - rust-lang#70250 (Remove wrong entry from RELEASES.md) - rust-lang#70253 (Remove another wrong entry from RELEASES.md) - rust-lang#70254 (couple more clippy fixes (let_and_return, if_same_then_else)) - rust-lang#70266 (proc_macro_harness: Use item header spans for errors) Failed merges: r? @ghost
Is it ok that this artificial example no longer compiles in nightly? https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c444d791d838b73c5ad3e9813e9838c6 #[derive(PartialEq,Eq)]structA;implA{constA:A = A;}fnmain(){for <A>::Ainvec![A]{}} |
nikomatsakis
commented
Mar 23, 2020
So, let me understand what happened here:
|
fmease
commented
Jan 14, 2022
for future reference, linking rust-lang/rfcs#3216 |
dtolnay
commented
Aug 15, 2025
This is referring to #61682. An irrefutable pattern with a uni-valued associated constant would have worked since Rust 1.20 (#42809) — but is even less likely to appear in real code. structT;implT{constUNIT:() = ();}fnmain(){let _ = for <T>::UNITinNone{};} |
When encountering
forand<is 1 token ahead, interpret this as an explicitly quantified generic closure and recover, rather than attempting to parse aforloop. This provides both improved diagnostics as well as an insurance policy for the ability to use this as the syntax for generic closures in the future.As requested by r? @eddyb