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

  1. Supply a valid Rust path expression: `#[tokio::main(crate = "my_tokio")]` where `my_tokio` is the actual crate name in `Cargo.toml`.
  2. Remove the `crate = ...` option entirely if you are not repointing tokio.
  3. 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

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

Related errors


AI-assisted analysis of tokio-rs/tokio@625954f365 (2026-08-11). Data as JSON: /api/errors/65ec18c298eeacb6. Report an issue: GitHub.