@@ -262,31 +262,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
262
262
method_name. name
263
263
) ) ;
264
264
265
- let self_ty_name = self
265
+ let mut self_ty_name = self
266
266
. sess ( )
267
267
. source_map ( )
268
268
. span_to_snippet ( self_ty_span)
269
269
. unwrap_or_else ( |_| self_ty. to_string ( ) ) ;
270
270
271
- let self_ty_generics_count = match self_ty. kind ( ) {
272
- // Get the number of generics the self type has (if an Adt) unless we can determine that
273
- // the user has written the self type with generics already which we (naively) do by looking
274
- // for a "<" in `self_ty_name`.
275
- Adt ( def, _) if !self_ty_name. contains ( '<' ) => self . tcx . generics_of ( def. did ) . count ( ) ,
276
- _ => 0 ,
277
- } ;
278
- let self_ty_generics = if self_ty_generics_count > 0 {
279
- format ! ( "<{}>" , vec![ "_" ; self_ty_generics_count] . join( ", " ) )
280
- } else {
281
- String :: new ( )
282
- } ;
271
+ // Get the number of generics the self type has (if an Adt) unless we can determine that
272
+ // the user has written the self type with generics already which we (naively) do by looking
273
+ // for a "<" in `self_ty_name`.
274
+ if !self_ty_name. contains ( '<' ) {
275
+ if let Adt ( def, _) = self_ty. kind ( ) {
276
+ let generics = self . tcx . generics_of ( def. did ) ;
277
+ if !generics. params . is_empty ( ) {
278
+ let counts = generics. own_counts ( ) ;
279
+ self_ty_name += & format ! (
280
+ "<{}>" ,
281
+ std:: iter:: repeat( "'_" )
282
+ . take( counts. lifetimes)
283
+ . chain( std:: iter:: repeat( "_" ) . take( counts. types + counts. consts) )
284
+ . collect:: <Vec <_>>( )
285
+ . join( ", " )
286
+ ) ;
287
+ }
288
+ }
289
+ }
283
290
lint. span_suggestion (
284
291
span,
285
292
"disambiguate the associated function" ,
286
- format ! (
287
- "<{}{} as {}>::{}" ,
288
- self_ty_name, self_ty_generics, trait_name, method_name. name,
289
- ) ,
293
+ format ! ( "<{} as {}>::{}" , self_ty_name, trait_name, method_name. name, ) ,
290
294
Applicability :: MachineApplicable ,
291
295
) ;
292
296
0 commit comments