slint-ui/slint · error
We just added spaces
Error message
We just added spaces
What it means
`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.
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
Example fix
// before
Some(String::from_utf8(bytes).expect("We just added spaces"))
// after
Some(String::from_utf8(bytes).unwrap_or_else(|e| {
panic!("extract_rust_macro produced invalid UTF-8 at byte {}: masking logic bug", e.valid_up_to())
})) Defensive patterns
Strategy: validation
Validate before calling
assert!(src.is_char_boundary(end + 1), "mask index must fall on a char boundary");
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- a setter belongs to a field
- an identifier
- binding was of the wrong type
- Cannot get property
- Cannot invoke callback
AI-assisted analysis of slint-ui/slint@bb937076de (2026-09-16).
Data as JSON: /api/errors/b4ae23e7894717c2.
Report an issue: GitHub.
Appendix: source
Thrown at internal/compiler/lexer.rs:504
for c in &mut bytes[..start] {
if *c != b'\n' {
*c = b' '
}
}
if start > 0 {
bytes[start - 1] = 2;
}
if end < bytes.len() {
bytes[end] = 3;
for c in &mut bytes[end + 1..] {
if *c != b'\n' {
*c = b' '
}
}
}
Some(String::from_utf8(bytes).expect("We just added spaces"))
}
#[test]
fn test_extract_rust_macro() {
assert_eq!(extract_rust_macro("\nslint{!{}}".into()), None);
assert_eq!(
extract_rust_macro(
"abc\n€\nslint ! {x \" \\\" }🦀\" { () {}\n {} }xx =}- ;}\n xxx \n yyy {}\n".into(),
),
Some(
" \n \n \u{2}x \" \\\" }🦀\" { () {}\n {} }xx =\u{3} \n \n \n".into(),
)
);
assert_eq!(
extract_rust_macro("xx\nabcd::slint!{abc{}efg".into()),
Some(" \n \u{2}abc{}efg".into())
);View on GitHub (pinned to bb937076de)