{"record":{"id":"b4ae23e7894717c2","repo":"slint-ui/slint","slug":"we-just-added-spaces","errorCode":null,"errorMessage":"We just added spaces","messagePattern":"We just added spaces","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/compiler/lexer.rs","lineNumber":504,"sourceCode":"    for c in &mut bytes[..start] {\n        if *c != b'\\n' {\n            *c = b' '\n        }\n    }\n\n    if start > 0 {\n        bytes[start - 1] = 2;\n    }\n    if end < bytes.len() {\n        bytes[end] = 3;\n\n        for c in &mut bytes[end + 1..] {\n            if *c != b'\\n' {\n                *c = b' '\n            }\n        }\n    }\n    Some(String::from_utf8(bytes).expect(\"We just added spaces\"))\n}\n\n#[test]\nfn test_extract_rust_macro() {\n    assert_eq!(extract_rust_macro(\"\\nslint{!{}}\".into()), None);\n    assert_eq!(\n        extract_rust_macro(\n            \"abc\\n€\\nslint !  {x \\\" \\\\\\\" }🦀\\\" { () {}\\n {} }xx =}-  ;}\\n xxx \\n yyy {}\\n\".into(),\n        ),\n        Some(\n            \"   \\n   \\n         \\u{2}x \\\" \\\\\\\" }🦀\\\" { () {}\\n {} }xx =\\u{3}     \\n     \\n       \\n\".into(),\n        )\n    );\n\n    assert_eq!(\n        extract_rust_macro(\"xx\\nabcd::slint!{abc{}efg\".into()),\n        Some(\"  \\n            \\u{2}abc{}efg\".into())\n    );","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/internal/compiler/lexer.rs#L486-L522","documentation":"`extract_rust_macro` masks everything outside the `slint!{...}` macro with spaces, then converts the bytes back to a String. Since the function only ever replaces ASCII bytes with spaces in valid UTF-8 input, `from_utf8` cannot fail — the panic guards that invariant.","triggerScenarios":"Only if the masking code corrupted multi-byte UTF-8 sequences (an off-by-one in the `end` index) would `String::from_utf8` fail. In practice unreachable for correct input.","commonSituations":"A developer modifies the byte-masking loop (e.g. the newline-preserving logic) and introduces an off-by-one that splits a multi-byte character; then the slint! macro proc-macro panics while parsing a Rust file.","solutions":["Verify your change to the masking logic preserves UTF-8 boundaries (only whole characters overwritten)","Confirm the input path to the proc-macro is valid UTF-8 Rust source","Operate on char boundaries instead of raw byte indices when masking"],"exampleFix":"// before\nSome(String::from_utf8(bytes).expect(\"We just added spaces\"))\n// after\nSome(String::from_utf8(bytes).unwrap_or_else(|e| {\n    panic!(\"extract_rust_macro produced invalid UTF-8 at byte {}: masking logic bug\", e.valid_up_to())\n}))","handlingStrategy":"validation","validationCode":"assert!(src.is_char_boundary(end + 1), \"mask index must fall on a char boundary\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When editing byte-masking loops, only overwrite with same-length ASCII on valid UTF-8","Add a unit test with multi-byte characters adjacent to macro boundaries"],"tags":["rust","proc-macro","panic","utf-8"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}