{"record":{"id":"3fab87da73c41c26","repo":"rust-lang/rust","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":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/rust-analyzer/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/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rust-analyzer/crates/project-model/src/toolchain_info/target_tuple.rs#L85-L121","documentation":"Returned by the target_tuple parser when the Cargo build.target config value is neither a TOML string nor an array (or an array element is not a string). rust-analyzer reads build.target to learn the set of target triples Cargo will build for; anything else is rejected.","triggerScenarios":"Parsed from the Cargo config (config.toml or .cargo/config.toml) build.target key when its value is a number, boolean, table, or an array containing non-strings. The parse_err is also attached via .context() when an array element fails as_str().","commonSituations":"A typo in config.toml writing build.target = 42 or build.target = true; a malformed array like build.target = [\"x86_64\", 64]; inheriting a config from a template that used a different schema; Cargo config from a future Cargo version that added a new shape.","solutions":["Open .cargo/config.toml (and ~/.cargo/config.toml, and the global config) and set build.target to a string or array of strings.","Validate the file with a TOML linter.","If you meant a single target, use build.target = \"<triple>\"; for several, build.target = [\"<triple1>\", \"<triple2>\"]."],"exampleFix":"# before (in .cargo/config.toml)\n[build]\ntarget = 42\n\n# after\n[build]\ntarget = [\"x86_64-unknown-linux-gnu\", \"wasm32-unknown-unknown\"]","handlingStrategy":"type-guard","validationCode":"// Lint the cargo config before rust-analyzer loads the workspace:\nfn valid_build_target(cfg: &toml::Value) -> bool {\n    match cfg.get(\"build\").and_then(|b| b.get(\"target\")) {\n        None => true,\n        Some(toml::Value::String(_)) => true,\n        Some(toml::Value::Array(a)) => a.iter().all(|v| matches!(v, toml::Value::String(_))),\n        _ => false,\n    }\n}","typeGuard":"// Type-guard for the parsed build.target value:\nfn build_target_is_valid(t: &toml::de::DeValue) -> bool {\n    match t.as_ref() {\n        toml::de::DeValue::String(_) => true,\n        toml::de::DeValue::Array(arr) => arr.iter().all(|v| v.as_ref().as_str().is_some()),\n        _ => false,\n    }\n}","tryCatchPattern":"match load_target_tuple(&target) {\n    Ok(t) => Ok(t),\n    Err(e) if e.to_string().contains(\"build.target\") => {\n        eprintln!(\"fix .cargo/config.toml: build.target must be a string or array of strings\");\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Always set build.target as a string or array of strings in config.toml.","Lint .cargo/config.toml with a TOML schema checker in CI.","Inherit configs carefully from templates; verify the schema after copying."],"tags":["rust-analyzer","cargo-config","toml","target-triple","project-model"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}