tokio-rs/tokio · error · syn::Error
Failed to parse value of `{}` as path: "{}"
Error message
Failed to parse value of `{}` as path: "{}" What it means
Compile-time error from `parse_path` when the value IS a string literal but its contents cannot be parsed as a `syn::Path`. Used only by the `crate` field (see `set_crate_name` calling `parse_path(..., "crate")` in entry.rs:160). The offending string is echoed back in the message.
Source
Thrown at tokio-macros/src/entry.rs:287
fn parse_string(int: syn::Lit, span: Span, field: &str) -> Result<String, syn::Error> {
match int {
syn::Lit::Str(s) => Ok(s.value()),
syn::Lit::Verbatim(s) => Ok(s.to_string()),
_ => Err(syn::Error::new(
span,
format!("Failed to parse value of `{field}` as string."),
)),
}
}
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,View on GitHub (pinned to 625954f365)
Solutions
- Supply a valid Rust path expression: `#[tokio::main(crate = "my_tokio")]` where `my_tokio` is the actual crate name in `Cargo.toml`.
- Remove the `crate = ...` option entirely if you are not repointing tokio.
- Verify the crate is actually a dependency under that exact name.
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
- Provide the `crate` option only when repointing to a renamed tokio, and quote a valid Rust path.
- Use the exact crate name from `Cargo.toml`.
- Omit `crate = ...` entirely in normal projects.
When it happens
Trigger: `#[tokio::main(crate = "123")]`, `crate = "with spaces"`, `crate = "@@@"`, or any string that is not a valid Rust path — e.g. a renamed-crate path that isn't a valid identifier path.
Common situations: Using `crate = "my_tokio"` to redirect to a vendored/renamed tokio but mistyping it; pasting a version number, a URL, or a freeform label instead of a path; confusing it with a Cargo feature name.
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 `{field}` 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/65ec18c298eeacb6.
Report an issue: GitHub.