@@ -102,6 +102,7 @@ pub struct ItemCtxt<'tcx> {
102102
103103///////////////////////////////////////////////////////////////////////////
104104
105+ #[ derive( Default ) ]
105106crate struct PlaceholderHirTyCollector ( crate Vec < Span > ) ;
106107
107108impl < ' v > Visitor < ' v > for PlaceholderHirTyCollector {
@@ -116,16 +117,13 @@ impl<'v> Visitor<'v> for PlaceholderHirTyCollector {
116117 }
117118}
118119
119- impl PlaceholderHirTyCollector {
120- pub fn new ( ) -> PlaceholderHirTyCollector {
121- PlaceholderHirTyCollector ( vec ! [ ] )
122- }
123- }
124-
125120struct CollectItemTypesVisitor < ' tcx > {
126121 tcx : TyCtxt < ' tcx > ,
127122}
128123
124+ /// If there are any placeholder types (`_`), emit an error explaining that this is not allowed
125+ /// and suggest adding type parameters in the appropriate place, taking into consideration any and
126+ /// all already existing generic type parameters to avoid suggesting a name that is already in use.
129127crate fn placeholder_type_error (
130128 tcx : TyCtxt < ' tcx > ,
131129 ident_span : Span ,
@@ -136,6 +134,7 @@ crate fn placeholder_type_error(
136134 if placeholder_types. is_empty ( ) {
137135 return ;
138136 }
137+ // This is the whitelist of possible parameter names that we might suggest.
139138 let possible_names = [ "T" , "K" , "L" , "A" , "B" , "C" ] ;
140139 let used_names = generics
141140 . iter ( )
@@ -181,7 +180,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
181180 _ => return ,
182181 } ;
183182
184- let mut visitor = PlaceholderHirTyCollector :: new ( ) ;
183+ let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
185184 visitor. visit_item ( item) ;
186185
187186 placeholder_type_error ( tcx, item. ident . span , generics, visitor. 0 , suggest) ;
@@ -1796,15 +1795,7 @@ fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool {
17961795 match & ty. kind {
17971796 hir:: TyKind :: Infer => true ,
17981797 hir:: TyKind :: Slice ( ty) | hir:: TyKind :: Array ( ty, _) => is_suggestable_infer_ty ( ty) ,
1799- hir:: TyKind :: Tup ( tys)
1800- if !tys. is_empty ( )
1801- && tys. iter ( ) . any ( |ty| match ty. kind {
1802- hir:: TyKind :: Infer => true ,
1803- _ => false ,
1804- } ) =>
1805- {
1806- true
1807- }
1798+ hir:: TyKind :: Tup ( tys) => tys. iter ( ) . any ( |ty| is_suggestable_infer_ty ( ty) ) ,
18081799 _ => false ,
18091800 }
18101801}
@@ -1838,7 +1829,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
18381829 match get_infer_ret_ty ( & sig. decl . output ) {
18391830 Some ( ty) => {
18401831 let fn_sig = tcx. typeck_tables_of ( def_id) . liberated_fn_sigs ( ) [ hir_id] ;
1841- let mut visitor = PlaceholderHirTyCollector :: new ( ) ;
1832+ let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
18421833 visitor. visit_ty ( ty) ;
18431834 let mut diag = bad_placeholder_type ( tcx, visitor. 0 ) ;
18441835 let ret_ty = fn_sig. output ( ) ;
0 commit comments