{"record":{"id":"f09ae8e64de87448","repo":"rust-lang/cargo","slug":"target-name-is-required","errorCode":null,"errorMessage":"{} target {}.name is required","messagePattern":"(.+?) target (.+?)\\.name is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":1190,"sourceCode":"    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}\n\nfn validate_bin_proc_macro(\n    target: &TomlTarget,\n    edition: Edition,\n    warnings: &mut Vec<String>,\n    errors: &mut Vec<String>,\n) -> CargoResult<()> {\n    if target.proc_macro() == Some(true) {\n        let name = name_or_panic(target);\n        errors.push(format!(","sourceCodeStart":1172,"sourceCodeEnd":1208,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/workspace/parser/targets.rs#L1172-L1208","documentation":"For explicitly declared targets (`[[bin]]`, `[[test]]`, `[[bench]]`, `[[example]]`), the `name` field is mandatory — there is no inference for listed tables. `validate_target_name` hits the `None` arm at targets.rs:1190-1194 and bails. (Auto-inferred targets like the default `src/main.rs` bin bypass this path.)","triggerScenarios":"A `[[bin]]` (or `[[test]]`/`[[bench]]`/`[[example]]`) table with no `name` key. The `match target.name` falls through to `None`.","commonSituations":"Adding a `[[bin]]` table to set only `path` and forgetting `name`. Truncated copy-paste of a target block. Tutorials that omit the name field.","solutions":["Add an explicit `name = \"...\"` to the target table.","Alternatively, rely on file-based discovery (place the binary at `src/bin/foo.rs`) instead of a `[[bin]]` table."],"exampleFix":"# before\n[[bin]]\npath = \"src/server.rs\"\n\n# after\n[[bin]]\nname = \"server\"\npath = \"src/server.rs\"","handlingStrategy":"validation","validationCode":"fn explicit_targets_have_name(tables: &[Option<&str>]) -> bool {\n    tables.iter().all(|t| t.is_some())\n}\n// every [[bin]]/[[test]]/[[bench]]/[[example]] table must carry a `name`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set `name` on explicitly listed target tables.","Prefer file-based discovery (`src/bin/foo.rs`) when name inference is wanted.","Lint manifests for nameless target tables."],"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"}