@@ -133,52 +133,50 @@ crate fn placeholder_type_error(
133
133
placeholder_types : Vec < Span > ,
134
134
suggest : bool ,
135
135
) {
136
- if !placeholder_types. is_empty ( ) {
137
- let possible_names = [ "T" , "K" , "L" , "A" , "B" , "C" ] ;
138
- let used_names = generics
139
- . iter ( )
140
- . filter_map ( |p| match p. name {
141
- hir:: ParamName :: Plain ( ident) => Some ( ident. name ) ,
142
- _ => None ,
143
- } )
144
- . collect :: < Vec < _ > > ( ) ;
136
+ if placeholder_types. is_empty ( ) {
137
+ return ;
138
+ }
139
+ let possible_names = [ "T" , "K" , "L" , "A" , "B" , "C" ] ;
140
+ let used_names = generics
141
+ . iter ( )
142
+ . filter_map ( |p| match p. name {
143
+ hir:: ParamName :: Plain ( ident) => Some ( ident. name ) ,
144
+ _ => None ,
145
+ } )
146
+ . collect :: < Vec < _ > > ( ) ;
145
147
146
- let mut type_name = "ParamName" ;
147
- for name in & possible_names {
148
- if !used_names. contains ( & Symbol :: intern ( name) ) {
149
- type_name = name;
150
- break ;
151
- }
152
- }
148
+ let type_name = possible_names
149
+ . iter ( )
150
+ . find ( |n| !used_names. contains ( & Symbol :: intern ( n) ) )
151
+ . unwrap_or ( & "ParamName" ) ;
153
152
154
- let mut sugg: Vec < _ > =
155
- placeholder_types. iter ( ) . map ( |sp| ( * sp, type_name. to_string ( ) ) ) . collect ( ) ;
156
- if generics. is_empty ( ) {
157
- sugg. push ( ( ident_span. shrink_to_hi ( ) , format ! ( "<{}>" , type_name) ) ) ;
158
- } else {
159
- sugg. push ( (
160
- generics. iter ( ) . last ( ) . unwrap ( ) . span . shrink_to_hi ( ) ,
161
- format ! ( ", {}" , type_name) ,
162
- ) ) ;
163
- }
164
- let mut err = struct_span_err ! (
165
- tcx. sess,
166
- placeholder_types. clone( ) ,
167
- E0121 ,
168
- "the type placeholder `_` is not allowed within types on item signatures" ,
153
+ let mut sugg: Vec < _ > =
154
+ placeholder_types. iter ( ) . map ( |sp| ( * sp, type_name. to_string ( ) ) ) . collect ( ) ;
155
+ if generics. is_empty ( ) {
156
+ sugg. push ( ( ident_span. shrink_to_hi ( ) , format ! ( "<{}>" , type_name) ) ) ;
157
+ } else {
158
+ sugg. push ( (
159
+ generics. iter ( ) . last ( ) . unwrap ( ) . span . shrink_to_hi ( ) ,
160
+ format ! ( ", {}" , type_name) ,
161
+ ) ) ;
162
+ }
163
+ let mut err = struct_span_err ! (
164
+ tcx. sess,
165
+ placeholder_types. clone( ) ,
166
+ E0121 ,
167
+ "the type placeholder `_` is not allowed within types on item signatures" ,
168
+ ) ;
169
+ for span in & placeholder_types {
170
+ err. span_label ( * span, "not allowed in type signatures" ) ;
171
+ }
172
+ if suggest {
173
+ err. multipart_suggestion (
174
+ "use type parameters instead" ,
175
+ sugg,
176
+ Applicability :: HasPlaceholders ,
169
177
) ;
170
- for span in & placeholder_types {
171
- err. span_label ( * span, "not allowed in type signatures" ) ;
172
- }
173
- if suggest {
174
- err. multipart_suggestion (
175
- "use type parameters instead" ,
176
- sugg,
177
- Applicability :: HasPlaceholders ,
178
- ) ;
179
- }
180
- err. emit ( ) ;
181
178
}
179
+ err. emit ( ) ;
182
180
}
183
181
184
182
fn reject_placeholder_type_signatures_in_item ( tcx : TyCtxt < ' tcx > , item : & ' tcx hir:: Item < ' tcx > ) {
0 commit comments