I have been using the #[tokio::main]
macro in one of my programs. After importing main
and using it unqualified, I encountered an unexpected error.
use tokio::main;
#[main]
async fn main() {}
error[E0659]: `main` is ambiguous
--> src/main.rs:3:3
|
3 | #[main]
| ^^^^ ambiguous name
|
= note: ambiguous because of a name conflict with a builtin attribute
= note: `main` could refer to a built-in attribute
I've been scouring the documentation but I haven't been able to find this built-in #[main]
attribute described anywhere. The Rust Reference contains an index of built-in attributes. The index doesn't include #[main]
, though it does include an attribute named #[no_main]
.
I did a search of the rustlang/rust
repository, and found some code that seems related, but it seems to use a pair of macros named #[start]
and #[rustc_main]
, with no mention of #[main]
itself. (Neither of those macros appears to be usable on stable, with #[start]
emitting an error that it's unstable, and #[rustc_main]
emitting an error that it's only meant for internal use by the compiler.)
My guess from the name would have been that it's meant to mark a different function as an entry-point instead of main
, but it also doesn't seem to do that:
#[main]
fn something_else() {
println!("this does not run");
}
fn main() {
println!("this runs");
}
Rust Analyzer didn't have much to offer:
What does the built-in #[main]
attribute do, aside from conflicting with my imports?