Skip to content

rustfmt fail (>Format Document) with async syntax (wrong edition) #2146

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

Closed
Speedy37 opened this issue Oct 31, 2019 · 4 comments · Fixed by #2477
Closed

rustfmt fail (>Format Document) with async syntax (wrong edition) #2146

Speedy37 opened this issue Oct 31, 2019 · 4 comments · Fixed by #2477

Comments

@Speedy37
Copy link
Contributor

Typing edition 2018 syntax like:

async fn test() {
    0;
}

Makes the formatting to fail with:

error[E0670]: `async fn` is not permitted in the 2015 edition
  --> <stdin>:25:1
   |
25 | async fn test() {
   | ^^^^^

In handlers.rs:547, rustfmt is started without an edition provided.
A workaround is to set the edition in rustfmt config file.
But I think rust-analyser should know the current edition, and provide it when running rustfmt

@matklad
Copy link
Member

matklad commented Dec 4, 2019

We run rustfmt as an external process, and I feel this is out of scope for the current implementation. Once we use rustfmt as a library (which won't be any time soon), we should make sure to pass the proper edition. For the time being, it seems like it might be a good idea for rustfmt to fetch edition from Cargo.toml? Otherwise, every project would have to use a dummy rustfmt.toml which sets an edition, which seems not really necessary from the user's POW.

@matklad matklad closed this as completed Dec 4, 2019
@matklad
Copy link
Member

matklad commented Dec 4, 2019

OTOH, I'll accept a PR which papers over this specific issue :)

@Speedy37
Copy link
Contributor Author

Speedy37 commented Dec 4, 2019

I've a local patch that add --edition 2018 to the command would you accept that?
Or you prefer to fetch the Cargo.toml edition related to the file and infer the edition from it?

@matklad
Copy link
Member

matklad commented Dec 4, 2019

I've a local patch that add --edition 2018 to the command would you accept that?

Just adding --edition 2018 would be wrong, b/c edition could be 2015. We need to check to which crate the current file belongs, and only pass this option if it matches Cargo.toml

bors bot added a commit that referenced this issue Dec 4, 2019
2477: Run rustfmt with respect to Cargo.toml edition r=matklad a=Speedy37

Fixes #2146
Fixes #1959

Co-authored-by: Vincent Rouillé <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants