gccrs: Fix ICE on enum tuple variants with rest patterns
Fixes an internal compiler error in gccrs when processing rest patterns in enum tuple variants.
This commit resolves an ICE (Internal Compiler Error) in gccrs that occurred when encountering rest patterns (using ..) in enum tuple variants. Previously, the pattern checking and binding visitors incorrectly assumed the field layout of structs, not enums. The fix involves reading enum variant fields through the payload union, aligning with how non-rest patterns are handled.
In Details
In gccrs, pattern matching on enum variants that use rest patterns (..) was causing an ICE. The CompilePatternCheckExpr and CompilePatternBindings visitors in rust-compile-pattern.cc were not equipped to handle the structure of enum variants with rest patterns, as they only understood struct field layouts. This patch modifies these visitors to correctly access enum variant fields via the payload union, similar to how non-rest patterns are processed, thus fixing the ICE and addressing Rust-GCC/gccrs#4978.
- ICE
- Internal Compiler Error. A condition where the compiler encounters an unrecoverable error during its execution, leading to a crash.
- rest pattern
- A pattern matching syntax (often
..) that allows a variable number of fields or elements to be ignored or captured in a single binding. - enum tuple variant
- A variant of an enumeration that holds its data as a tuple of unnamed fields.