@@ -15,15 +15,15 @@ use ra_syntax::ast::RangeOp;
15
15
16
16
use crate :: {
17
17
autoderef, method_resolution, op,
18
- traits:: { FnTrait , Guidance , InEnvironment , SolutionVariables } ,
18
+ traits:: { FnTrait , InEnvironment } ,
19
19
utils:: { generics, variant_data, Generics } ,
20
20
ApplicationTy , Binders , CallableDef , InferTy , IntTy , Mutability , Obligation , Rawness , Substs ,
21
21
TraitRef , Ty , TypeCtor ,
22
22
} ;
23
23
24
24
use super :: {
25
25
find_breakable, BindingMode , BreakableContext , Diverges , Expectation , InferenceContext ,
26
- InferenceDiagnostic , Solution , TypeMismatch ,
26
+ InferenceDiagnostic , TypeMismatch ,
27
27
} ;
28
28
29
29
impl < ' a > InferenceContext < ' a > {
@@ -65,52 +65,47 @@ impl<'a> InferenceContext<'a> {
65
65
66
66
fn callable_sig_from_fn_trait ( & mut self , ty : & Ty , num_args : usize ) -> Option < ( Vec < Ty > , Ty ) > {
67
67
let krate = self . resolver . krate ( ) ?;
68
- let fn_traits: Vec < crate :: TraitId > = [ FnTrait :: FnOnce , FnTrait :: FnMut , FnTrait :: Fn ]
69
- . iter ( )
70
- . filter_map ( |f| f. get_id ( self . db , krate) )
71
- . collect ( ) ;
72
68
let fn_once_trait = FnTrait :: FnOnce . get_id ( self . db , krate) ?;
73
69
let output_assoc_type =
74
70
self . db . trait_data ( fn_once_trait) . associated_type_by_name ( & name ! [ Output ] ) ?;
75
- for fn_trait in fn_traits {
76
- let generic_params = generics ( self . db . upcast ( ) , fn_trait. into ( ) ) ;
77
- if generic_params. len ( ) != 2 {
78
- continue ;
79
- }
80
-
81
- let mut param_builder = Substs :: builder ( num_args) ;
82
- for _ in 0 ..num_args {
83
- param_builder = param_builder. push ( self . table . new_type_var ( ) ) ;
84
- }
85
- let arg_ty = Ty :: Apply ( ApplicationTy {
86
- ctor : TypeCtor :: Tuple { cardinality : num_args as u16 } ,
87
- parameters : param_builder. build ( ) ,
88
- } ) ;
89
- let substs = Substs :: build_for_generics ( & generic_params)
90
- . push ( ty. clone ( ) )
91
- . push ( arg_ty. clone ( ) )
92
- . build ( ) ;
93
-
94
- let trait_ref = TraitRef { trait_ : fn_trait, substs : substs. clone ( ) } ;
95
- let trait_env = Arc :: clone ( & self . trait_env ) ;
96
- let implements_fn_goal = self . canonicalizer ( ) . canonicalize_obligation ( InEnvironment {
97
- value : Obligation :: Trait ( trait_ref) ,
98
- environment : trait_env,
99
- } ) ;
100
- let solution = match self . db . trait_solve ( krate, implements_fn_goal. value . clone ( ) ) {
101
- Some ( Solution :: Unique ( SolutionVariables ( solution) ) )
102
- | Some ( Solution :: Ambig ( Guidance :: Definite ( SolutionVariables ( solution) ) ) )
103
- | Some ( Solution :: Ambig ( Guidance :: Suggested ( SolutionVariables ( solution) ) ) ) => {
104
- solution
105
- }
106
- _ => continue ,
107
- } ;
71
+ let generic_params = generics ( self . db . upcast ( ) , fn_once_trait. into ( ) ) ;
72
+ if generic_params. len ( ) != 2 {
73
+ return None ;
74
+ }
75
+
76
+ let mut param_builder = Substs :: builder ( num_args) ;
77
+ let mut arg_tys = vec ! [ ] ;
78
+ for _ in 0 ..num_args {
79
+ let arg = self . table . new_type_var ( ) ;
80
+ param_builder = param_builder. push ( arg. clone ( ) ) ;
81
+ arg_tys. push ( arg) ;
82
+ }
83
+ let parameters = param_builder. build ( ) ;
84
+ let arg_ty = Ty :: Apply ( ApplicationTy {
85
+ ctor : TypeCtor :: Tuple { cardinality : num_args as u16 } ,
86
+ parameters,
87
+ } ) ;
88
+ let substs = Substs :: build_for_generics ( & generic_params)
89
+ . push ( ty. clone ( ) )
90
+ . push ( arg_ty. clone ( ) )
91
+ . build ( ) ;
92
+
93
+ let trait_env = Arc :: clone ( & self . trait_env ) ;
94
+ let implements_fn_trait =
95
+ Obligation :: Trait ( TraitRef { trait_ : fn_once_trait, substs : substs. clone ( ) } ) ;
96
+ let goal = self . canonicalizer ( ) . canonicalize_obligation ( InEnvironment {
97
+ value : implements_fn_trait. clone ( ) ,
98
+ environment : trait_env,
99
+ } ) ;
100
+ if self . db . trait_solve ( krate, goal. value ) . is_some ( ) {
101
+ self . obligations . push ( implements_fn_trait) ;
108
102
let output_proj_ty =
109
103
crate :: ProjectionTy { associated_ty : output_assoc_type, parameters : substs } ;
110
104
let return_ty = self . normalize_projection_ty ( output_proj_ty) ;
111
- return Some ( ( solution. value , return_ty) ) ;
105
+ Some ( ( arg_tys, return_ty) )
106
+ } else {
107
+ None
112
108
}
113
- None
114
109
}
115
110
116
111
pub fn callable_sig ( & mut self , ty : & Ty , num_args : usize ) -> Option < ( Vec < Ty > , Ty ) > {
0 commit comments