Skip to content
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

async closure syntax causes compiler error in disabled code block #125366

Closed
conradludgate opened this issue May 21, 2024 · 3 comments
Closed

async closure syntax causes compiler error in disabled code block #125366

conradludgate opened this issue May 21, 2024 · 3 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.

Comments

@conradludgate
Copy link
Contributor

I tried this code:

#[cfg_attr(feature = "foobar", features(async_fn_traits))]

#[cfg(feature = "foobar")]
fn test() {
    let x = async || {};
}

I expected to see this happen: program compiles on stable when "foobar" feature is not set.

Instead, this happened:

error[E0658]: async closures are unstable
 --> src/lib.rs:5:13
  |
5 |     let x = async || {};
  |             ^^^^^
  |
  = note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
  = help: to use an async block, remove the `||`: `async {`

Meta

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2
@conradludgate conradludgate added the C-bug Category: This is a bug. label May 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 21, 2024
@fmease fmease added C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 21, 2024
@fmease
Copy link
Member

fmease commented May 21, 2024

This works as intended. Feature gates for experimental syntax extensions are intentionally run before macro expansion to prevent stable code from relying on it. We promise not to break stable code (with some exceptions ofc). Permitting experimental syntax in “cfg'ed out” code would hinder us to adjust or remove the syntax as stable crates could now fail with syntax errors.

@fmease
Copy link
Member

fmease commented May 21, 2024

We have some syntax extensions which still have post-expansion feature gates (which used to be default in the past iirc) like auto_traits. Due to the aforementioned reasons, we can't change the syntax of auto traits anymore (not easily at least).

@conradludgate
Copy link
Contributor Author

Right. Makes sense. Found a workaround using declarative macros since they skip the parser during this phase.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.
Projects
None yet
Development

No branches or pull requests

3 participants