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 functions in sub-crate break formatting #13790

Closed
fmeef opened this issue Dec 17, 2022 · 2 comments · Fixed by #13795
Closed

Async functions in sub-crate break formatting #13790

fmeef opened this issue Dec 17, 2022 · 2 comments · Fixed by #13795
Assignees
Labels
A-formatting formatting of r-a output/formatting on save C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now

Comments

@fmeef
Copy link

fmeef commented Dec 17, 2022

rust-analyzer version: 21e61be 2022-12-10

rustc version: rustc 1.66.0 (69f9c33d7 2022-12-12)

relevant settings: helix editor with default settings

When working with a project composed of multiple local crates added via lib = { path = "./lib" } in cargo.toml formatting seems to fail if an async function or an async block is present in the current file. This seems to affect the entire file where async code is present. Running formatting on the topmost crate even when multiple crates are in cargo.toml causes formatting to run correctly. Running cargo fmt always works even when rust-analyzer fails to format

I created a minimal reproduction here https://github.com/fmeef/rust-analyzer-format-fail/, attempting to format the lib.rs file in the lib crate results in nothing actually happening.

@jonas-schievink
Copy link
Contributor

[WARN rust_analyzer::handlers] rustfmt exited with status 1 command="rustfmt" captured_stderr=error[E0670]: `async fn` is not permitted in Rust 2015

Are we not passing --edition 2021 to rustfmt in all cases? Clearly most of the time we are, or you couldn't format async code at all. Weird.

@jonas-schievink jonas-schievink added S-actionable Someone could pick this issue up and work on it right now C-bug Category: bug A-formatting formatting of r-a output/formatting on save labels Dec 19, 2022
@jonas-schievink
Copy link
Contributor

Ah, the package in question is a path dependency, but not a workspace member, so cargo_target_for_crate_root returns None, and we can't determine the edition in use.

Maybe that code should use the crate graph instead of looking at the Cargo workspace info? The crate graph also stores the edition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-formatting formatting of r-a output/formatting on save C-bug Category: bug S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants