SUNDAY, SEPTEMBER 6, 2026
gccrs
gccrs: Handle generic trait arguments in paths.
Correctly substitutes generic arguments for traits used within paths.
This commit improves gccrs’s ability to handle generic arguments when traits appear in paths, resolving Rust-GCC/gccrs#4853. The SubstMapper class is updated to correctly perform substitutions on dynamic objects (dyn Trait), ensuring that trait implementations with generic parameters are properly resolved.
In Details
The SubstMapper::valid_type and SubstMapper::visit methods in rust-substitution-mapper.cc were enhanced to correctly handle substitutions involving trait objects with generic type parameters. This addresses a gap in the substitution logic where dynamic trait objects (dyn Trait) with generics were not being processed correctly, potentially leading to resolution errors.
For Context
- trait
- In Rust, a trait defines a set of methods that a type must implement. It's similar to an interface in other languages.
- generic arguments
- Placeholders for types or values that are specified when a generic function, struct, or trait is used. For example,
Vec<T>usesTas a generic argument. - paths
- In Rust, paths are used to refer to items like modules, functions, structs, and traits, often involving hierarchical namespaces (e.g.,
std::collections::HashMap). - dyn Trait
- Represents a trait object, allowing for dynamic dispatch.
dyn Traitsignifies a value of any type that implements the specifiedTrait, enabling polymorphism at runtime.