{"record":{"id":"9b873ca4ac913e1d","repo":"rust-lang/cargo","slug":"could-not-compile-due-to-error-count-previous-ta","errorCode":null,"errorMessage":"could not compile due to {error_count} previous target resolution error{plural}","messagePattern":"could not compile due to (.+?) previous target resolution error(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/mod.rs","lineNumber":637,"sourceCode":"    }\n\n    // Validate target src path for each root unit\n    let mut error_count: usize = 0;\n    for unit in &root_units {\n        if let Some(target_src_path) = unit.target.src_path().path() {\n            validate_target_path_as_source_file(\n                gctx,\n                target_src_path,\n                unit.target.name(),\n                unit.target.kind(),\n                unit.pkg.manifest_path(),\n                &mut error_count,\n            )?\n        }\n    }\n    if error_count > 0 {\n        let plural: &str = if error_count > 1 { \"s\" } else { \"\" };\n        anyhow::bail!(\n            \"could not compile due to {error_count} previous target resolution error{plural}\"\n        );\n    }\n\n    if honor_rust_version.unwrap_or(true) {\n        let rustc_version = target_data.rustc.version.clone().into();\n\n        let mut incompatible = Vec::new();\n        let mut local_incompatible = false;\n        for unit in unit_graph.keys() {\n            let Some(pkg_msrv) = unit.pkg.rust_version() else {\n                continue;\n            };\n\n            if pkg_msrv.is_compatible_with(&rustc_version) {\n                continue;\n            }\n","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/rust-lang/cargo/blob/495c385d0875c4ba51eb72ea0448a2d4c018b8d4/src/ops/cargo_compile/mod.rs#L619-L655","documentation":"Aggregate failure thrown after the per-unit validate_target_path_as_source_file loop accumulated one or more target-resolution errors. Each individual problem was already printed; this bail converts the nonzero error_count into a single terminating message with correct pluralization.","triggerScenarios":"One or more build targets referenced a source path that failed validation (non-existent file, wrong extension, path is a directory, etc.) during unit construction. The detailed per-target causes are emitted just before this summary.","commonSituations":"Manifest targets pointing at moved/renamed source files; `path = \"src/main.rs2\"` typos in [[bin]]/[[example]] tables; targets referencing generated files that have not been generated yet; switching editions/modes that change expected paths.","solutions":["Scroll up in the build output and read each individual target resolution error, fixing them one by one.","Correct the target `path` values in Cargo.toml to point at existing source files of the right type.","Regenerate any build-script-produced source files the targets depend on before building.","Remove stale [[bin]]/[[example]]/[[test]] entries for deleted sources."],"exampleFix":"# before (Cargo.toml)\n[[bin]]\nname = \"app\"\npath = \"src/main.rs2\"\n# after\n[[bin]]\nname = \"app\"\npath = \"src/main.rs\"","handlingStrategy":"validation","validationCode":"// Lint manifest target paths before building.\nuse std::path::Path;\nfn target_paths_exist(manifest: &Path) -> Result<(), String> {\n    // parse [[bin]]/[[example]]/[[test]]/[[bench]].path, check is_file\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate target `path` values in CI with `cargo check` before full builds.","Keep [[bin]]/[[example]] entries in sync with the source tree.","Regenerate build-script sources before building targets that consume them."],"tags":["cargo-compile","target-resolution","manifest","aggregate"],"backgroundTag":null,"analyzedSha":"495c385d0875c4ba51eb72ea0448a2d4c018b8d4","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}