{"record":{"id":"d882786703674e65","repo":"rust-lang/rust-analyzer","slug":"failed-to-parse-build-target-as-an-array-of-targ","errorCode":null,"errorMessage":"Failed to parse `build.target` as an array of target","messagePattern":"Failed to parse `build\\.target` as an array of target","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/project-model/src/toolchain_info/target_tuple.rs","lineNumber":103,"sourceCode":"            s.to_owned()\n        }\n    };\n\n    let parse_err = \"Failed to parse `build.target` as an array of target\";\n\n    match target.as_ref() {\n        toml::de::DeValue::String(s) => {\n            Ok(Some(vec![join_to_origin_if_json_path(s.as_ref(), target)]))\n        }\n        toml::de::DeValue::Array(arr) => arr\n            .iter()\n            .map(|v| {\n                let s = v.as_ref().as_str().context(parse_err)?;\n                Ok(join_to_origin_if_json_path(s, v))\n            })\n            .collect::<anyhow::Result<_>>()\n            .map(Option::Some),\n        _ => Err(anyhow::anyhow!(parse_err)),\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use paths::{AbsPathBuf, Utf8PathBuf};\n\n    use crate::{ManifestPath, Sysroot};\n\n    use super::*;\n\n    #[test]\n    fn cargo() {\n        let manifest_path = concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/Cargo.toml\");\n        let sysroot = Sysroot::empty();\n        let manifest_path =\n            ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();\n        let cfg = QueryConfig::Cargo(&sysroot, &manifest_path, &None);","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/project-model/src/toolchain_info/target_tuple.rs#L85-L121","documentation":"When reading `[build] target` from a Cargo config file, rust-analyzer's `parse_toml_cargo_config_build_target` accepts either a single string or an array of strings. If the TOML value is neither (e.g. an integer, boolean, or table), it returns the anyhow error `Failed to parse \\`build.target\\` as an array of target` via the shared `parse_err` message.","triggerScenarios":"A `.cargo/config.toml` or `.cargo/config` whose `build.target` is set to a non-string non-array value (e.g. `build.target = 3` or a nested table). Triggered when rust-analyzer loads the cargo config through `cargo_config_build_target`.","commonSituations":"Hand-editing config.toml and forgetting quotes around the target triple, tools writing structured values into the key, or copying JSON-style config where the value became an object.","solutions":["Set `build.target` to a string: `build.target = \"x86_64-unknown-linux-gnu\"`.","Or use an array of strings for multiple targets: `build.target = [\"a\", \"b\"]`.","Remove any non-string/non-array value from the key and re-run `cargo check` to confirm the config is valid.","Verify with `cargo config get build.target` (cargo-config) or by building, since cargo itself would also reject it."],"exampleFix":"# before (.cargo/config.toml)\n[build]\ntarget = 3\n\n# after (.cargo/config.toml)\n[build]\ntarget = \"x86_64-unknown-linux-gnu\"","handlingStrategy":"validation","validationCode":"// validate build.target shape before handing config to the consumer\nfn validate_build_target(cfg: &toml::Value) -> Result<(), String> {\n    match cfg.get(\"build\").and_then(|b| b.get(\"target\")) {\n        None | Some(toml::Value::String(_)) => Ok(()),\n        Some(toml::Value::Array(a)) if a.iter().all(|v| v.is_str()) => Ok(()),\n        Some(other) => Err(format!(\"build.target must be string or string array, got: {other}\")),\n    }\n}","typeGuard":"fn is_string_or_string_array(v: &toml::Value) -> bool {\n    v.is_str() || matches!(v, toml::Value::Array(a) if a.iter().all(toml::Value::is_str))\n}","tryCatchPattern":"match load_cargo_config(path) {\n    Err(e) if e.to_string().contains(\"Failed to parse `build.target`\") => {\n        eprintln!(\"fix [build] target in .cargo/config.toml: must be a string or array of strings\");\n        fallback_to_default_target()\n    }\n    other => other,\n}","preventionTips":["Always quote target triples in .cargo/config.toml.","Run `cargo check` after editing config.toml; cargo validates the same key.","Don't write non-scalar TOML values into build.target."],"tags":["config","toml","cargo","rust-analyzer"],"backgroundTag":"invalid-config-value","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}