gccrs: Fix projection normalization logic
Corrects projection normalization in gccrs to handle non-trait position projections resolving to generics, fixing Rust-GCC/gccrs#4804.
This commit refactors the projection normalization logic in gccrs to correctly handle cases where non-trait position projections might resolve to generics. Previously, this could lead to incorrect base types being used for projections. The fix is verified with a new test case, issue-4804.rs.
In Details
The normalize_projection function in rust-type-util.cc previously had a flaw where, depending on the order of operations, projections in non-trait positions could resolve to generics. This allowed the compiler to attempt to derive the underlying type and use that as the basis for the projection. This patch adds a check to prevent this erroneous path, ensuring correct type normalization for Rust generics within gccrs.
- projection
- In Rust's trait system, a projection is a way to refer to an associated type of a trait. For example,
Iterator::Itemprojects theItemtype from theIteratortrait. - trait
- A Rust concept defining a set of methods that a type must implement. Traits enable shared behavior across different types.
- generics
- A programming feature allowing code to operate on values of unspecified types. This enables writing reusable code that can work with various types without duplication.
- associated type
- A type specified within a trait definition that implementers must provide. For instance, the
Iteratortrait has anItemassociated type representing the type of elements the iterator yields.