{"id":"7b001145aba1115c","repo":"rust-lang/cargo","slug":"could-not-find-rs-file-in-rustc-args","errorCode":null,"errorMessage":"could not find .rs file in rustc args","messagePattern":"could not find \\.rs file in rustc args","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_fix/mod.rs","lineNumber":1272,"sourceCode":"                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,\n            reason = \"internal only, no reason for config support\"\n        )]\n        let prepare_for_edition = env::var(EDITION_ENV_INTERNAL).ok().map(|v| {\n            let enabled_edition = enabled_edition.unwrap_or(Edition::Edition2015);\n            let mode = EditionFixMode::from_str(&v);\n            mode.next_edition(enabled_edition)\n        });\n\n        #[expect(\n            clippy::disallowed_methods,","sourceCodeStart":1254,"sourceCodeEnd":1290,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_fix/mod.rs#L1254-L1290","documentation":"Thrown in FixArgs::from_args (src/ops/cargo_fix/mod.rs:1272) after parsing all proxy arguments: none of them was an existing .rs source file. The handle_arg closure only sets `file` when it finds an argument whose extension is `.rs` and which exists on disk; if none matched, `file` stays None and bail fires.","triggerScenarios":"Cargo-fix proxy mode where the rustc invocation's arguments contain no .rs path that exists (e.g. only --cfg/--emit flags, or a .rs path that was deleted/renamed between cargo's scheduling and the fix proxy run). The final `file.ok_or_else` fails.","commonSituations":"A source file was removed or moved after cargo scheduled the build but before the fix proxy executed. A generated source file that does not exist yet. Filesystem case mismatch on case-sensitive volumes. A wrapper that rewrites rustc args and drops the source path.","solutions":["Ensure the .rs source file exists at the path cargo expects (it is usually src/main.rs or src/lib.rs).","Re-run `cargo fix` after `cargo clean` to rebuild the unit graph against current files.","If the file is generated, make sure the generator (build.rs / xtask) runs before fix.","Avoid wrappers that strip the source .rs argument from the rustc command line."],"exampleFix":"# before: src/cli.rs deleted, `cargo fix` cannot find a .rs arg\nrm src/cli.rs && cargo fix\n\n# after: restore the file then fix\ngit checkout src/cli.rs\ncargo fix --allow-dirty","handlingStrategy":"validation","validationCode":"// Before fix, ensure each target's .rs source still exists.\nfn sources_exist(pkg: &cargo::core::Package) -> Result<(), String> {\n    for t in pkg.targets() {\n        if let Some(p) = t.src_path().path() {\n            if !p.is_file() { return Err(format!(\"missing {}\", p.display())); }\n        }\n    }\n    Ok(())\n}","typeGuard":"fn all_target_srcs_exist(pkg: &cargo::core::Package) -> bool {\n    pkg.targets().iter().all(|t|\n        t.src_path().path().map(|p| p.is_file()).unwrap_or(true))\n}","tryCatchPattern":"match FixArgs::from_args(argv) {\n    Err(e) if e.to_string().contains(\"could not find .rs file\") => {\n        eprintln!(\"a source .rs file is missing; restore it or run cargo clean\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Run `cargo fix` only against a clean, consistent tree.","Ensure generated sources exist before invoking fix."],"tags":["cargo","cargo-fix","proxy","source-file","rustc","internal"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}