{"id":"6ad2ab7131cc15f7","repo":"rust-lang/cargo","slug":"no-target-desc-target-named-target-name-un","errorCode":null,"errorMessage":"no {target_desc} target {named} `{target_name}`{unmatched_packages}{suggestion}","messagePattern":"no (.+?) target (.+?) `(.+?)`(.+?)(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/unit_generator.rs","lineNumber":317,"sourceCode":"                msg,\n                \"no {target_desc} target {named} `{target_name}`{unmatched_packages}{suggestion}\",\n            )?;\n            if !targets_elsewhere.is_empty() {\n                append_targets_elsewhere(&mut msg)?;\n            } else if suggestion.is_empty() && !targets.is_empty() {\n                write!(msg, \"\\nhelp: available {} targets:\", target_desc)?;\n                for (target_name, pkgs) in targets {\n                    if pkgs.len() == 1 {\n                        write!(msg, \"\\n    {target_name}\")?;\n                    } else {\n                        for (pkg, _) in pkgs {\n                            let pkg_name = pkg.name();\n                            write!(msg, \"\\n    {target_name} in package {pkg_name}\")?;\n                        }\n                    }\n                }\n            }\n            anyhow::bail!(msg);\n        }\n        Ok(proposals)\n    }\n\n    fn get_targets_from_other_packages(\n        &self,\n        filter_fn: impl Fn(&Target) -> bool,\n    ) -> CargoResult<Vec<(&str, Vec<&str>)>> {\n        let packages = Packages::All(Vec::new()).get_packages(self.ws)?;\n        let targets = packages\n            .into_iter()\n            .filter_map(|pkg| {\n                let mut targets: Vec<_> = pkg\n                    .manifest()\n                    .targets()\n                    .iter()\n                    .filter_map(|target| filter_fn(target).then(|| target.name()))\n                    .collect();","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_compile/unit_generator.rs#L299-L335","documentation":"Thrown by find_named_targets (src/ops/cargo_compile/unit_generator.rs:232-319) when a named target filter (--bin NAME, --example NAME, --test NAME, --bench NAME, or a glob) matches no target in the selected packages. The message includes the target description, the name/pattern, where it was looked for, a did-you-mean suggestion, and (if targets exist elsewhere) a list of available targets in other packages.","triggerScenarios":"`cargo build --bin nonexistent`, `cargo test --test missing`, `--example ghost`, or a glob like `--bin 'x*'` that matches nothing. The proposals list is empty, so the error builder assembles target_desc + named + target_name + unmatched_packages + suggestion.","commonSituations":"Typo in the target name. Renaming a binary/test/example without updating docs or scripts. Pointing --bin at a target defined in a dependency rather than the local package. Case mismatches.","solutions":["Read the 'help: available ... targets' list in the error to copy the exact name.","Run `cargo build --bins`/`--help` or `cargo metadata` to enumerate real targets.","Check that the target is declared in the selected package (use -p to pick the right package).","If using a glob, verify the syntax and that at least one target matches."],"exampleFix":"# before\ncargo run --bin serves     # typo\n\n# after\ncargo run --bin server","handlingStrategy":"validation","validationCode":"// Confirm a named target exists in the selected package before building.\nfn target_exists(pkg: &cargo::core::Package, kind: fn(&Target)->bool, name: &str) -> bool {\n    pkg.targets().iter().any(|t| kind(t) && t.name() == name)\n}","typeGuard":"fn has_named_target(pkg: &cargo::core::Package, name: &str) -> bool {\n    pkg.targets().iter().any(|t| t.name() == name)\n}","tryCatchPattern":"if let Err(e) = generate_root_units {\n    if e.to_string().starts_with(\"no \") && e.to_string().contains(\"target\") {\n        eprintln!(\"unknown target; see the 'available targets' list in the error\");\n    }\n    return Err(e);\n}","preventionTips":["Source target names from the manifest / `cargo metadata` in scripts.","Use the did-you-mean suggestion printed by cargo to fix typos."],"tags":["cargo","target-selection","cli","did-you-mean","manifest"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}