@@ -1751,27 +1751,6 @@ impl<'db, 'c> SpecializationBuilder<'db, 'c> {
17511751 self . types
17521752 }
17531753
1754- /// Map the types that have been assigned in this specialization.
1755- pub ( crate ) fn mapped (
1756- & self ,
1757- generic_context : GenericContext < ' db > ,
1758- f : impl Fn ( BoundTypeVarInstance < ' db > , Type < ' db > ) -> Type < ' db > ,
1759- ) -> Self {
1760- let mut types = self . types . clone ( ) ;
1761- for ( identity, variable) in generic_context. variables_inner ( self . db ) {
1762- if let Some ( ty) = types. get_mut ( identity) {
1763- * ty = f ( * variable, * ty) ;
1764- }
1765- }
1766-
1767- Self {
1768- db : self . db ,
1769- constraints : self . constraints ,
1770- inferable : self . inferable ,
1771- types,
1772- }
1773- }
1774-
17751754 pub ( crate ) fn with_default (
17761755 & self ,
17771756 generic_context : GenericContext < ' db > ,
@@ -1805,24 +1784,20 @@ impl<'db, 'c> SpecializationBuilder<'db, 'c> {
18051784 /// Build a specialization, using a caller-provided hook to select the solution for each
18061785 /// typevar.
18071786 ///
1808- /// The `choose` hook is called for each typevar in the generic context with the typevar's
1809- /// materialized lower and upper bounds:
1810- /// - For typevars that were inferred (present in the type mappings), both bounds are set to
1811- /// the inferred type (representing an equality constraint).
1812- /// - For typevars that were not inferred, `lower` is `Never` and `upper` is `object`
1813- /// (representing an unconstrained typevar).
1787+ /// The `choose` hook is called for each *inferred* typevar (those with entries in the type
1788+ /// mappings) with the typevar's materialized lower and upper bounds. Currently, both bounds
1789+ /// are set to the inferred type (representing an equality constraint). Unmapped typevars
1790+ /// are left to `specialize_recursive` to fill in with defaults.
18141791 ///
18151792 /// The hook returns:
18161793 /// - `Some(ty)` to use `ty` as the specialization for this typevar
1817- /// - `None` to use the default (the inferred type for mapped typevars, or the typevar's
1818- /// default for unmapped typevars)
1794+ /// - `None` to use the inferred type unchanged
18191795 ///
18201796 /// This method replaces the pattern of `mapped(...).build(...)`, allowing callers to
18211797 /// transform inferred types (e.g., literal promotion) in a single step. In the future,
18221798 /// when the builder's internal representation switches from a `HashMap` to a `ConstraintSet`,
18231799 /// the hook will receive actual lower/upper bounds from the constraint set instead of
18241800 /// synthetic equality bounds.
1825- #[ expect( dead_code) ] // Will be used in Phase 2 of the constraint set migration
18261801 pub ( crate ) fn build_with (
18271802 & mut self ,
18281803 generic_context : GenericContext < ' db > ,
@@ -1832,14 +1807,10 @@ impl<'db, 'c> SpecializationBuilder<'db, 'c> {
18321807 . variables_inner ( self . db )
18331808 . iter ( )
18341809 . map ( |( identity, variable) | {
1835- if let Some ( & mapped_ty) = self . types . get ( identity) {
1836- // The typevar was inferred — present both bounds as the inferred type.
1837- let chosen = choose ( * variable, mapped_ty, mapped_ty) ;
1838- Some ( chosen. unwrap_or ( mapped_ty) )
1839- } else {
1840- // The typevar was not inferred — present open bounds.
1841- choose ( * variable, Type :: Never , Type :: object ( ) )
1842- }
1810+ let mapped_ty = self . types . get ( identity) . copied ( ) ?;
1811+ // The typevar was inferred — present both bounds as the inferred type.
1812+ let chosen = choose ( * variable, mapped_ty, mapped_ty) ;
1813+ Some ( chosen. unwrap_or ( mapped_ty) )
18431814 } ) ;
18441815
18451816 generic_context. specialize_recursive ( self . db , types)
0 commit comments