tokio-rs/tokio · error · syn::Error
`name` set multiple times.
Error message
`name` set multiple times.
What it means
The `#[tokio::main]` / `#[tokio::test]` attribute accepts a `name = "..."` option that sets the runtime builder's name. The macro's config builder (`set_name`, entry.rs:104) rejects a second `name` occurrence in the same invocation with a `syn::Error`, surfaced as a compile error.
Source
Thrown at tokio-macros/src/entry.rs:106
Configuration {
name: None,
rt_multi_thread_available: rt_multi_thread,
default_flavor: match is_test {
true => RuntimeFlavor::CurrentThread,
false => RuntimeFlavor::Threaded,
},
flavor: None,
worker_threads: None,
start_paused: None,
is_test,
crate_name: None,
unhandled_panic: None,
}
}
fn set_name(&mut self, name: syn::Lit, span: Span) -> Result<(), syn::Error> {
if self.name.is_some() {
return Err(syn::Error::new(span, "`name` set multiple times."));
}
let runtime_name = parse_string(name, span, "name")?;
self.name = Some(runtime_name);
Ok(())
}
fn set_flavor(&mut self, runtime: syn::Lit, span: Span) -> Result<(), syn::Error> {
if self.flavor.is_some() {
return Err(syn::Error::new(span, "`flavor` set multiple times."));
}
let runtime_str = parse_string(runtime, span, "flavor")?;
let runtime =
RuntimeFlavor::from_str(&runtime_str).map_err(|err| syn::Error::new(span, err))?;
self.flavor = Some(runtime);
Ok(())
}View on GitHub (pinned to 625954f365)
Solutions
- Remove the duplicate `name` argument so it appears exactly once.
- If two names were intended for different runtimes, split the code into two annotated entry points.
Example fix
// before
#[tokio::main(name = "rt1", name = "rt2")]
async fn main() {}
// after
#[tokio::main(name = "rt1")]
async fn main() {} Defensive patterns
Strategy: validation
Prevention
- Each `#[tokio::main]`/`#[tokio::test]` option key must appear at most once — self-check your attribute before compiling.
- When merging configs, replace rather than append option keys.
- Keep a single canonical macro invocation per entry point.
When it happens
Trigger: Writing `#[tokio::main(name = "a", name = "b")]` (or the `tokio::test` equivalent) — two `name` keys in one attribute.
Common situations: Merging two attribute configs by hand; copy-paste of options; editing tools that append rather than replace.
Related errors
- `flavor` set multiple times.
- `worker_threads` set multiple times.
- `start_paused` set multiple times.
- `crate` set multiple times.
- `unhandled_panic` set multiple times.
AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11).
Data as JSON: /api/errors/0eb845fb3c457c98.
Report an issue: GitHub.