gccrs: typecheck: Add ADT to ADT unsize coercion support
gccrs typechecker now supports ADT-to-ADT unsized coercions.
The gccrs typechecker has been updated to support unsized coercions between Algebraic Data Types (ADTs). This change refactors the existing coerce_unsized function into smaller, more manageable helpers for improved readability and maintainability. It lays the groundwork for more complex type coercions involving unsized ADTs.
In Details
Basic support for ADT-to-ADT unsized coercions has been added to gccrs' typechecker. The commit refactors TypeCoercionRules::coerce_unsized into several helper functions, including unwrap_ptrs_and_refs, coerce_unsized_array_to_slice, coerce_unsized_dyn, and coerce_unsized_adt. This change also registers the COERCE_UNSIZED lang item. The function HIRCompileBase::resolve_unsized_adt_adjustment is introduced to help with adjustment resolution for unsized ADTs.
- ADT
- Algebraic Data Type. A composite type formed by combining other types. In Rust, this typically refers to structs and enums.
- unsized coercion
- A conversion in Rust that allows a sized type to be coerced into a DST behind a pointer. For example,
&[T; N]can be coerced into&[T]. - typechecker
- A component of the compiler responsible for verifying that the code adheres to the language's type system rules, ensuring type safety.
- lang item
- A specific, built-in feature or capability of the Rust language that the compiler needs to implement, such as
Sized,Copy, orcoerce_unsized.