You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0670]: `async fn` is not permitted in Rust 2015
--> main.rs:1:1
|
1 | async fn main() {}
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
|
= help: set `edition = "2021"` in `Cargo.toml`
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
error[E0752]: `main` function is not allowed to be `async`
--> main.rs:1:1
|
1 | async fn main() {}
| ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0670, E0752.
For more information about an error, try `rustc --explain E0670`.
Here is my Cargo.toml file:
[package]
name = "visualizer"
version = "0.1.0"
edition = '2021'
Here is what it auto-generates in Cargo.lock file:
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "visualizer"
version = "0.1.0"
ATTEMPTED SOLUTION:
I removed the async keyword in async fn main() {} so it became fn main() {} in main.rs. Then I did the following in the terminal:
$ cargo fix --edition
Checking visualizer v0.1.0 ( // I manually removed the path for privacy reasons )
warning: `src/main.rs` is already on the latest edition (2021), unable to migrate further
If you are trying to migrate from the previous edition (2018), the
process requires following these steps:
1. Start with `edition = "2018"` in `Cargo.toml`
2. Run `cargo fix --edition`
3. Modify `Cargo.toml` to set `edition = "2021"`
4. Run `cargo build` or `cargo test` to verify the fixes worked
More details may be found at
https://doc.rust-lang.org/edition-guide/editions/transitioning-an-existing-project-to-a-new-edition.html
Finished dev [unoptimized + debuginfo] target(s) in 0.29s
So I changed edition = "2021" into edition = "2015" in Cargo.toml. Then I did the following in the terminal:
$ cargo fix --edition
Checking visualizer v0.1.0 ( // I manually removed the path for privacy reasons )
Migrating src/main.rs from 2015 edition to 2018
Finished dev [unoptimized + debuginfo] target(s) in 0.95s
Then I edited back from edition = "2015" to edition = "2021" and did the following in the terminal:
$ cargo build
Compiling visualizer v0.1.0 ( // I manually removed the path for privacy reasons )
Finished dev [unoptimized + debuginfo] target(s) in 0.37s
$ cargo test
Compiling visualizer v0.1.0 ( // I manually removed the path for privacy reasons )
Finished test [unoptimized + debuginfo] target(s) in 0.26s
Running unittests ( // I manually removed the path for privacy reasons )
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Then I changed back from fn main() {} to async fn main() {} in main.rs, and here's the output I get:
error[E0670]: `async fn` is not permitted in Rust 2015
--> main.rs:1:1
|
1 | async fn main() {}
| ^^^^^ to use `async fn`, switch to Rust 2018 or later
|
= help: set `edition = "2021"` in `Cargo.toml`
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
error[E0752]: `main` function is not allowed to be `async`
--> main.rs:1:1
|
1 | async fn main() {}
| ^^^^^^^^^^^^^^^ `main` function is not allowed to be `async`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0670, E0752.
For more information about an error, try `rustc --explain E0670`.
[Done] exited with code=1 in 0.1 seconds
That's strange. For some reason, the edition field is not being picked up. Are those error messages coming directly from running cargo in a terminal? Or are you using something else? I noticed you say you have rust-analyzer and vscode, perhaps you are somehow checking the code in there? If so, what exact steps are you taking to get that output?
I notice that your error message has a path like main.rs. That is unusual in a cargo project, as main.rs is usually inside a src directory, and the messages should say src/main.rs. Do you have a standard cargo project layout?
Here's my code in main.rs :
Here's the output:
Here is my Cargo.toml file:
Here is what it auto-generates in Cargo.lock file:
ATTEMPTED SOLUTION:
I removed the
async
keyword inasync fn main() {}
so it becamefn main() {}
in main.rs. Then I did the following in the terminal:So I changed
edition = "2021"
intoedition = "2015"
in Cargo.toml. Then I did the following in the terminal:Then I edited back from
edition = "2015"
toedition = "2021"
and did the following in the terminal:Then I changed back from
fn main() {}
toasync fn main() {}
in main.rs, and here's the output I get:Thus, my attempted solution has failed.
Rust Version
rust-analyzer 2022-05-09
Editor:
VSCode
Operating System:
Archlinux
rust-analyzer version: rust-analyzer version: 5d5bbec 2022-05-09 stable
rustc version: rustc 1.59.0 (9d1b210 2022-02-23)
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTUP_HOME
orCARGO_HOME
)The text was updated successfully, but these errors were encountered: