{"record":{"id":"d92802afa51a5484","repo":"rust-lang/cargo","slug":"target-names-cannot-be-empty","errorCode":null,"errorMessage":"{} target names cannot be empty","messagePattern":"(.+?) target names cannot be empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":1180,"sourceCode":"        anyhow::bail!(\n            \"the binary target name `{name}` is forbidden, \\\n                 it conflicts with cargo's build directory names\",\n        )\n    }\n\n    Ok(())\n}\n\nfn validate_target_name(\n    target: &TomlTarget,\n    target_kind_human: &str,\n    target_kind: &str,\n    warnings: &mut Vec<String>,\n) -> CargoResult<()> {\n    match target.name {\n        Some(ref name) => {\n            if name.trim().is_empty() {\n                anyhow::bail!(\"{} target names cannot be empty\", target_kind_human)\n            }\n            if cfg!(windows) && restricted_names::is_windows_reserved(name) {\n                warnings.push(format!(\n                    \"{} target `{}` is a reserved Windows filename, \\\n                        this target will not work on Windows platforms\",\n                    target_kind_human, name\n                ));\n            }\n        }\n        None => anyhow::bail!(\n            \"{} target {}.name is required\",\n            target_kind_human,\n            target_kind\n        ),\n    }\n\n    Ok(())\n}","sourceCodeStart":1162,"sourceCodeEnd":1198,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/workspace/parser/targets.rs#L1162-L1198","documentation":"When a target's `name` field is present, it must not be empty or whitespace-only. `validate_target_name` trims the name and bails at targets.rs:1184 if `name.trim().is_empty()`. An empty name cannot map to a file or artifact.","triggerScenarios":"`[[bin]] name = \"\"` or `name = \"   \"`. The `Some(ref name)` arm with the trimmed-empty check fires.","commonSituations":"Placeholder names from code generation. YAML/TOML merge tools that collapse values to empty. Accidentally clearing a name during a refactor.","solutions":["Provide a non-empty, non-whitespace `name`.","Remove the `name` field only if the target is auto-inferred (not applicable to explicitly listed `[[bin]]` etc.).","Add a pre-commit manifest validator that rejects empty names."],"exampleFix":"# before\n[[bin]]\nname = \"\"\npath = \"src/main.rs\"\n\n# after\n[[bin]]\nname = \"myapp\"\npath = \"src/main.rs\"","handlingStrategy":"validation","validationCode":"fn name_non_empty(name: &str) -> bool {\n    !name.trim().is_empty()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject empty/whitespace target names in manifest linting.","Validate generated manifests before writing.","Treat an empty `name` as a scaffolding bug."],"tags":["cargo","config","targets","validation","manifest"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}