tokio-rs/tokio · error · syn::Error
Failed to parse value of `{field}` as path.
Error message
Failed to parse value of `{field}` as path. What it means
Compile-time error from `parse_path`'s `_` arm: the value for the `crate` field is not a string literal at all. Distinct from error 22 (which fires when the string is present but unparseable).
Source
Thrown at tokio-macros/src/entry.rs:296
}
}
fn parse_path(lit: syn::Lit, span: Span, field: &str) -> Result<Path, syn::Error> {
match lit {
syn::Lit::Str(s) => {
let err = syn::Error::new(
span,
format!(
"Failed to parse value of `{}` as path: \"{}\"",
field,
s.value()
),
);
s.parse::<syn::Path>().map_err(|_| err.clone())
}
_ => Err(syn::Error::new(
span,
format!("Failed to parse value of `{field}` as path."),
)),
}
}
fn parse_bool(bool: syn::Lit, span: Span, field: &str) -> Result<bool, syn::Error> {
match bool {
syn::Lit::Bool(b) => Ok(b.value),
_ => Err(syn::Error::new(
span,
format!("Failed to parse value of `{field}` as bool."),
)),
}
}
fn contains_impl_trait(ty: &syn::Type) -> bool {
match ty {
syn::Type::ImplTrait(_) => true,
syn::Type::Array(t) => contains_impl_trait(&t.elem),View on GitHub (pinned to 625954f365)
Solutions
- Quote the path: `#[tokio::main(crate = "my_tokio")]`.
- Drop the `crate` option if you are not repointing the macro to a renamed crate.
Example fix
// before
#[tokio::main(crate = my_tokio)]
async fn main() {}
// after
#[tokio::main(crate = "my_tokio")]
async fn main() {} Defensive patterns
Strategy: validation
Prevention
- The `crate` field expects a quoted string literal, not an identifier or number.
- Prefer omitting `crate` unless you are vendoring/renaming tokio.
- Keep a single canonical macro snippet in docs.
When it happens
Trigger: `#[tokio::main(crate = 5)]`, `crate = true`, or `crate = 'a'`. Any non-string token for the `crate` field.
Common situations: Passing the crate as an identifier/path (`crate = my_tokio`) instead of a quoted string; passing a number/bool by mistake.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse value of `{field}` as integer.
- Failed to parse value of `{field}` as string.
- Failed to parse value of `{}` as path: "{}"
- Failed to parse value of `{field}` as bool.
- The #[tokio::main] macro requires rt or rt-multi-thread.
AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11).
Data as JSON: /api/errors/5eb200de83fad518.
Report an issue: GitHub.