rust-lang/cargo · error

previously normalized

Error message

previously normalized

What it means

Invariant immediately after 309: `package.normalized_build().expect("previously normalized")`. The vendoring pipeline normalizes the `[package]` table earlier, so `normalized_build()` (which returns `Result`) should not error here. The expect guards the assumption that build-script normalization already happened.

Source

Thrown at src/ops/cargo_vendor.rs:543

        gctx,
        &mut warnings,
        &mut errors,
    )?;
    let new_pkg = Package::new(manifest, me.manifest_path());
    Ok(new_pkg)
}

fn prepare_toml_for_vendor(
    mut me: cargo_util_schemas::manifest::TomlManifest,
    packaged_files: &[PathBuf],
    gctx: &GlobalContext,
) -> CargoResult<cargo_util_schemas::manifest::TomlManifest> {
    let package = me
        .package
        .as_mut()
        .expect("venedored manifests must have packages");
    // Validates if build script file is included in package. If not, warn and ignore.
    if let Some(custom_build_scripts) = package.normalized_build().expect("previously normalized") {
        let mut included_scripts = Vec::new();
        for script in custom_build_scripts {
            let path = paths::normalize_path(Path::new(script));
            let included = packaged_files.contains(&path);
            if included {
                let path = path
                    .into_os_string()
                    .into_string()
                    .map_err(|_err| anyhow::format_err!("non-UTF8 `package.build`"))?;
                let path = crate::workspace::parser::normalize_path_string_sep(path);
                included_scripts.push(path);
            } else {
                gctx.shell().warn(format!(
                    "ignoring `package.build` entry `{}` as it is not included in the published package",
                    path.display()
                ))?;
            }
        }

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Inspect the `[package].build` key of the crate being vendored (`cargo vendor -v`) for an unusual shape.
  2. Report a cargo bug with the offending manifest attached.
  3. As a workaround, simplify `build = { path = "..." }` to `build = "..."` (or vice-versa) in the source manifest if you control it.

Example fix

// before
if let Some(custom_build_scripts) = package.normalized_build().expect("previously normalized") {

// after
if let Some(custom_build_scripts) = package.normalized_build()
    .with_context(|| "failed to re-normalize [package].build during vendoring")? {
Defensive patterns

Strategy: validation

Validate before calling

// Validate [package].build shape before vendoring.
match &pkg.build {
    Some(toml_edit::Item::Value(_)) | Some(toml_edit::Item::Table(_)) | None => {},
    other => return Err(anyhow!("[package].build has unexpected shape: {:?}", other)),
}

Prevention

When it happens

Trigger: Fires only if `normalized_build()` fails on a `[package]` table that was supposed to have been normalized upstream — e.g. a `build = "..."` key shaped in a way the normalizer accepts but the re-normalizer rejects, or a manifest mutated between normalization and this call.

Common situations: Cargo bug in the vendor manifest-preparation pipeline; a `[package].build` value (string vs. table) inconsistent between the original and prepared manifest; regression after changes to `TomlPackage::normalized_build`. End users rarely hit this directly.

Related errors


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