{"id":"9a7826bb7a2db8cc","repo":"rust-lang/cargo","slug":"expected-rustc-as-first-argument","errorCode":null,"errorMessage":"expected rustc as first argument","messagePattern":"expected rustc as first argument","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_fix/mod.rs","lineNumber":1262,"sourceCode":"                }\n            }\n            other.push(path.into());\n            Ok(())\n        };\n\n        if let Some(argfile_path) = rustc.to_str().unwrap_or_default().strip_prefix(\"@\") {\n            // Because cargo in fix-proxy-mode might hit the command line size limit,\n            // cargo fix need handle `@path` argfile for this special case.\n            if argv.next().is_some() {\n                bail!(\"argfile `@path` cannot be combined with other arguments\");\n            }\n            let contents = fs::read_to_string(argfile_path)\n                .with_context(|| format!(\"failed to read argfile at `{argfile_path}`\"))?;\n            let mut iter = contents.lines().map(OsString::from);\n            rustc = iter\n                .next()\n                .map(PathBuf::from)\n                .ok_or_else(|| anyhow::anyhow!(\"expected rustc as first argument\"))?;\n            for arg in iter {\n                handle_arg(arg)?;\n            }\n        } else {\n            for arg in argv {\n                handle_arg(arg)?;\n            }\n        }\n\n        let file = file.ok_or_else(|| anyhow::anyhow!(\"could not find .rs file in rustc args\"))?;\n        #[expect(\n            clippy::disallowed_methods,\n            reason = \"internal only, no reason for config support\"\n        )]\n        let idioms = env::var(IDIOMS_ENV_INTERNAL).is_ok();\n\n        #[expect(\n            clippy::disallowed_methods,","sourceCodeStart":1244,"sourceCodeEnd":1280,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_fix/mod.rs#L1244-L1280","documentation":"Thrown in FixArgs::from_args (src/ops/cargo_fix/mod.rs:1250-1262) when the first argument was an `@path` argfile (read successfully) but the argfile's first line — which must be the rustc executable path — was missing. The argfile parsing expects line 1 = rustc, remaining lines = args.","triggerScenarios":"Cargo-fix proxy mode with an `@path` argfile whose contents are empty or do not start with a rustc path. Triggered when the command line is too long and cargo writes an argfile, but that file is malformed/truncated.","commonSituations":"A truncated/empty argfile from a filesystem issue or a crashed writer. A third-party tool that generates the argfile incorrectly. Race condition where the argfile was overwritten between write and read.","solutions":["Re-run `cargo fix` to let cargo regenerate the argfile.","Check disk space / permissions in the temp directory where argfiles are written.","Avoid the argfile path by shortening the command line (fewer features/targets).","Reinstall/upgrade cargo if the argfile generation is buggy in your version."],"exampleFix":"# before: argfile contents missing the rustc line\n# (file at @path starts with --cfg, no rustc)\n\n# after: regenerate via a clean run\ncargo clean\ncargo fix --allow-dirty","handlingStrategy":"validation","validationCode":"// For an @path argfile, require a non-empty first line as the rustc path.\nfn argfile_ok(contents: &str) -> bool {\n    contents.lines().next().map(|l| !l.trim().is_empty()).unwrap_or(false)\n}","typeGuard":"fn argfile_has_rustc(contents: &str) -> bool {\n    argfile_ok(contents)\n}","tryCatchPattern":"match FixArgs::from_args(argv) {\n    Err(e) if e.to_string().contains(\"expected rustc as first argument\") => {\n        eprintln!(\"argfile is missing its rustc line; re-run cargo fix\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Keep temp dir writable and with free space so argfiles are written fully.","Shorten command lines to avoid the argfile path under cargo fix."],"tags":["cargo","cargo-fix","proxy","argfile","rustc","internal"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}