5
5
use std:: ops:: ControlFlow ;
6
6
7
7
use base_db:: { CrateId , Edition } ;
8
- use chalk_ir:: { cast:: Cast , Mutability , TyKind , UniverseIndex , WhereClause } ;
8
+ use chalk_ir:: { cast:: Cast , Mutability , TyKind , TyVariableKind , UniverseIndex , WhereClause } ;
9
9
use hir_def:: {
10
10
data:: { adt:: StructFlags , ImplData } ,
11
11
nameres:: DefMap ,
@@ -1000,14 +1000,14 @@ 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 : Ty ,
1004
1004
first_adjustment : ReceiverAdjustments ,
1005
1005
traits_in_scope : & FxHashSet < TraitId > ,
1006
1006
visible_from_module : VisibleFromModule ,
1007
1007
name : Option < & Name > ,
1008
1008
mut callback : & mut dyn FnMut ( ReceiverAdjustments , AssocItemId , bool ) -> ControlFlow < ( ) > ,
1009
1009
) -> ControlFlow < ( ) > {
1010
- if receiver_ty . value . is_general_var ( Interner , & receiver_ty. binders ) {
1010
+ if let TyKind :: InferenceVar ( _ , TyVariableKind :: General ) = receiver_ty. kind ( Interner ) {
1011
1011
// don't try to resolve methods on unknown types
1012
1012
return ControlFlow :: Continue ( ( ) ) ;
1013
1013
}
@@ -1025,43 +1025,36 @@ fn iterate_method_candidates_with_autoref(
1025
1025
} ;
1026
1026
1027
1027
let mut maybe_reborrowed = first_adjustment. clone ( ) ;
1028
- if let Some ( ( _, _, m) ) = receiver_ty. value . as_reference ( ) {
1028
+ if let Some ( ( _, _, m) ) = receiver_ty. as_reference ( ) {
1029
1029
// Prefer reborrow of references to move
1030
1030
maybe_reborrowed. autoref = Some ( m) ;
1031
1031
maybe_reborrowed. autoderefs += 1 ;
1032
1032
}
1033
1033
1034
1034
iterate_method_candidates_by_receiver ( receiver_ty. clone ( ) , maybe_reborrowed) ?;
1035
1035
1036
- let refed = Canonical {
1037
- value : TyKind :: Ref ( Mutability :: Not , static_lifetime ( ) , receiver_ty. value . clone ( ) )
1038
- . intern ( Interner ) ,
1039
- binders : receiver_ty. binders . clone ( ) ,
1040
- } ;
1036
+ let refed =
1037
+ TyKind :: Ref ( Mutability :: Not , static_lifetime ( ) , receiver_ty. clone ( ) ) . intern ( Interner ) ;
1041
1038
1042
1039
iterate_method_candidates_by_receiver ( refed, first_adjustment. with_autoref ( Mutability :: Not ) ) ?;
1043
1040
1044
- let ref_muted = Canonical {
1045
- value : TyKind :: Ref ( Mutability :: Mut , static_lifetime ( ) , receiver_ty. value . clone ( ) )
1046
- . intern ( Interner ) ,
1047
- binders : receiver_ty. binders . clone ( ) ,
1048
- } ;
1041
+ let ref_muted =
1042
+ TyKind :: Ref ( Mutability :: Mut , static_lifetime ( ) , receiver_ty. clone ( ) ) . intern ( Interner ) ;
1049
1043
1050
1044
iterate_method_candidates_by_receiver ( ref_muted, first_adjustment. with_autoref ( Mutability :: Mut ) )
1051
1045
}
1052
1046
1053
1047
#[ tracing:: instrument( skip_all, fields( name = ?name) ) ]
1054
1048
fn iterate_method_candidates_by_receiver (
1055
1049
table : & mut InferenceTable < ' _ > ,
1056
- receiver_ty : Canonical < Ty > ,
1050
+ receiver_ty : Ty ,
1057
1051
receiver_adjustments : ReceiverAdjustments ,
1058
1052
traits_in_scope : & FxHashSet < TraitId > ,
1059
1053
visible_from_module : VisibleFromModule ,
1060
1054
name : Option < & Name > ,
1061
1055
mut callback : & mut dyn FnMut ( ReceiverAdjustments , AssocItemId , bool ) -> ControlFlow < ( ) > ,
1062
1056
) -> ControlFlow < ( ) > {
1063
1057
table. run_in_snapshot ( |table| {
1064
- let receiver_ty = table. instantiate_canonical ( receiver_ty. clone ( ) ) ;
1065
1058
// We're looking for methods with *receiver* type receiver_ty. These could
1066
1059
// be found in any of the derefs of receiver_ty, so we have to go through
1067
1060
// that, including raw derefs.
@@ -1358,7 +1351,8 @@ pub(crate) fn resolve_indexing_op(
1358
1351
let ty = table. instantiate_canonical ( ty) ;
1359
1352
let deref_chain = autoderef_method_receiver ( & mut table, ty) ;
1360
1353
for ( ty, adj) in deref_chain {
1361
- let goal = generic_implements_goal ( db, & table. trait_env , index_trait, & ty) ;
1354
+ let canonical = table. canonicalize ( ty) ;
1355
+ let goal = generic_implements_goal ( db, & table. trait_env , index_trait, & canonical) ;
1362
1356
if db
1363
1357
. trait_solve ( table. trait_env . krate , table. trait_env . block , goal. cast ( Interner ) )
1364
1358
. is_some ( )
@@ -1638,24 +1632,21 @@ fn generic_implements_goal(
1638
1632
fn autoderef_method_receiver (
1639
1633
table : & mut InferenceTable < ' _ > ,
1640
1634
ty : Ty ,
1641
- ) -> Vec < ( Canonical < Ty > , ReceiverAdjustments ) > {
1635
+ ) -> Vec < ( Ty , ReceiverAdjustments ) > {
1642
1636
let mut deref_chain: Vec < _ > = Vec :: new ( ) ;
1643
- let mut autoderef = autoderef:: Autoderef :: new ( table, ty, false ) ;
1644
- while let Some ( ( ty, derefs) ) = autoderef. next ( ) {
1637
+ let autoderef = autoderef:: Autoderef :: new ( table, ty, false ) ;
1638
+ for ( ty, derefs) in autoderef {
1645
1639
deref_chain. push ( (
1646
- autoderef . table . canonicalize ( ty ) ,
1640
+ ty ,
1647
1641
ReceiverAdjustments { autoref : None , autoderefs : derefs, unsize_array : false } ,
1648
1642
) ) ;
1649
1643
}
1650
1644
// As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!)
1651
- if let Some ( ( TyKind :: Array ( parameters, _) , binders , adj) ) =
1652
- deref_chain. last ( ) . map ( |( ty, adj) | ( ty. value . kind ( Interner ) , ty . binders . clone ( ) , adj) )
1645
+ if let Some ( ( TyKind :: Array ( parameters, _) , adj) ) =
1646
+ deref_chain. last ( ) . map ( |( ty, adj) | ( ty. kind ( Interner ) , adj) )
1653
1647
{
1654
1648
let unsized_ty = TyKind :: Slice ( parameters. clone ( ) ) . intern ( Interner ) ;
1655
- deref_chain. push ( (
1656
- Canonical { value : unsized_ty, binders } ,
1657
- ReceiverAdjustments { unsize_array : true , ..adj. clone ( ) } ,
1658
- ) ) ;
1649
+ deref_chain. push ( ( unsized_ty, ReceiverAdjustments { unsize_array : true , ..adj. clone ( ) } ) ) ;
1659
1650
}
1660
1651
deref_chain
1661
1652
}
0 commit comments