rustfmt doesn't see Cargo.toml file correctly ?
alarsyo opened this issue · 9 comments
in a newly created project, I have this in main.rs
:
#[async_std::main]
async fn main() {
println!("Hello, world!");
}
When saving the buffer, I get the following error:
error[E0670]: `async fn` is not permitted in the 2015 edition
--> /home/alarsyo/work/more-jpeg/src/main.rs:2:1
|
2 | async fn main() {
| ^^^^^
|
= note: to use `async fn`, switch to Rust 2018
= help: set `edition = "2018"` in `Cargo.toml`
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
This is a project I just created with cargo new
, so it already has the 2018 edition setting. Running rustic-cargo-fmt
doesn't have that problem, as it find the Cargo file correctly.
I'm on Doom emacs, if that helps.
Is it possible that you also need a rustfmt.toml ?
I have the same issue even with rustfmt.toml
. It works at the command line if I run rustfmt --emit stdout src\routes.rs
(Windows, FYI) but if I try it from in rustic-mode
it gives me the same error about async functions as @alarsyo described. I would be happy to use rustic-cargo-fmt
, but that doesn’t revert the buffers.
Yes, same for me, reverting the buffers when running rustic-cargo-fmt
would also help replacing the format on save.
When I put edition = "2018"
in the rustfmt.toml it works. Can you please give it a try.
It worked this time. Not sure why putting that in rustfmt.toml
didn’t work earlier, but I’m glad it did this time. Thanks!
@alarsyo I documented it in the readme. Please reopen the issue if you still got problems with this.
@brotzeit Would it make sense to use cargo fmt
for format-on-save instead of rustfmt
directly? (with config option). That way, the edition would be picked up from Cargo.toml
.
Actually, nevermind. It looks like cargo fmt
can't format a single file -- only a whole project. See rust-lang/rustfmt#4074.
How does e.g. VSCode do it? They have format-on-save, but I never had to create a rustfmt.toml
file to specify that it's using the 2021 edition. Maybe we can have an option to use cargo fmt
instead of rustfmt
on save anyways, regardless if it tries to format the whole project?