{"id":"cc9e26621beeef43","repo":"rust-lang/cargo","slug":"cannot-mix-proc-macro-crate-type-with-others","errorCode":null,"errorMessage":"cannot mix `proc-macro` crate type with others","messagePattern":"cannot mix `proc-macro` crate type with others","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/workspace/parser/targets.rs","lineNumber":258,"sourceCode":"    // A plugin requires exporting plugin_registrar so a crate cannot be\n    // both at once.\n    let crate_types = match (lib.crate_types(), lib.proc_macro()) {\n        (Some(kinds), _)\n            if kinds.contains(&CrateType::Dylib.as_str().to_owned())\n                && kinds.contains(&CrateType::Cdylib.as_str().to_owned()) =>\n        {\n            anyhow::bail!(format!(\n                \"library `{}` cannot set the crate type of both `dylib` and `cdylib`\",\n                name_or_panic(lib)\n            ));\n        }\n        (Some(kinds), _) if kinds.contains(&\"proc-macro\".to_string()) => {\n            warnings.push(format!(\n                \"library `{}` should only specify `proc-macro = true` instead of setting `crate-type`\",\n                name_or_panic(lib)\n            ));\n            if kinds.len() > 1 {\n                anyhow::bail!(\"cannot mix `proc-macro` crate type with others\");\n            }\n            vec![CrateType::ProcMacro]\n        }\n        (Some(kinds), _) => kinds.iter().map(|s| s.into()).collect(),\n        (None, Some(true)) => vec![CrateType::ProcMacro],\n        (None, _) => vec![CrateType::Lib],\n    };\n\n    let mut target = Target::lib_target(name_or_panic(lib), crate_types, path, edition);\n    configure(lib, &mut target, TARGET_KIND_HUMAN_LIB, warnings)?;\n    target.set_name_inferred(original_lib.map_or(true, |v| v.name.is_none()));\n    Ok(Some(target))\n}\n\n#[tracing::instrument(skip_all)]\npub fn normalize_bins(\n    toml_bins: Option<&Vec<TomlBinTarget>>,\n    package_root: &Path,","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/parser/targets.rs#L240-L276","documentation":"Error \"cannot mix `proc-macro` crate type with others\" thrown in rust-lang/cargo.","triggerScenarios":"Thrown at src/workspace/parser/targets.rs:258 when the library encounters an invalid state.","commonSituations":"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.","solutions":["Use only `proc-macro` in `crate-type` for a procedural macro library.","Move other crate types into a separate non-proc-macro crate."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}