Where clauses handled in two passes
GCC Rust's type checking now uses two passes to correctly resolve complex where clauses and type bindings.
GCC Rust’s type checker now uses a two-pass approach to handle ‘where’ clauses, improving the resolution of type constraints. The first pass registers bounds on single-segment TypePaths, and the second pass handles regular type bindings like I::Item or Item = U::Item. This ordering is crucial for correctly resolving dependencies where initial predicates must be established before parameter declarations and projections.
In Details
The gccrs type checker now implements a two-pass system for resolving where clauses. Pass 1 registers bounds on TypePath segments (e.g., P: Deref). Pass 2 registers type bindings (e.g., I::Item or Item = U::Item). This addresses ordering dependencies where projections rely on previously resolved bounds and parameter declarations. The changes are primarily in typecheck/rust-hir-type-check-*.cc files.
- where clauses
- In Rust,
whereclauses are used to specify trait bounds or associated type constraints on generic parameters. They help to clarify complex generic relationships. - TypePaths
- Represents a path to a type in Rust, which can include module names, type names, and generic arguments. Examples include
std::collections::HashMaporT::Output. - trait bounds
- Constraints that specify which traits a generic type parameter must implement. For example,
T: Displaymeans thatTmust implement theDisplaytrait. - associated type
- Types that are defined within a trait and are specific to each type that implements the trait. For example, an
Iteratortrait might have anItemassociated type representing the type of elements it yields.