rust-lang/cargo · warning

normalized have a path

Error message

normalized have a path

What it means

This panic is in the non-kebab-case-bin-names lint diagnostic generator. When a binary target's name is not kebab-case and the bin has been normalized (its name was inferred or set via the [package] name rather than an explicit [[bin]] table), the code reaches the else branch at line 216 and expects bin.path to be Some. The invariant is that normalization always assigns a path.

Source

Thrown at src/diagnostics/rules/non_kebab_case_bins.rs:220

                    ),
                );
            } else {
                report.push(
                    Level::HELP
                        .secondary_title(help_package_name)
                        .element(Origin::path(manifest_path)),
                );
                report.push(
                    Level::HELP
                        .secondary_title(help_bin_table)
                        .element(Origin::path(manifest_path)),
                );
            }
        } else {
            let path = bin
                .path
                .as_ref()
                .expect("normalized have a path")
                .0
                .as_path();
            let display_path = path.as_os_str().to_string_lossy();
            let end = display_path.len() - if display_path.ends_with(".rs") { 3 } else { 0 };
            let start = path
                .parent()
                .map(|p| {
                    let p = p.as_os_str().to_string_lossy();
                    // Account for trailing slash that was removed
                    p.len() + if p.is_empty() { 0 } else { 1 }
                })
                .unwrap_or(0);
            let help = Level::HELP
                .secondary_title(format!(
                    "to change the binary name to `{kebab_case}`, convert the file stem"
                ))
                .element(Snippet::source(display_path).patch(Patch::new(start..end, kebab_case)));
            report.push(help);

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Add an explicit path to the [[bin]] entry: [[bin]] name = "my_binary" path = "src/main.rs".
  2. Rename the binary target to kebab-case to avoid the lint entirely.
  3. Ensure the binary source file follows cargo's default path conventions (src/bin/<name>.rs).

Example fix

# before
[[bin]]
name = "MyBinary"
# after (add explicit path)
[[bin]]
name = "MyBinary"
path = "src/bin/my_binary.rs"
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on the lint, ensure bin targets have explicit paths
for bin in manifest.bin_targets() {
    if bin.path.is_none() {
        eprintln!("warning: bin `{}` has no explicit path; add [[bin]] path = \"...\"", bin.name);
    }
}

Prevention

When it happens

Trigger: Having a Cargo.toml where a binary target triggers the non-kebab-case lint but its path field is None after normalization — which could happen if the manifest has an inconsistent [[bin]] entry with a name but no path and no src/main.rs convention.

Common situations: A manifest with a [[bin]] target that has a non-kebab-case name, no explicit path, and doesn't follow the src/bin/<name>.rs or src/main.rs convention; a workspace with unusual target inheritance; a cargo version where the normalization logic has a gap.

Related errors


AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06). Data as JSON: /data/errors/993d35f9c01a3d2e.json. Report an issue: GitHub.