{"id":"2909846d691483dd","repo":"rust-lang/cargo","slug":"len-1-above","errorCode":null,"errorMessage":"len() == 1 above","messagePattern":"len\\(\\) == 1 above","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/mod.rs","lineNumber":2441,"sourceCode":"    fn non_empty(d: Option<&toml_edit::RawString>) -> bool {\n        d.map_or(false, |p| !p.as_str().unwrap_or_default().trim().is_empty())\n    }\n    fn non_empty_decor(d: &toml_edit::Decor) -> bool {\n        non_empty(d.prefix()) || non_empty(d.suffix())\n    }\n    fn non_empty_key_decor(k: &toml_edit::Key) -> bool {\n        non_empty_decor(k.leaf_decor()) || non_empty_decor(k.dotted_decor())\n    }\n    let ok = {\n        let mut got_to_value = false;\n        let mut table = doc.as_table();\n        let mut is_root = true;\n        while table.is_dotted() || is_root {\n            is_root = false;\n            if table.len() != 1 {\n                break;\n            }\n            let (k, n) = table.iter().next().expect(\"len() == 1 above\");\n            match n {\n                Item::Table(nt) => {\n                    if table.key(k).map_or(false, non_empty_key_decor)\n                        || non_empty_decor(nt.decor())\n                    {\n                        bail!(\n                            \"--config argument `{arg}` \\\n                                includes non-whitespace decoration\"\n                        )\n                    }\n                    table = nt;\n                }\n                Item::Value(v) if v.is_inline_table() => {\n                    bail!(\n                        \"--config argument `{arg}` \\\n                        sets a value to an inline table, which is not accepted\"\n                    );\n                }","sourceCodeStart":2423,"sourceCodeEnd":2459,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/mod.rs#L2423-L2459","documentation":"This panic is in the --config argument validator (validate_config_arg_dotted_key). It walks a parsed TOML document's nested tables, checking that each level has exactly one key (a dotted-key chain). The while loop on line 2436 breaks if table.len() != 1 (line 2438), so reaching line 2441 guarantees exactly one entry. The .expect(\"len() == 1 above\") asserts table.iter().next() returns that single entry.","triggerScenarios":"Passing a --config argument to cargo whose TOML representation passes the len()==1 check but then yields no iterator element — theoretically impossible with a correct TOML parser, indicating either a toml_edit internal bug or a memory corruption issue.","commonSituations":"Passing complex or malformed --config arguments like cargo build --config 'foo.bar=\"baz\"' that stress the dotted-key parser; using a cargo build with a mismatched toml_edit version; corrupted argument passing on the command line.","solutions":["Simplify the --config argument to a straightforward dotted-key expression.","Use a config file instead of --config for complex overrides.","Update cargo — if this is a toml_edit version-compatibility bug, it will be fixed in a patch release."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate --config argument is a simple dotted-key expression before passing to cargo\nfn validate_config_arg(arg: &str) -> Result<(), String> {\n    let doc: toml_edit::DocumentMut = arg.parse()\n        .map_err(|e| format!(\"invalid TOML: {}\", e))?;\n    let mut table = doc.as_table();\n    let mut is_root = true;\n    while table.is_dotted() || is_root {\n        is_root = false;\n        if table.len() != 1 { break; }\n        if let Some((_, n)) = table.iter().next() {\n            match n {\n                toml_edit::Item::Table(t) => table = t,\n                toml_edit::Item::Value(v) if v.is_inline_table() => {\n                    return Err(\"inline tables not allowed in --config\".into());\n                }\n                _ => break,\n            }\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use simple dotted-key --config arguments: cargo build --config 'profile.release.lto=true'.","Prefer config files for complex settings.","Test --config arguments in isolation before adding to build scripts."],"tags":["rust","cargo","panic","invariant","config","toml","cli-args"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}