{"record":{"id":"f7ab5251e87c92a7","repo":"rust-lang/cargo","slug":"expected-table-for-configuration-key-but-found-in","errorCode":null,"errorMessage":"expected table for configuration key `{}`, but found {} in {}","messagePattern":"expected table for configuration key `(.+?)`, but found (.+?) in (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/mod.rs","lineNumber":871,"sourceCode":"        }\n        let mut parts = key.parts().enumerate();\n        let Some(mut val) = vals.get(parts.next().unwrap().1) else {\n            return Ok(None);\n        };\n        for (i, part) in parts {\n            match val {\n                CV::Table(map, _) => {\n                    val = match map.get(part) {\n                        Some(val) => val,\n                        None => return Ok(None),\n                    }\n                }\n                CV::Integer(_, def)\n                | CV::String(_, def)\n                | CV::List(_, def)\n                | CV::Boolean(_, def) => {\n                    let key_so_far = ConfigKey::from_parts(key.parts().take(i));\n                    bail!(\n                        \"expected table for configuration key `{}`, \\\n                         but found {} in {}\",\n                        key_so_far,\n                        val.desc(),\n                        def\n                    )\n                }\n            }\n        }\n        Ok(Some(val.clone()))\n    }\n\n    /// This is a helper for getting a CV from a file or env var.\n    pub(crate) fn get_cv_with_env(&self, key: &ConfigKey) -> CargoResult<Option<CV>> {\n        // Determine if value comes from env, cli, or file, and merge env if\n        // possible.\n        let cv = self.get_cv(key)?;\n        if key.is_root() {","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/context/mod.rs#L853-L889","documentation":"Cargo raises this hard error when resolving a configuration key whose intermediate value must be a table (e.g. `target.x.y` or `[foo]` sections) but the stored value is a scalar (integer, string, list, or boolean) instead. It is thrown in get_cv_helper while walking the config key path: a prefix of the requested key resolved to a non-table CV variant, so a nested key cannot exist beneath it. The message names the truncated key, the found value's description, and the file:line where that value was defined.","triggerScenarios":"Calling config lookups such as gctx.get(...) with a multi-part key (e.g. [\"target\", \"x86_64-unknown-linux-gnu\", \"linker\"]) where a prefix like `target` or `target.<triple>` was defined in a config file as a scalar — for example `target = \"x86_64-linux\"` instead of `target.\"x86_64-...\" = ...`, or a `[foo]` table accidentally overridden by a `foo = ...` scalar in a later config source.","commonSituations":"Typos or wrong nesting in ~/.cargo/config.toml or .cargo/config.toml (defining `target` as a string instead of a table); merging config sources where one file uses TOML key syntax `foo = value` and another uses `[foo]` tables, silently replacing the table with a scalar; environment-variable-based config where dotted names don't produce nested tables.","solutions":["Open the config file named in the error (the `in <file>` part) and change the scalar value into a TOML table, e.g. replace `target = \"...\"` with a `[target.\"<triple>\"]` section.","Check for duplicate definitions across all config sources (system, global ~/.cargo/config.toml, project .cargo/config.toml) and remove the one that defines the key as a scalar.","Verify quoting for keys that contain hyphens or dots, e.g. [target.'cfg(all(unix, target_arch = \"x86_64\"))']."],"exampleFix":"// before: .cargo/config.toml\ntarget = \"x86_64-unknown-linux-gnu\"\n\n// after: .cargo/config.toml\n[target.x86_64-unknown-linux-gnu]\nlinker = \"clang\"","handlingStrategy":"validation","validationCode":"// TOML / shell check before invoking cargo\ngrep -n '^\\s*target\\s*=' ~/.cargo/config.toml .cargo/config.toml 2>/dev/null || true\n# any hit means `target` (or the failing key prefix) is a scalar, not a table — fix it","typeGuard":"fn is_table(v: &toml::Value) -> bool { matches!(v, toml::Value::Table(_)) }","tryCatchPattern":"match gctx.get::<String>(&[\"target\", triple, \"linker\"]) {\n    Err(e) if e.to_string().contains(\"expected table for configuration key\") => {\n        // fall back to default / repair config\n    }\n    other => other?,\n}","preventionTips":["Never define section names (`target`, `registry`, `source`) as scalar keys; always use table syntax.","Keep one canonical config file per scope to avoid cross-source key collisions.","Quote complex key expressions (cfg(...) strings) correctly inside table headers."],"tags":["config","toml","type-mismatch","cargo"],"backgroundTag":"config-type-mismatch","analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-09-22T13:55:30.201Z","contentChangedAt":"2026-09-22T13:55:30.201Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}