tokio-rs/tokio · error · syn::Error
`crate` set multiple times.
Error message
`crate` set multiple times.
What it means
`set_crate_name` (entry.rs:156) records the first `crate = path` (an indirection used when tokio is re-exported under a different name) and rejects a second `crate` key in the same attribute.
Source
Thrown at tokio-macros/src/entry.rs:158
return Err(syn::Error::new(span, "`worker_threads` may not be 0."));
}
self.worker_threads = Some((worker_threads, span));
Ok(())
}
fn set_start_paused(&mut self, start_paused: syn::Lit, span: Span) -> Result<(), syn::Error> {
if self.start_paused.is_some() {
return Err(syn::Error::new(span, "`start_paused` set multiple times."));
}
let start_paused = parse_bool(start_paused, span, "start_paused")?;
self.start_paused = Some((start_paused, span));
Ok(())
}
fn set_crate_name(&mut self, name: syn::Lit, span: Span) -> Result<(), syn::Error> {
if self.crate_name.is_some() {
return Err(syn::Error::new(span, "`crate` set multiple times."));
}
let name_path = parse_path(name, span, "crate")?;
self.crate_name = Some(name_path);
Ok(())
}
fn set_unhandled_panic(
&mut self,
unhandled_panic: syn::Lit,
span: Span,
) -> Result<(), syn::Error> {
if self.unhandled_panic.is_some() {
return Err(syn::Error::new(
span,
"`unhandled_panic` set multiple times.",
));
}
View on GitHub (pinned to 625954f365)
Solutions
- Keep a single `crate = path` matching the re-exported tokio path.
Example fix
// before
#[tokio::main(crate = renamed_tokio, crate = tokio)]
async fn main() {}
// after
#[tokio::main(crate = renamed_tokio)]
async fn main() {} Defensive patterns
Strategy: validation
Prevention
- Set `crate = path` at most once, pointing at your tokio re-export.
- Only needed when tokio is re-exported under a different crate name.
- Remove the option entirely if you depend on tokio directly.
When it happens
Trigger: Writing `#[tokio::main(crate = my_tokio, crate = other)]`.
Common situations: Renaming the tokio dependency and leaving both the old and new `crate =` paths; merge conflicts in attributes.
Related errors
- `name` set multiple times.
- `flavor` set multiple times.
- `worker_threads` set multiple times.
- `start_paused` set multiple times.
- `unhandled_panic` set multiple times.
AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11).
Data as JSON: /api/errors/4cd0a0d0d4fd6ef2.
Report an issue: GitHub.