@@ -85,54 +85,56 @@ pub fn call_callee(
85
85
continue ;
86
86
}
87
87
88
- // NOTE: PERFORMANCE: TODO: This could probably be optimized
89
- if let Some ( caller) = ctx
88
+ let Some ( caller) = ctx
90
89
. func_ref
91
90
. map ( |caller_func_ref| ctx. asg . funcs . get ( caller_func_ref) . unwrap ( ) )
92
- {
93
- let from_env = caller. impl_params . params . iter ( ) . filter ( |( _, param_trait) | {
94
- callee
91
+ else {
92
+ continue ;
93
+ } ;
94
+
95
+ // NOTE: PERFORMANCE: TODO: This could probably be optimized
96
+ let from_env = caller. impl_params . params . iter ( ) . filter ( |( _, param_trait) | {
97
+ callee
98
+ . recipe
99
+ . resolve_trait ( expected_trait)
100
+ . map_or ( false , |expected_trait| * * param_trait == expected_trait)
101
+ } ) ;
102
+
103
+ match from_env. exactly_one ( ) {
104
+ Ok ( ( param_name, _) ) => {
105
+ if callee
95
106
. recipe
96
- . resolve_trait ( expected_trait)
97
- . map_or ( false , |expected_trait| * * param_trait == expected_trait)
98
- } ) ;
99
-
100
- match from_env. exactly_one ( ) {
101
- Ok ( ( param_name, _) ) => {
102
- if callee
103
- . recipe
104
- . polymorphs
105
- . insert ( expected_name. into ( ) , PolyValue :: PolyImpl ( param_name. into ( ) ) )
106
- . is_some ( )
107
- {
108
- return Err ( ResolveError :: other (
107
+ . polymorphs
108
+ . insert ( expected_name. into ( ) , PolyValue :: PolyImpl ( param_name. into ( ) ) )
109
+ . is_some ( )
110
+ {
111
+ return Err ( ResolveError :: other (
109
112
format ! (
110
113
"Could not automatically supply trait implementation for '${} {}' required by function call, since the polymorph is already in use" ,
111
114
expected_name,
112
115
expected_trait. display( & ctx. asg) ,
113
116
) ,
114
117
source,
115
118
) ) ;
116
- }
117
119
}
118
- Err ( mut non_unique) => {
119
- return Err ( ResolveError :: other (
120
- if non_unique. next ( ) . is_some ( ) {
121
- format ! (
120
+ }
121
+ Err ( mut non_unique) => {
122
+ return Err ( ResolveError :: other (
123
+ if non_unique. next ( ) . is_some ( ) {
124
+ format ! (
122
125
"Ambiguous trait implementation for '${} {}' required by function call, please specify manually" ,
123
126
expected_name,
124
127
expected_trait. display( & ctx. asg) ,
125
128
)
126
- } else {
127
- format ! (
128
- "Missing '${} {}' trait implementation required by function call" ,
129
- expected_name,
130
- expected_trait. display( & ctx. asg) ,
131
- )
132
- } ,
133
- source,
134
- ) ) ;
135
- }
129
+ } else {
130
+ format ! (
131
+ "Missing '${} {}' trait implementation required by function call" ,
132
+ expected_name,
133
+ expected_trait. display( & ctx. asg) ,
134
+ )
135
+ } ,
136
+ source,
137
+ ) ) ;
136
138
}
137
139
}
138
140
}
0 commit comments