@@ -76,16 +76,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
76
76
found : Ty < ' tcx > ,
77
77
can_satisfy : impl FnOnce ( Ty < ' tcx > ) -> bool ,
78
78
) -> bool {
79
- let Some ( ( def_id_or_name, output, num_inputs ) ) = self . extract_callable_info ( expr, found)
79
+ let Some ( ( def_id_or_name, output, inputs ) ) = self . extract_callable_info ( expr, found)
80
80
else { return false ; } ;
81
81
if can_satisfy ( output) {
82
- let ( sugg_call, mut applicability) = match num_inputs {
82
+ let ( sugg_call, mut applicability) = match inputs . len ( ) {
83
83
0 => ( "" . to_string ( ) , Applicability :: MachineApplicable ) ,
84
84
1 ..=4 => (
85
- ( 0 ..num_inputs) . map ( |_| "_" ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ,
86
- Applicability :: MachineApplicable ,
85
+ inputs
86
+ . iter ( )
87
+ . map ( |ty| {
88
+ if ty. is_suggestable ( self . tcx , false ) {
89
+ format ! ( "/* {ty} */" )
90
+ } else {
91
+ "" . to_string ( )
92
+ }
93
+ } )
94
+ . collect :: < Vec < _ > > ( )
95
+ . join ( ", " ) ,
96
+ Applicability :: HasPlaceholders ,
87
97
) ,
88
- _ => ( "..." . to_string ( ) , Applicability :: HasPlaceholders ) ,
98
+ _ => ( "/* ... */ " . to_string ( ) , Applicability :: HasPlaceholders ) ,
89
99
} ;
90
100
91
101
let msg = match def_id_or_name {
@@ -137,19 +147,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137
147
& self ,
138
148
expr : & Expr < ' _ > ,
139
149
found : Ty < ' tcx > ,
140
- ) -> Option < ( DefIdOrName , Ty < ' tcx > , usize ) > {
150
+ ) -> Option < ( DefIdOrName , Ty < ' tcx > , Vec < Ty < ' tcx > > ) > {
141
151
// Autoderef is useful here because sometimes we box callables, etc.
142
152
let Some ( ( def_id_or_name, output, inputs) ) = self . autoderef ( expr. span , found) . silence_errors ( ) . find_map ( |( found, _) | {
143
153
match * found. kind ( ) {
144
154
ty:: FnPtr ( fn_sig) =>
145
- Some ( ( DefIdOrName :: Name ( "function pointer" ) , fn_sig. output ( ) , fn_sig. inputs ( ) . skip_binder ( ) . len ( ) ) ) ,
155
+ Some ( ( DefIdOrName :: Name ( "function pointer" ) , fn_sig. output ( ) , fn_sig. inputs ( ) ) ) ,
146
156
ty:: FnDef ( def_id, _) => {
147
157
let fn_sig = found. fn_sig ( self . tcx ) ;
148
- Some ( ( DefIdOrName :: DefId ( def_id) , fn_sig. output ( ) , fn_sig. inputs ( ) . skip_binder ( ) . len ( ) ) )
158
+ Some ( ( DefIdOrName :: DefId ( def_id) , fn_sig. output ( ) , fn_sig. inputs ( ) ) )
149
159
}
150
160
ty:: Closure ( def_id, substs) => {
151
161
let fn_sig = substs. as_closure ( ) . sig ( ) ;
152
- Some ( ( DefIdOrName :: DefId ( def_id) , fn_sig. output ( ) , fn_sig. inputs ( ) . skip_binder ( ) . len ( ) - 1 ) )
162
+ Some ( ( DefIdOrName :: DefId ( def_id) , fn_sig. output ( ) , fn_sig. inputs ( ) . map_bound ( |inputs| & inputs [ 1 .. ] ) ) )
153
163
}
154
164
ty:: Opaque ( def_id, substs) => {
155
165
self . tcx . bound_item_bounds ( def_id) . subst ( self . tcx , substs) . iter ( ) . find_map ( |pred| {
@@ -161,7 +171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
161
171
Some ( (
162
172
DefIdOrName :: DefId ( def_id) ,
163
173
pred. kind ( ) . rebind ( proj. term . ty ( ) . unwrap ( ) ) ,
164
- args. len ( ) ,
174
+ pred . kind ( ) . rebind ( args. as_slice ( ) ) ,
165
175
) )
166
176
} else {
167
177
None
@@ -178,7 +188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
178
188
Some ( (
179
189
DefIdOrName :: Name ( "trait object" ) ,
180
190
pred. rebind ( proj. term . ty ( ) . unwrap ( ) ) ,
181
- args. len ( ) ,
191
+ pred . rebind ( args. as_slice ( ) ) ,
182
192
) )
183
193
} else {
184
194
None
@@ -197,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
197
207
Some ( (
198
208
DefIdOrName :: DefId ( def_id) ,
199
209
pred. kind ( ) . rebind ( proj. term . ty ( ) . unwrap ( ) ) ,
200
- args. len ( ) ,
210
+ pred . kind ( ) . rebind ( args. as_slice ( ) ) ,
201
211
) )
202
212
} else {
203
213
None
@@ -209,6 +219,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
209
219
} ) else { return None ; } ;
210
220
211
221
let output = self . replace_bound_vars_with_fresh_vars ( expr. span , infer:: FnCall , output) ;
222
+ let inputs = inputs
223
+ . skip_binder ( )
224
+ . iter ( )
225
+ . map ( |ty| {
226
+ self . replace_bound_vars_with_fresh_vars (
227
+ expr. span ,
228
+ infer:: FnCall ,
229
+ inputs. rebind ( * ty) ,
230
+ )
231
+ } )
232
+ . collect ( ) ;
212
233
213
234
// We don't want to register any extra obligations, which should be
214
235
// implied by wf, but also because that would possibly result in
@@ -228,23 +249,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
228
249
rhs_ty : Ty < ' tcx > ,
229
250
can_satisfy : impl FnOnce ( Ty < ' tcx > , Ty < ' tcx > ) -> bool ,
230
251
) -> bool {
231
- let Some ( ( _, lhs_output_ty, num_lhs_inputs ) ) = self . extract_callable_info ( lhs_expr, lhs_ty)
252
+ let Some ( ( _, lhs_output_ty, lhs_inputs ) ) = self . extract_callable_info ( lhs_expr, lhs_ty)
232
253
else { return false ; } ;
233
- let Some ( ( _, rhs_output_ty, num_rhs_inputs ) ) = self . extract_callable_info ( rhs_expr, rhs_ty)
254
+ let Some ( ( _, rhs_output_ty, rhs_inputs ) ) = self . extract_callable_info ( rhs_expr, rhs_ty)
234
255
else { return false ; } ;
235
256
236
257
if can_satisfy ( lhs_output_ty, rhs_output_ty) {
237
258
let mut sugg = vec ! [ ] ;
238
259
let mut applicability = Applicability :: MachineApplicable ;
239
260
240
- for ( expr, num_inputs ) in [ ( lhs_expr, num_lhs_inputs ) , ( rhs_expr, num_rhs_inputs ) ] {
241
- let ( sugg_call, this_applicability) = match num_inputs {
261
+ for ( expr, inputs ) in [ ( lhs_expr, lhs_inputs ) , ( rhs_expr, rhs_inputs ) ] {
262
+ let ( sugg_call, this_applicability) = match inputs . len ( ) {
242
263
0 => ( "" . to_string ( ) , Applicability :: MachineApplicable ) ,
243
264
1 ..=4 => (
244
- ( 0 ..num_inputs) . map ( |_| "_" ) . collect :: < Vec < _ > > ( ) . join ( ", " ) ,
245
- Applicability :: MachineApplicable ,
265
+ inputs
266
+ . iter ( )
267
+ . map ( |ty| {
268
+ if ty. is_suggestable ( self . tcx , false ) {
269
+ format ! ( "/* {ty} */" )
270
+ } else {
271
+ "/* value */" . to_string ( )
272
+ }
273
+ } )
274
+ . collect :: < Vec < _ > > ( )
275
+ . join ( ", " ) ,
276
+ Applicability :: HasPlaceholders ,
246
277
) ,
247
- _ => ( "..." . to_string ( ) , Applicability :: HasPlaceholders ) ,
278
+ _ => ( "/* ... */ " . to_string ( ) , Applicability :: HasPlaceholders ) ,
248
279
} ;
249
280
250
281
applicability = applicability. max ( this_applicability) ;
0 commit comments