{"record":{"id":"260d3b627452fd48","repo":"gleam-lang/gleam","slug":"failed-to-split-a-slice","errorCode":null,"errorMessage":"Failed to split 'a' slice","messagePattern":"Failed to split 'a' slice","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler-core/src/error.rs","lineNumber":830,"sourceCode":"// https://github.com/rust-lang/rust/blob/03994e498df79aa1f97f7bbcfd52d57c8e865049/compiler/rustc_span/src/edit_distance.rs\npub fn edit_distance(a: &str, b: &str, limit: usize) -> Option<usize> {\n    let mut a = &a.chars().collect::<Vec<_>>()[..];\n    let mut b = &b.chars().collect::<Vec<_>>()[..];\n\n    if a.len() < b.len() {\n        std::mem::swap(&mut a, &mut b);\n    }\n\n    let min_dist = a.len() - b.len();\n    // If we know the limit will be exceeded, we can return early.\n    if min_dist > limit {\n        return None;\n    }\n\n    // Strip common prefix.\n    while !b.is_empty() && !a.is_empty() {\n        let (b_first, b_rest) = b.split_last().expect(\"Failed to split 'b' slice\");\n        let (a_first, a_rest) = a.split_last().expect(\"Failed to split 'a' slice\");\n\n        if b_first == a_first {\n            a = a_rest;\n            b = b_rest;\n        } else {\n            break;\n        }\n    }\n\n    // If either string is empty, the distance is the length of the other.\n    // We know that `b` is the shorter string, so we don't need to check `a`.\n    if b.is_empty() {\n        return Some(min_dist);\n    }\n\n    let mut prev_prev = vec![usize::MAX; b.len() + 1];\n    let mut prev = (0..=b.len()).collect::<Vec<_>>();\n    let mut current = vec![0; b.len() + 1];","sourceCodeStart":812,"sourceCodeEnd":848,"githubUrl":"https://github.com/gleam-lang/gleam/blob/49f8762da595eb3c8f576656a4200a142ca188c9/compiler-core/src/error.rs#L812-L848","documentation":"The mirror of error 103: `a.split_last().expect(\"Failed to split 'a' slice\")` inside the same `did_you_mean` loop in `compiler-core/src/error.rs`. The surrounding `while !b.is_empty() && !a.is_empty()` check makes the failure unreachable under correct logic, so this panic acts purely as an internal consistency assertion on slice `a`.","triggerScenarios":"`split_last` on an empty `a` despite the loop guard — only possible through an upstream logic bug (e.g. `a` recomputed to empty inside the loop body) or concurrent mutation of the slice between the emptiness check and the split call.","commonSituations":"Not encountered in normal use; would manifest as a Gleam compiler panic while computing a spelling suggestion for a misspelled import, label, or field name.","solutions":["Report a compiler bug with reproduction steps if triggered — this is an internal invariant violation","Update to the newest Gleam release before filing, in case the suggestion code was already patched","Harden the helper by returning `None` from `split_last` matches rather than panicking on empty slices"],"exampleFix":"// before\nlet (a_first, a_rest) = a.split_last().expect(\"Failed to split 'a' slice\");\n// after\nlet Some((a_first, a_rest)) = a.split_last() else { return None; };","handlingStrategy":"fallback","validationCode":"// defensive pre-condition for library contributors:\ndebug_assert!(!a.is_empty() && !b.is_empty(), \"slices must be non-empty before split_last\");","typeGuard":null,"tryCatchPattern":"// ICE — no user catch; guard the compiler process invocation:\nmatch std::process::Command::new(\"gleam\").arg(\"check\").status() {\n    Ok(s) if s.success() => {},\n    _ => eprintln!(\"gleam check failed or panicked\"),\n}","preventionTips":["Report occurrences with a minimal reproduction to the Gleam issue tracker","Upgrade the compiler before filing","In library code, replace expect with graceful early-return (return None)"],"tags":["rust","compiler","levenshtein","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"49f8762da595eb3c8f576656a4200a142ca188c9","analyzedAt":"2026-09-14T11:14:59.388Z","contentChangedAt":"2026-09-14T11:14:59.388Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}