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 fn + rustfmt don't "just work" inside of RLS #61072

Closed
nikomatsakis opened this issue May 23, 2019 · 16 comments
Closed

async fn + rustfmt don't "just work" inside of RLS #61072

nikomatsakis opened this issue May 23, 2019 · 16 comments

Comments

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented May 23, 2019

If you create a new rust project in the RLS and try to use async fn:

async fn foo() { }
fn main() { }

you will get errors from rustfmt that async fn is not supported in the 2015 Edition when you attempt to format. This is true even if your project is in Rust 2018. Presumably the RLS is not supplying the correct version information. I view this as a fairly large "user experience" problem.

Note: Probably this should be filed on the RLS repository, but I wanted to file a bug here so that we could track it more easily as a potential blocker for stabilization (I would consider it to be one). I think in the future we should be tracking said bugs through repository-wise searches to avoid this sort of dilemma, but anyway.

cc @Xanewok -- any thoughts?

@Xanewok
Copy link
Member

@Xanewok Xanewok commented May 23, 2019

This is one of the cases where RLS is overzealous when it comes to making sure we've picked up a right edition, to the point where it refuses to do any work if it's not 100% sure (and it doesn't pick up the correct edition, which is another case).

To provide some more context on why's that, it's technically possible for a file to fall under multiple editions - an edge case where we have separate crates with different editions in Cargo.toml which pull in the same module. Since we issue format request for a given file, we do not disambiguate now and thus we first run analysis compilation, detect which files were part of a given crate and only then allow to format a file with a detected edition.

It seems that the edition detection has regressed recently so that's probably the case why it continues to not work in the 2018 edition - will look into it.

@cramertj
Copy link
Member

@cramertj cramertj commented May 23, 2019

Hey @Centril you're tagging all of this issues as async/await blocking -- can you explain why that is? IMO bugs in editors and things shouldn't block stabilization of async/await.

@Centril
Copy link
Contributor

@Centril Centril commented May 23, 2019

Hey @Centril you're tagging all of this issues as async/await blocking -- can you explain why that is? IMO bugs in editors and things shouldn't block stabilization of async/await.

Per Niko's note:

Note: Probably this should be filed on the RLS repository, but I wanted to file a bug here so that we could track it more easily as a potential blocker for stabilization (I would consider it to be one).

@cramertj
Copy link
Member

@cramertj cramertj commented Jun 4, 2019

@Xanewok have you had a chance to investigate this further?

@Xanewok
Copy link
Member

@Xanewok Xanewok commented Jun 10, 2019

@cramertj sorry, not yet. I'll work on this this week.

@cramertj
Copy link
Member

@cramertj cramertj commented Jun 14, 2019

@Xanewok Were you able to look into this?

@Xanewok
Copy link
Member

@Xanewok Xanewok commented Jun 18, 2019

Yeah, sorry for the radio silence.

Looking at this now, the edition is correctly inferred (if you use edition = "2018" in Cargo.toml that's now supplied by default for cargo new) in the code path but currently this fails on newest nightly due to

async fn is unstable

note: for more information, see https://github.com/rust-lang/rust/issues/50547
help: add #![feature(async_await)] to the crate attributes to enable

As it is now, if the analyzed code doesn't successfully compile as a whole the RLS doesn't update cached input files for crates in the workspace - which means the cache is empty and we're not 100% sure what should be edition and just bail.
That's something that we definitely should improve as it's bad user experience but this also means that sticking feature at the top like so:

#![feature(async_await)]

async fn foo() { }
fn main() { }

correctly causes cache to update and thus formatting to succeed, hopefully unblocking the work here.
@nikomatsakis @cramertj should we drop the async/await blocking label then?

@nikomatsakis
Copy link
Contributor Author

@nikomatsakis nikomatsakis commented Jun 25, 2019

Closing as fixed.

@omarabid
Copy link

@omarabid omarabid commented Nov 25, 2019

I'm still having this problem with Rust 1.39 (stable) or Rust 1.41 (nightly) with rustfmt 1.4.9 (nightly).

@kenkoooo
Copy link

@kenkoooo kenkoooo commented Nov 27, 2019

I have this problem with the IntelliJ plugin. It happened because the default edition of rustfmt is not 2018 but 2015. I resolved this issue by setting edition = "2018" in .rustfmt.toml.

@omarabid
Copy link

@omarabid omarabid commented Nov 27, 2019

Thanks @kenkoooo. That was the issue.

@ashthespy
Copy link

@ashthespy ashthespy commented Mar 12, 2020

Closing as fixed.

Just ran into the same issue with rustc 1.41.0 (5e1a79984 2020-01-27)

LuRsT added a commit to LuRsT/breezometer_dummy_api that referenced this issue Mar 28, 2020
Had to use vim's `=` to format the file since rustfmt wasn't working.
Also add .rustfmt.toml so `rustfmt` doesn't error out with 2015 edition
errors like `async` not being correct.

As per:
rust-lang/rust#61072
@harrisonthorne
Copy link

@harrisonthorne harrisonthorne commented May 23, 2020

@ashthespy Did you edit or add a rustfmt.toml config file as kenkoooo did? Adding one in my home directory with edition = "2018" at the top fixed this issue for me.

@Clee681
Copy link

@Clee681 Clee681 commented Nov 30, 2020

I just hit this issue while using rustfmt 1.4.24-stable (eb894d53 2020-11-05). I get the below error message despite edition being set to 2018 in my Cargo.toml file.

    | ^^^^^ to use `async fn`, switch to Rust 2018
    |
    = help: set `edition = "2018"` in `Cargo.toml`

@vjyanand
Copy link

@vjyanand vjyanand commented Dec 18, 2020

I just hit this issue while using rustfmt 1.4.24-stable (eb894d53 2020-11-05). I get the below error message despite edition being set to 2018 in my Cargo.toml file.

    | ^^^^^ to use `async fn`, switch to Rust 2018
    |
    = help: set `edition = "2018"` in `Cargo.toml`

What's the fix? Thanks

@DanielJoyce
Copy link

@DanielJoyce DanielJoyce commented Mar 11, 2021

Same on 1.50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet