Filters candidates by checking self compatibility
GCC Rust filters out method candidates with incompatible 'self' types, preventing incorrect matches.
GCC Rust now filters out method selection candidates when the ‘self’ type is incompatible. This prevents erroneous matches, such as those involving double references (e.g., &&A) when only a single reference is expected or compatible, as seen with PartialOrd for &i8. This fix ensures that method resolution considers the precise nature of the receiver type.
In Details
The method selection logic in gccrs now includes a check for 'self' type compatibility. This prevents the MethodResolver from incorrectly selecting candidates when dealing with complex reference types (e.g., &&A) against simpler expected types (e.g., &A). This is particularly relevant for trait implementations where receiver types can vary.
- method selection
- The process of determining which method implementation should be called based on the type of the receiver (the object on which the method is called) and the method name.
- self
- In Rust,
selfrefers to the instance of the type on which a method is called. It can be passed by value, immutable reference (&self), or mutable reference (&mut self). - PartialOrd
- A Rust trait used for partial ordering comparisons. Types implementing
PartialOrdcan be compared using operators like<,>,<=, and>=. - reference
- A pointer to a value that does not own the data. In Rust, references can be immutable (
&T) or mutable (&mut T).