@@ -973,7 +973,7 @@ pub fn iterate_method_candidates_dyn(
973
973
deref_chain. into_iter ( ) . try_for_each ( |( receiver_ty, adj) | {
974
974
iterate_method_candidates_with_autoref (
975
975
& mut table,
976
- & receiver_ty,
976
+ receiver_ty,
977
977
adj,
978
978
traits_in_scope,
979
979
visible_from_module,
@@ -1000,7 +1000,7 @@ pub fn iterate_method_candidates_dyn(
1000
1000
#[ tracing:: instrument( skip_all, fields( name = ?name) ) ]
1001
1001
fn iterate_method_candidates_with_autoref (
1002
1002
table : & mut InferenceTable < ' _ > ,
1003
- receiver_ty : & Canonical < Ty > ,
1003
+ receiver_ty : Canonical < Ty > ,
1004
1004
first_adjustment : ReceiverAdjustments ,
1005
1005
traits_in_scope : & FxHashSet < TraitId > ,
1006
1006
visible_from_module : VisibleFromModule ,
@@ -1031,32 +1031,29 @@ fn iterate_method_candidates_with_autoref(
1031
1031
maybe_reborrowed. autoderefs += 1 ;
1032
1032
}
1033
1033
1034
- iterate_method_candidates_by_receiver ( receiver_ty, maybe_reborrowed) ?;
1034
+ iterate_method_candidates_by_receiver ( receiver_ty. clone ( ) , maybe_reborrowed) ?;
1035
1035
1036
1036
let refed = Canonical {
1037
1037
value : TyKind :: Ref ( Mutability :: Not , static_lifetime ( ) , receiver_ty. value . clone ( ) )
1038
1038
. intern ( Interner ) ,
1039
1039
binders : receiver_ty. binders . clone ( ) ,
1040
1040
} ;
1041
1041
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 ) ) ?;
1043
1043
1044
1044
let ref_muted = Canonical {
1045
1045
value : TyKind :: Ref ( Mutability :: Mut , static_lifetime ( ) , receiver_ty. value . clone ( ) )
1046
1046
. intern ( Interner ) ,
1047
1047
binders : receiver_ty. binders . clone ( ) ,
1048
1048
} ;
1049
1049
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 ) )
1054
1051
}
1055
1052
1056
1053
#[ tracing:: instrument( skip_all, fields( name = ?name) ) ]
1057
1054
fn iterate_method_candidates_by_receiver (
1058
1055
table : & mut InferenceTable < ' _ > ,
1059
- receiver_ty : & Canonical < Ty > ,
1056
+ receiver_ty : Canonical < Ty > ,
1060
1057
receiver_adjustments : ReceiverAdjustments ,
1061
1058
traits_in_scope : & FxHashSet < TraitId > ,
1062
1059
visible_from_module : VisibleFromModule ,
@@ -1143,9 +1140,9 @@ fn iterate_trait_method_candidates(
1143
1140
callback : & mut dyn FnMut ( ReceiverAdjustments , AssocItemId , bool ) -> ControlFlow < ( ) > ,
1144
1141
) -> ControlFlow < ( ) > {
1145
1142
let db = table. db ;
1146
- let env = table. trait_env . clone ( ) ;
1147
1143
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 ;
1149
1146
1150
1147
' traits: for & t in traits_in_scope {
1151
1148
let data = db. trait_data ( t) ;
@@ -1160,7 +1157,7 @@ fn iterate_trait_method_candidates(
1160
1157
{
1161
1158
// FIXME: this should really be using the edition of the method name's span, in case it
1162
1159
// comes from a macro
1163
- if db. crate_graph ( ) [ env . krate ] . edition < Edition :: Edition2021 {
1160
+ if db. crate_graph ( ) [ krate] . edition < Edition :: Edition2021 {
1164
1161
continue ;
1165
1162
}
1166
1163
}
@@ -1179,8 +1176,8 @@ fn iterate_trait_method_candidates(
1179
1176
IsValidCandidate :: No => continue ,
1180
1177
} ;
1181
1178
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 ( ) {
1184
1181
continue ' traits;
1185
1182
}
1186
1183
}
@@ -1361,7 +1358,7 @@ pub(crate) fn resolve_indexing_op(
1361
1358
let ty = table. instantiate_canonical ( ty) ;
1362
1359
let deref_chain = autoderef_method_receiver ( & mut table, ty) ;
1363
1360
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) ;
1365
1362
if db
1366
1363
. trait_solve ( table. trait_env . krate , table. trait_env . block , goal. cast ( Interner ) )
1367
1364
. is_some ( )
@@ -1544,7 +1541,7 @@ fn is_valid_impl_fn_candidate(
1544
1541
1545
1542
for goal in goals. clone ( ) {
1546
1543
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) ;
1548
1545
let solution = table. db . trait_solve (
1549
1546
table. trait_env . krate ,
1550
1547
table. trait_env . block ,
@@ -1582,10 +1579,10 @@ fn is_valid_impl_fn_candidate(
1582
1579
pub fn implements_trait (
1583
1580
ty : & Canonical < Ty > ,
1584
1581
db : & dyn HirDatabase ,
1585
- env : Arc < TraitEnvironment > ,
1582
+ env : & TraitEnvironment ,
1586
1583
trait_ : TraitId ,
1587
1584
) -> bool {
1588
- let goal = generic_implements_goal ( db, env. clone ( ) , trait_, ty) ;
1585
+ let goal = generic_implements_goal ( db, env, trait_, ty) ;
1589
1586
let solution = db. trait_solve ( env. krate , env. block , goal. cast ( Interner ) ) ;
1590
1587
1591
1588
solution. is_some ( )
@@ -1594,10 +1591,10 @@ pub fn implements_trait(
1594
1591
pub fn implements_trait_unique (
1595
1592
ty : & Canonical < Ty > ,
1596
1593
db : & dyn HirDatabase ,
1597
- env : Arc < TraitEnvironment > ,
1594
+ env : & TraitEnvironment ,
1598
1595
trait_ : TraitId ,
1599
1596
) -> bool {
1600
- let goal = generic_implements_goal ( db, env. clone ( ) , trait_, ty) ;
1597
+ let goal = generic_implements_goal ( db, env, trait_, ty) ;
1601
1598
let solution = db. trait_solve ( env. krate , env. block , goal. cast ( Interner ) ) ;
1602
1599
1603
1600
matches ! ( solution, Some ( crate :: Solution :: Unique ( _) ) )
@@ -1608,32 +1605,34 @@ pub fn implements_trait_unique(
1608
1605
#[ tracing:: instrument( skip_all) ]
1609
1606
fn generic_implements_goal (
1610
1607
db : & dyn HirDatabase ,
1611
- env : Arc < TraitEnvironment > ,
1608
+ env : & TraitEnvironment ,
1612
1609
trait_ : TraitId ,
1613
1610
self_ty : & Canonical < Ty > ,
1614
1611
) -> Canonical < InEnvironment < super :: DomainGoal > > {
1615
- let mut kinds = self_ty. binders . interned ( ) . to_vec ( ) ;
1612
+ let binders = self_ty. binders . interned ( ) ;
1616
1613
let trait_ref = TyBuilder :: trait_ref ( db, trait_)
1617
1614
. push ( self_ty. value . clone ( ) )
1618
- . fill_with_bound_vars ( DebruijnIndex :: INNERMOST , kinds . len ( ) )
1615
+ . fill_with_bound_vars ( DebruijnIndex :: INNERMOST , binders . len ( ) )
1619
1616
. 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
+
1632
1633
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 }
1637
1636
}
1638
1637
1639
1638
fn autoderef_method_receiver (
@@ -1644,7 +1643,7 @@ fn autoderef_method_receiver(
1644
1643
let mut autoderef = autoderef:: Autoderef :: new ( table, ty, false ) ;
1645
1644
while let Some ( ( ty, derefs) ) = autoderef. next ( ) {
1646
1645
deref_chain. push ( (
1647
- autoderef. table . canonicalize ( ty) . value ,
1646
+ autoderef. table . canonicalize ( ty) ,
1648
1647
ReceiverAdjustments { autoref : None , autoderefs : derefs, unsize_array : false } ,
1649
1648
) ) ;
1650
1649
}
0 commit comments