Stops method selection on generic params
GCC Rust's method resolution now halts when encountering generic parameters to avoid incorrect matches.
GCC Rust’s method selection process has been updated to stop when it encounters generic parameters. This prevents the type unification machinery from incorrectly matching types by injecting inferred variables. Instead, generics are expected to match directly via their associated type bound predicates, which are checked separately. This ensures more accurate method resolution in the presence of generics.
In Details
The MethodResolver::select in gccrs now includes logic to stop processing when it encounters ParamTypes (representing generic parameters). This prevents the types_compatible machinery from incorrectly unifying types by inferring variables. The intended behavior is for generics to resolve through their associated type bounds, which are handled elsewhere. This change is in typecheck/rust-hir-dot-operator.cc.
- method selection
- The process of determining which method implementation to call based on the type of the receiver and the method name. This involves resolving trait methods and handling potential ambiguities.
- generic params
- Placeholders used in generic types, functions, or traits that can be substituted with concrete types. For example, in
impl<T> MyTrait for Vec<T>,Tis a generic parameter. - type unification
- The process of determining if two types are compatible or equivalent, often by finding a common type or by substituting type variables. This is a core part of type inference and checking.
- associated type bound
- A constraint within a trait that specifies a type associated with a generic parameter. For example,
trait Iterator { type Item; }.