rust-lang/cargo · error · anyhow::Error

cannot mix `proc-macro` crate type with others

Error message

cannot mix `proc-macro` crate type with others

What it means

Error "cannot mix `proc-macro` crate type with others" thrown in rust-lang/cargo.

Source

Thrown at src/workspace/parser/targets.rs:258

    // A plugin requires exporting plugin_registrar so a crate cannot be
    // both at once.
    let crate_types = match (lib.crate_types(), lib.proc_macro()) {
        (Some(kinds), _)
            if kinds.contains(&CrateType::Dylib.as_str().to_owned())
                && kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>
        {
            anyhow::bail!(format!(
                "library `{}` cannot set the crate type of both `dylib` and `cdylib`",
                name_or_panic(lib)
            ));
        }
        (Some(kinds), _) if kinds.contains(&"proc-macro".to_string()) => {
            warnings.push(format!(
                "library `{}` should only specify `proc-macro = true` instead of setting `crate-type`",
                name_or_panic(lib)
            ));
            if kinds.len() > 1 {
                anyhow::bail!("cannot mix `proc-macro` crate type with others");
            }
            vec![CrateType::ProcMacro]
        }
        (Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),
        (None, Some(true)) => vec![CrateType::ProcMacro],
        (None, _) => vec![CrateType::Lib],
    };

    let mut target = Target::lib_target(name_or_panic(lib), crate_types, path, edition);
    configure(lib, &mut target, TARGET_KIND_HUMAN_LIB, warnings)?;
    target.set_name_inferred(original_lib.map_or(true, |v| v.name.is_none()));
    Ok(Some(target))
}

#[tracing::instrument(skip_all)]
pub fn normalize_bins(
    toml_bins: Option<&Vec<TomlBinTarget>>,
    package_root: &Path,

View on GitHub (pinned to 0e07a15537)

Solutions

  1. Use only `proc-macro` in `crate-type` for a procedural macro library.
  2. Move other crate types into a separate non-proc-macro crate.

When it happens

Trigger: Thrown at src/workspace/parser/targets.rs:258 when the library encounters an invalid state.

Common situations: Occurs when `crate-type` mixes `proc-macro` with other crate types (e.g. `lib`, `dylib`). A proc-macro crate must declare only `proc-macro` as its crate type.


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