rust-lang/cargo · error

no such subcommand `{cmd}`{suggested_command}{suggested_scri

Error message

no such subcommand `{cmd}`{suggested_command}{suggested_script}

What it means

Raised in the (false, false) arm of exec_manifest_command (run.rs:141-176): the token is neither an existing file nor usable as a script, and script support is off. Cargo could not find a matching built-in or third-party subcommand, so it reports `no such subcommand` with optional suggestions for close command names or scripts that require `-Zscript`.

Source

Thrown at src/bin/cargo/commands/run.rs:172

                    format!(
                        " {}",
                        args.into_iter().map(|os| os.to_string_lossy()).join(" ")
                    )
                };
                format!(
                    "\nhelp: there is a command with a similar name: `{suggested_command} {actual_args}{args}`"
                )
            } else {
                "".to_owned()
            };
            let suggested_script = if let Some(suggested_script) = suggested_script(cmd) {
                format!(
                    "\nhelp: there is a script with a similar name: `{suggested_script}` (requires `-Zscript`)"
                )
            } else {
                "".to_owned()
            };
            return Err(anyhow::anyhow!(
                "no such subcommand `{cmd}`{suggested_command}{suggested_script}"
            )
            .into());
        }
    }

    let manifest_path = root_manifest(Some(manifest_path), gctx)?;

    // Treat `cargo foo.rs` like `cargo install --path foo` and re-evaluate the config based on the
    // location where the script resides, rather than the environment from where it's being run.
    let parent_path = manifest_path
        .parent()
        .expect("a file should always have a parent");
    gctx.reload_rooted_at(parent_path)?;

    let mut ws = Workspace::new(&manifest_path, gctx)?;
    if gctx.cli_unstable().avoid_dev_deps {
        ws.set_require_optional_deps(false);

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Check spelling against `cargo --list`.
  2. Install the intended external command: `cargo install cargo-<name>`.
  3. If the suggestion mentions a script, run on nightly with `-Zscript`.
  4. If you meant to run a file, ensure the path exists and pass `-Zscript`.

Example fix

// before
$ cargo bulid
error: no such subcommand `bulid`
help: there is a command with a similar name: `build`

// after
$ cargo build
Defensive patterns

Strategy: validation

Validate before calling

// Validate the subcommand before exec'ing cargo
let known = list_builtin_commands().iter().any(|c| c == cmd)
    || third_party_installed(cmd)      // cargo-<cmd> on PATH
    || Path::new(cmd).is_file();
if !known {
    eprintln!("unknown cargo subcommand `{cmd}`; check `cargo --list`");
}

Type guard

fn looks_like_valid_cargo_cmd(cmd: &str, installed: &[String]) -> bool {
    let is_builtin = matches!(cmd, "build"|"run"|"test"|"check"|"doc"|"tree"|"update"|/* ... */);
    is_builtin || installed.iter().any(|c| c == cmd)
}

Prevention

When it happens

Trigger: Running `cargo foobar` where `foobar` is not a built-in command, not a `cargo-foobar` executable on PATH, not an existing file, and `-Zscript` is not enabled.

Common situations: Typos in subcommand names; expecting a third-party subcommand that isn't installed; using a nightly-only subcommand on stable; stale muscle memory after a subcommand was renamed.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/08e1b05ea9eceafd.json. Report an issue: GitHub.