@@ -76,16 +76,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7676 found : Ty < ' tcx > ,
7777 can_satisfy : impl FnOnce ( Ty < ' tcx > ) -> bool ,
7878 ) -> 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)
8080 else { return false ; } ;
8181 if can_satisfy ( output) {
82- let ( sugg_call, mut applicability) = match num_inputs {
82+ let ( sugg_call, mut applicability) = match inputs . len ( ) {
8383 0 => ( "" . to_string ( ) , Applicability :: MachineApplicable ) ,
8484 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 ,
8797 ) ,
88- _ => ( "..." . to_string ( ) , Applicability :: HasPlaceholders ) ,
98+ _ => ( "/* ... */ " . to_string ( ) , Applicability :: HasPlaceholders ) ,
8999 } ;
90100
91101 let msg = match def_id_or_name {
@@ -137,19 +147,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137147 & self ,
138148 expr : & Expr < ' _ > ,
139149 found : Ty < ' tcx > ,
140- ) -> Option < ( DefIdOrName , Ty < ' tcx > , usize ) > {
150+ ) -> Option < ( DefIdOrName , Ty < ' tcx > , Vec < Ty < ' tcx > > ) > {
141151 // Autoderef is useful here because sometimes we box callables, etc.
142152 let Some ( ( def_id_or_name, output, inputs) ) = self . autoderef ( expr. span , found) . silence_errors ( ) . find_map ( |( found, _) | {
143153 match * found. kind ( ) {
144154 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 ( ) ) ) ,
146156 ty:: FnDef ( def_id, _) => {
147157 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 ( ) ) )
149159 }
150160 ty:: Closure ( def_id, substs) => {
151161 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 .. ] ) ) )
153163 }
154164 ty:: Opaque ( def_id, substs) => {
155165 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> {
161171 Some ( (
162172 DefIdOrName :: DefId ( def_id) ,
163173 pred. kind ( ) . rebind ( proj. term . ty ( ) . unwrap ( ) ) ,
164- args. len ( ) ,
174+ pred . kind ( ) . rebind ( args. as_slice ( ) ) ,
165175 ) )
166176 } else {
167177 None
@@ -178,7 +188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
178188 Some ( (
179189 DefIdOrName :: Name ( "trait object" ) ,
180190 pred. rebind ( proj. term . ty ( ) . unwrap ( ) ) ,
181- args. len ( ) ,
191+ pred . rebind ( args. as_slice ( ) ) ,
182192 ) )
183193 } else {
184194 None
@@ -197,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
197207 Some ( (
198208 DefIdOrName :: DefId ( def_id) ,
199209 pred. kind ( ) . rebind ( proj. term . ty ( ) . unwrap ( ) ) ,
200- args. len ( ) ,
210+ pred . kind ( ) . rebind ( args. as_slice ( ) ) ,
201211 ) )
202212 } else {
203213 None
@@ -209,6 +219,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
209219 } ) else { return None ; } ;
210220
211221 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 ( ) ;
212233
213234 // We don't want to register any extra obligations, which should be
214235 // implied by wf, but also because that would possibly result in
@@ -228,23 +249,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
228249 rhs_ty : Ty < ' tcx > ,
229250 can_satisfy : impl FnOnce ( Ty < ' tcx > , Ty < ' tcx > ) -> bool ,
230251 ) -> 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)
232253 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)
234255 else { return false ; } ;
235256
236257 if can_satisfy ( lhs_output_ty, rhs_output_ty) {
237258 let mut sugg = vec ! [ ] ;
238259 let mut applicability = Applicability :: MachineApplicable ;
239260
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 ( ) {
242263 0 => ( "" . to_string ( ) , Applicability :: MachineApplicable ) ,
243264 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 ,
246277 ) ,
247- _ => ( "..." . to_string ( ) , Applicability :: HasPlaceholders ) ,
278+ _ => ( "/* ... */ " . to_string ( ) , Applicability :: HasPlaceholders ) ,
248279 } ;
249280
250281 applicability = applicability. max ( this_applicability) ;
0 commit comments