{"id":"6353477f8f911ea3","repo":"rust-lang/cargo","slug":"failed-to-merge-config-value-from-into","errorCode":null,"errorMessage":"failed to merge config value from `{}` into `{}`: expected {}, but found {}","messagePattern":"failed to merge config value from `(.+?)` into `(.+?)`: expected (.+?), but found (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/config_value.rs","lineNumber":205,"sourceCode":"                                     {} and {}\",\n                                    key,\n                                    entry.definition(),\n                                    new_def,\n                                )\n                            })?;\n                        }\n                        Entry::Vacant(entry) => {\n                            entry.insert(value);\n                        }\n                    };\n                }\n            }\n            // Allow switching types except for tables or arrays.\n            (expected @ &mut CV::List(_, _), found)\n            | (expected @ &mut CV::Table(_, _), found)\n            | (expected, found @ CV::List(_, _))\n            | (expected, found @ CV::Table(_, _)) => {\n                return Err(anyhow!(\n                    \"failed to merge config value from `{}` into `{}`: expected {}, but found {}\",\n                    found.definition(),\n                    expected.definition(),\n                    expected.desc(),\n                    found.desc()\n                ));\n            }\n            (old, mut new) => {\n                if force || is_higher_priority {\n                    mem::swap(old, &mut new);\n                }\n            }\n        }\n\n        Ok(())\n    }\n\n    pub fn i64(&self, key: &str) -> CargoResult<(i64, &Definition)> {","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/config_value.rs#L187-L223","documentation":"When Cargo merges layered config (CLI > env > project > home) it calls ConfigValue::merge (config_value.rs:184-212). Scalars can override each other, but merging across a structural boundary is forbidden: you cannot merge a List/Table with a scalar or with a different structure. On such a type clash it returns 'failed to merge config value from `<source def>` into `<dest def>`: expected <X>, but found <Y>'. The definition locations point at the two conflicting config sources.","triggerScenarios":"Two config sources set the same key to incompatible types, e.g. `[build] jobs = 4` (integer) in config.toml but `CARGO_BUILD_JOCS=a,b` style list in env, or a table where a string is expected. Any merge where one side is CV::List/CV::Table and the other is not.","commonSituations":"Setting a config key as a string in config.toml but as an array in a higher-priority source; env var that should be a list vs. config that is a scalar; conflicting config.toml between home and project.","solutions":["Read the message: it names the source (`from`) and destination (`into`) definitions and the expected/found types.","Make both sources use the same type for that key (e.g. both string, or both array).","Check `$CARGO_HOME/config.toml`, project `.cargo/config.toml`, and relevant `CARGO_*` env vars for the offending key.","If you need to override, remove the lower-priority value rather than change its type."],"exampleFix":"# before (config.toml)\n[build]\nrustflags = [\"-A\", \"warnings\"]\n# env\nexport CARGO_BUILD_RUSTFLAGS=\"-D warnings\"  # scalar vs array -> clash\n# after\nexport CARGO_BUILD_RUSTFLAGS=\"-A warnings\"   # both array-encoded, or unset one","handlingStrategy":"validation","validationCode":"# Validate config layering doesn't change a key's type.\n# Use `cargo config get` (or inspect) to see the merged value and its source:\ncargo config get build.rustflags  # confirms resolved type & origin","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a single canonical source for each config key; avoid setting the same key in home + project + env.","Use arrays consistently for list-type keys across all sources.","Run `cargo config get` to inspect merged config before debugging mysterious type errors."],"tags":["config","merge","config-value","type-mismatch"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}