[rust-compiler] Fix non-ASCII panic in ValidateNoSetStateInEffects (#37539)
## Summary `get_identifier_name_with_loc` reads an identifier's name out of the source when SSA has dropped it. `SourceLocation.index` is a Babel position and counts UTF-16 code units, but the fallback used it to slice a Rust `&str`, which indexes UTF-8 bytes: ```rust let slice = &code[start_idx..end_idx]; ``` These agree only while the source is ASCII. After any non-ASCII character, later offsets are short by the extra bytes, so the slice reads the wrong span, or panics when it lands inside a character: ``` panicked at crates/react_compiler_validation/src/validate_no_set_state_in_effects.rs:168:30: start byte index 637 is not a char boundary; it is inside 'う' (bytes 636..639 of string) ``` The panic aborts validation for the whole file, so every diagnostic in it is lost. `validate_no_derived_computations_in_effects.rs` already converts correctly in its own copy of this function. Both were added in #36173 and only one got the UTF-16 handling, so this ports that logic over. Found through Biome, which embeds these crates for its `useReactCompiler` rule. ## How did you test this change? Added `repro-setState-in-effect-non-ascii-source.ts`, which panics before this change and compiles cleanly after: ``` bash scripts/test-rust-port.sh ValidateNoSetStateInEffects \ packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/repro-setState-in-effect-non-ascii-source.ts ``` The non-ASCII comments in it are test input, not documentation; removing them realigns the offsets and the crash disappears. Everything `compiler_rust.yml` runs is green on macOS arm64, including `scripts/test-rust-port.sh` (1811 passed) and `yarn snap --rust` (1812 passed).
M
Masaharu Hori committed
78c2d377d79a7284339fc24b560dd503daf314cc
Parent: 4558a16
Committed by GitHub <noreply@github.com>
on 9/9/2026, 12:06:00 PM