{"record":{"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/context/config_value.rs#L187-L223","documentation":"While merging layered Cargo config values, a non-list/non-table value's type changed in an incompatible way (e.g. a string in one layer, a table in another, or a list where a scalar was expected). The merge explicitly forbids type switches except between scalars, so it bails with the key path, expected vs found descriptors, and their definitions.","triggerScenarios":"Two config layers (e.g. `~/.cargo/config.toml` and project `.cargo/config.toml`, or CLI `--config` overrides) define the same key with different TOML types; e.g. `build.jobs = 4` in one and `[build.jobs]` (table) in another.","commonSituations":"Merging global and project configs after a refactor; `--config` flag passing a JSON-encoded value whose type differs from the file value; typos that turn a scalar into a section header.","solutions":["Read `expected.definition()` and `found.definition()` from the message to locate both files/lines.","Make the value types consistent across all config layers (both scalars, both tables, or both lists).","Remove the conflicting override from the lower-priority layer.","Use `cargo config get <key>` to inspect the merged value and its sources."],"exampleFix":"// before\n# ~/.cargo/config.toml\n[build]\njobs = 4\n# ./.cargo/config.toml (typo created a table)\n[build.jobs]\ndefault = true\n\n// after\n[build]\njobs = \"default\"","handlingStrategy":"validation","validationCode":"fn types_compatible(a: &ConfigValue, b: &ConfigValue) -> bool {\n    matches!((a, b), (CV::List(_,_), CV::List(_,_)) | (CV::Table(_,_), CV::Table(_,_))) || (!matches!(a, CV::List(_,_) | CV::Table(_,_)) && !matches!(b, CV::List(_,_) | CV::Table(_,_)))\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Lint `.cargo/config.toml` with a schema-aware TOML LSP.","Avoid `--config` overrides that change a key's TOML type.","Run `cargo config get` to verify merged values after edits."],"tags":["cargo","config","merge","toml","type-mismatch"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}