rust-lang/cargo · error · anyhow::Error
expected rustc or `@path` as first argument
Error message
expected rustc or `@path` as first argument
What it means
Thrown in FixArgs::from_args (src/ops/cargo_fix/mod.rs:1224-1229) when cargo is running as the rustc proxy during `cargo fix` and argv has no second element (no rustc/`@path` after the program name). This is an internal contract: cargo-fix invokes itself with the rustc executable as the first real argument.
Source
Thrown at src/ops/cargo_fix/mod.rs:1229
other: Vec<OsString>,
/// Path to the `rustc` executable.
rustc: PathBuf,
/// Path to host sysroot.
sysroot: Option<PathBuf>,
}
impl FixArgs {
fn get() -> CargoResult<FixArgs> {
Self::from_args(env::args_os())
}
// This is a separate function so that we can use it in tests.
fn from_args(argv: impl IntoIterator<Item = OsString>) -> CargoResult<Self> {
let mut argv = argv.into_iter();
let mut rustc = argv
.nth(1)
.map(PathBuf::from)
.ok_or_else(|| anyhow::anyhow!("expected rustc or `@path` as first argument"))?;
let mut file = None;
let mut enabled_edition = None;
let mut other = Vec::new();
let mut handle_arg = |arg: OsString| -> CargoResult<()> {
let path = PathBuf::from(arg);
if path.extension().and_then(|s| s.to_str()) == Some("rs") && path.exists() {
file = Some(path);
return Ok(());
}
if let Some(s) = path.to_str() {
if let Some(edition) = s.strip_prefix("--edition=") {
enabled_edition = Some(edition.parse()?);
return Ok(());
}
}
other.push(path.into());
Ok(())View on GitHub (pinned to 0e07a15537)
Solutions
- Re-run `cargo fix` normally (without a custom proxy wrapper) so cargo assembles the correct argv.
- Update/reinstall cargo to rule out a corrupted toolchain.
- If you are invoking the proxy manually, pass the rustc executable path as the first argument (or `@argfile`).
- Reduce command-line length so the @path argfile mechanism is not triggered incorrectly.
Example fix
# before: manual proxy call missing rustc arg /home/user/.cargo/bin/cargo-fix # after: let cargo invoke the proxy cargo fix --edition
Defensive patterns
Strategy: validation
Validate before calling
// Internal proxy contract: argv must contain at least program + rustc path.
fn proxy_argv_ok(argv: &[std::ffi::OsString]) -> bool {
argv.len() >= 2
}
// assert!(proxy_argv_ok(&env::args_os().collect::<Vec<_>>())); Type guard
fn has_rustc_or_argfile(argv: &[std::ffi::OsString]) -> bool {
argv.get(1).is_some()
} Try / catch
// FixArgs::from_args is internal; surface a clear message if it fails.
match FixArgs::from_args(env::args_os()) {
Err(e) if e.to_string().contains("expected rustc") => {
eprintln!("proxy invoked without a rustc argument; re-run `cargo fix` normally");
return Err(e);
}
r => r,
} Prevention
- Do not invoke the cargo-fix proxy binary directly; use `cargo fix`.
- Keep the toolchain intact to ensure correct proxy argv.
When it happens
Trigger: The proxy entry point receives fewer than two arguments — e.g. the FIX-related env drove cargo into proxy mode but the invoking command lacked the rustc path. Essentially an internal/invocation bug, not a user manifest error.
Common situations: A wrapper or custom tool calling the cargo-fix proxy binary with no rustc argument. Corruption of the proxy command line (e.g. very long arg lists causing the @path argfile path to be dropped). Broken cargo installation or shim that strips arguments.
Related errors
- expected rustc as first argument
- could not find .rs file in rustc args
- able to invoke rustc
- malformed output when learning about crate-type {} informati
- output of --print={request} missing when learning about targ
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/02be171baa02a191.json.
Report an issue: GitHub.