-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Require explicitly marking closures as coroutines #123792
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Some changes occurred in tests/ui/sanitizer cc @rust-lang/project-exploit-mitigations, @rcvalle |
self.with_new_scopes(ident.span, |this| { | ||
self.with_new_scopes(span, |this| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to do this change as otherwise the span points to the identifier of functions instead of the fn
, so adding gen
would have resulted in fn gen foo
instead of gen fn foo
.
if this.token.uninterpolated_span().at_least_rust_2024() | ||
// check for `gen {}` and `gen move {}` | ||
// or `async gen {}` and `async gen move {}` | ||
&& (this.is_gen_block(kw::Gen, 0) | ||
|| (this.check_keyword(kw::Async) && this.is_gen_block(kw::Gen, 1))) | ||
{ | ||
// FIXME: (async) gen closures aren't yet parsed. | ||
this.parse_gen_block() | ||
} else if this.check_keyword(kw::Async) { | ||
if this.check_keyword(kw::Async) { | ||
// FIXME(gen_blocks): Parse `gen async` and suggest swap | ||
if this.is_gen_block(kw::Async, 0) { | ||
if this.is_gen_block(kw::Async, 0) || this.is_gen_block(kw::Gen, 1) { | ||
// Check for `async {` and `async move {`, | ||
this.parse_gen_block() | ||
} else { | ||
this.parse_expr_closure() | ||
} | ||
} else if this.check_keyword(kw::Gen) | ||
&& this.token.uninterpolated_span().at_least_rust_2024() | ||
{ | ||
if this.is_gen_block(kw::Gen, 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deserves further cleanup, but I think it's already an improvement if all the async
stuff always goes through the kw::Async
arm.
Also we can now gate the edition check on the keyword check, yay
f0906f5
to
b692d5b
Compare
Some changes occurred in tests/ui/sanitizer cc @rust-lang/project-exploit-mitigations, @rcvalle |
Let's not use gen as the keyword for this. That conflicts with gen closures, which we could have as a parallel to async closures, and is confusing given that gen fns and gen blocks also exist. |
Given that full/general coroutines still are not expected to land anytime soon, I'd rather if we don't add syntax for this at all, and just use an attr tbh |
b692d5b
to
3c91020
Compare
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in src/tools/clippy cc @rust-lang/clippy The Miri subtree was changed cc @rust-lang/miri Some changes occurred in coverage tests. cc @Zalathar Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead. cc @rust-lang/rust-analyzer Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
3c91020
to
d8ab6bf
Compare
This comment has been minimized.
This comment has been minimized.
d8ab6bf
to
2ddca19
Compare
This comment has been minimized.
This comment has been minimized.
Cool -- I appreciate this new approach. I will review it in detail when I find some time soon... |
2ddca19
to
37af228
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #123468) made this pull request unmergeable. Please resolve the merge conflicts. |
37af228
to
b32acf6
Compare
…er-errors Require explicitly marking closures as coroutines instead of relying on patching up the closure to be a coroutine if it happens to contain a `yield` expression. I only do this in the 2024 edition, as the `gen` keyword is only available there.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
2c39d20
to
bf436b5
Compare
msvc -.- @bors r=compiler-errors rollup=iffy |
☔ The latest upstream changes (presumably #124295) made this pull request unmergeable. Please resolve the merge conflicts. |
…ing `yield` expressions
And suggest adding the `#[coroutine]` to the closure
bf436b5
to
aef0f40
Compare
@bors r=compiler-errors rollup=iffy |
☀️ Test successful - checks-actions |
Finished benchmarking commit (e936289): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 673.226s -> 672.79s (-0.06%) |
This is required with rust-lang/rust#123792
This is required with rust-lang/rust#123792
instead of relying on patching up the closure to be a coroutine if it happens to contain a
yield
expression.I only do this in the 2024 edition, as the
gen
keyword is only available there.