@@ -973,7 +973,7 @@ pub fn iterate_method_candidates_dyn(
973973 deref_chain. into_iter ( ) . try_for_each ( |( receiver_ty, adj) | {
974974 iterate_method_candidates_with_autoref (
975975 & mut table,
976- & receiver_ty,
976+ receiver_ty,
977977 adj,
978978 traits_in_scope,
979979 visible_from_module,
@@ -1000,7 +1000,7 @@ pub fn iterate_method_candidates_dyn(
10001000#[ tracing:: instrument( skip_all, fields( name = ?name) ) ]
10011001fn iterate_method_candidates_with_autoref (
10021002 table : & mut InferenceTable < ' _ > ,
1003- receiver_ty : & Canonical < Ty > ,
1003+ receiver_ty : Canonical < Ty > ,
10041004 first_adjustment : ReceiverAdjustments ,
10051005 traits_in_scope : & FxHashSet < TraitId > ,
10061006 visible_from_module : VisibleFromModule ,
@@ -1031,32 +1031,29 @@ fn iterate_method_candidates_with_autoref(
10311031 maybe_reborrowed. autoderefs += 1 ;
10321032 }
10331033
1034- iterate_method_candidates_by_receiver ( receiver_ty, maybe_reborrowed) ?;
1034+ iterate_method_candidates_by_receiver ( receiver_ty. clone ( ) , maybe_reborrowed) ?;
10351035
10361036 let refed = Canonical {
10371037 value : TyKind :: Ref ( Mutability :: Not , static_lifetime ( ) , receiver_ty. value . clone ( ) )
10381038 . intern ( Interner ) ,
10391039 binders : receiver_ty. binders . clone ( ) ,
10401040 } ;
10411041
1042- iterate_method_candidates_by_receiver ( & refed, first_adjustment. with_autoref ( Mutability :: Not ) ) ?;
1042+ iterate_method_candidates_by_receiver ( refed, first_adjustment. with_autoref ( Mutability :: Not ) ) ?;
10431043
10441044 let ref_muted = Canonical {
10451045 value : TyKind :: Ref ( Mutability :: Mut , static_lifetime ( ) , receiver_ty. value . clone ( ) )
10461046 . intern ( Interner ) ,
10471047 binders : receiver_ty. binders . clone ( ) ,
10481048 } ;
10491049
1050- iterate_method_candidates_by_receiver (
1051- & ref_muted,
1052- first_adjustment. with_autoref ( Mutability :: Mut ) ,
1053- )
1050+ iterate_method_candidates_by_receiver ( ref_muted, first_adjustment. with_autoref ( Mutability :: Mut ) )
10541051}
10551052
10561053#[ tracing:: instrument( skip_all, fields( name = ?name) ) ]
10571054fn iterate_method_candidates_by_receiver (
10581055 table : & mut InferenceTable < ' _ > ,
1059- receiver_ty : & Canonical < Ty > ,
1056+ receiver_ty : Canonical < Ty > ,
10601057 receiver_adjustments : ReceiverAdjustments ,
10611058 traits_in_scope : & FxHashSet < TraitId > ,
10621059 visible_from_module : VisibleFromModule ,
@@ -1143,9 +1140,9 @@ fn iterate_trait_method_candidates(
11431140 callback : & mut dyn FnMut ( ReceiverAdjustments , AssocItemId , bool ) -> ControlFlow < ( ) > ,
11441141) -> ControlFlow < ( ) > {
11451142 let db = table. db ;
1146- let env = table. trait_env . clone ( ) ;
11471143
1148- let canonical_self_ty = table. canonicalize ( self_ty. clone ( ) ) . value ;
1144+ let canonical_self_ty = table. canonicalize ( self_ty. clone ( ) ) ;
1145+ let TraitEnvironment { krate, block, .. } = * table. trait_env ;
11491146
11501147 ' traits: for & t in traits_in_scope {
11511148 let data = db. trait_data ( t) ;
@@ -1160,7 +1157,7 @@ fn iterate_trait_method_candidates(
11601157 {
11611158 // FIXME: this should really be using the edition of the method name's span, in case it
11621159 // comes from a macro
1163- if db. crate_graph ( ) [ env . krate ] . edition < Edition :: Edition2021 {
1160+ if db. crate_graph ( ) [ krate] . edition < Edition :: Edition2021 {
11641161 continue ;
11651162 }
11661163 }
@@ -1179,8 +1176,8 @@ fn iterate_trait_method_candidates(
11791176 IsValidCandidate :: No => continue ,
11801177 } ;
11811178 if !known_implemented {
1182- let goal = generic_implements_goal ( db, env . clone ( ) , t, & canonical_self_ty) ;
1183- if db. trait_solve ( env . krate , env . block , goal. cast ( Interner ) ) . is_none ( ) {
1179+ let goal = generic_implements_goal ( db, & table . trait_env , t, & canonical_self_ty) ;
1180+ if db. trait_solve ( krate, block, goal. cast ( Interner ) ) . is_none ( ) {
11841181 continue ' traits;
11851182 }
11861183 }
@@ -1361,7 +1358,7 @@ pub(crate) fn resolve_indexing_op(
13611358 let ty = table. instantiate_canonical ( ty) ;
13621359 let deref_chain = autoderef_method_receiver ( & mut table, ty) ;
13631360 for ( ty, adj) in deref_chain {
1364- let goal = generic_implements_goal ( db, table. trait_env . clone ( ) , index_trait, & ty) ;
1361+ let goal = generic_implements_goal ( db, & table. trait_env , index_trait, & ty) ;
13651362 if db
13661363 . trait_solve ( table. trait_env . krate , table. trait_env . block , goal. cast ( Interner ) )
13671364 . is_some ( )
@@ -1544,7 +1541,7 @@ fn is_valid_impl_fn_candidate(
15441541
15451542 for goal in goals. clone ( ) {
15461543 let in_env = InEnvironment :: new ( & table. trait_env . env , goal) ;
1547- let canonicalized = table. canonicalize ( in_env) ;
1544+ let canonicalized = table. canonicalize_with_free_vars ( in_env) ;
15481545 let solution = table. db . trait_solve (
15491546 table. trait_env . krate ,
15501547 table. trait_env . block ,
@@ -1582,10 +1579,10 @@ fn is_valid_impl_fn_candidate(
15821579pub fn implements_trait (
15831580 ty : & Canonical < Ty > ,
15841581 db : & dyn HirDatabase ,
1585- env : Arc < TraitEnvironment > ,
1582+ env : & TraitEnvironment ,
15861583 trait_ : TraitId ,
15871584) -> bool {
1588- let goal = generic_implements_goal ( db, env. clone ( ) , trait_, ty) ;
1585+ let goal = generic_implements_goal ( db, env, trait_, ty) ;
15891586 let solution = db. trait_solve ( env. krate , env. block , goal. cast ( Interner ) ) ;
15901587
15911588 solution. is_some ( )
@@ -1594,10 +1591,10 @@ pub fn implements_trait(
15941591pub fn implements_trait_unique (
15951592 ty : & Canonical < Ty > ,
15961593 db : & dyn HirDatabase ,
1597- env : Arc < TraitEnvironment > ,
1594+ env : & TraitEnvironment ,
15981595 trait_ : TraitId ,
15991596) -> bool {
1600- let goal = generic_implements_goal ( db, env. clone ( ) , trait_, ty) ;
1597+ let goal = generic_implements_goal ( db, env, trait_, ty) ;
16011598 let solution = db. trait_solve ( env. krate , env. block , goal. cast ( Interner ) ) ;
16021599
16031600 matches ! ( solution, Some ( crate :: Solution :: Unique ( _) ) )
@@ -1608,32 +1605,34 @@ pub fn implements_trait_unique(
16081605#[ tracing:: instrument( skip_all) ]
16091606fn generic_implements_goal (
16101607 db : & dyn HirDatabase ,
1611- env : Arc < TraitEnvironment > ,
1608+ env : & TraitEnvironment ,
16121609 trait_ : TraitId ,
16131610 self_ty : & Canonical < Ty > ,
16141611) -> Canonical < InEnvironment < super :: DomainGoal > > {
1615- let mut kinds = self_ty. binders . interned ( ) . to_vec ( ) ;
1612+ let binders = self_ty. binders . interned ( ) ;
16161613 let trait_ref = TyBuilder :: trait_ref ( db, trait_)
16171614 . push ( self_ty. value . clone ( ) )
1618- . fill_with_bound_vars ( DebruijnIndex :: INNERMOST , kinds . len ( ) )
1615+ . fill_with_bound_vars ( DebruijnIndex :: INNERMOST , binders . len ( ) )
16191616 . build ( ) ;
1620- kinds. extend ( trait_ref. substitution . iter ( Interner ) . skip ( 1 ) . map ( |it| {
1621- let vk = match it. data ( Interner ) {
1622- chalk_ir:: GenericArgData :: Ty ( _) => {
1623- chalk_ir:: VariableKind :: Ty ( chalk_ir:: TyVariableKind :: General )
1624- }
1625- chalk_ir:: GenericArgData :: Lifetime ( _) => chalk_ir:: VariableKind :: Lifetime ,
1626- chalk_ir:: GenericArgData :: Const ( c) => {
1627- chalk_ir:: VariableKind :: Const ( c. data ( Interner ) . ty . clone ( ) )
1628- }
1629- } ;
1630- chalk_ir:: WithKind :: new ( vk, UniverseIndex :: ROOT )
1631- } ) ) ;
1617+
1618+ let kinds =
1619+ binders. iter ( ) . cloned ( ) . chain ( trait_ref. substitution . iter ( Interner ) . skip ( 1 ) . map ( |it| {
1620+ let vk = match it. data ( Interner ) {
1621+ chalk_ir:: GenericArgData :: Ty ( _) => {
1622+ chalk_ir:: VariableKind :: Ty ( chalk_ir:: TyVariableKind :: General )
1623+ }
1624+ chalk_ir:: GenericArgData :: Lifetime ( _) => chalk_ir:: VariableKind :: Lifetime ,
1625+ chalk_ir:: GenericArgData :: Const ( c) => {
1626+ chalk_ir:: VariableKind :: Const ( c. data ( Interner ) . ty . clone ( ) )
1627+ }
1628+ } ;
1629+ chalk_ir:: WithKind :: new ( vk, UniverseIndex :: ROOT )
1630+ } ) ) ;
1631+ let binders = CanonicalVarKinds :: from_iter ( Interner , kinds) ;
1632+
16321633 let obligation = trait_ref. cast ( Interner ) ;
1633- Canonical {
1634- binders : CanonicalVarKinds :: from_iter ( Interner , kinds) ,
1635- value : InEnvironment :: new ( & env. env , obligation) ,
1636- }
1634+ let value = InEnvironment :: new ( & env. env , obligation) ;
1635+ Canonical { binders, value }
16371636}
16381637
16391638fn autoderef_method_receiver (
@@ -1644,7 +1643,7 @@ fn autoderef_method_receiver(
16441643 let mut autoderef = autoderef:: Autoderef :: new ( table, ty, false ) ;
16451644 while let Some ( ( ty, derefs) ) = autoderef. next ( ) {
16461645 deref_chain. push ( (
1647- autoderef. table . canonicalize ( ty) . value ,
1646+ autoderef. table . canonicalize ( ty) ,
16481647 ReceiverAdjustments { autoref : None , autoderefs : derefs, unsize_array : false } ,
16491648 ) ) ;
16501649 }
0 commit comments