@@ -201,33 +201,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
201
201
}
202
202
}
203
203
204
- // If we still couldn't find any associated type, just list them all.
205
-
206
- if all_candidate_names. is_empty ( ) {
207
- err. help ( format ! (
208
- "`{ty_param_name}` has no associated type, try removing `{assoc_name}`"
209
- ) ) ;
210
- return err. emit ( ) ;
211
- }
212
-
213
- let msg = if all_candidate_names. len ( ) > 1 {
214
- format ! ( "`{ty_param_name}` has the following associated types" )
215
- } else {
216
- format ! ( "`{ty_param_name}` has the following associated type" )
217
- } ;
204
+ // If we still couldn't find any associated type, and only one associated type exists,
205
+ // suggests using it.
206
+
207
+ if all_candidate_names. len ( ) == 1 {
208
+ // this should still compile, except on `#![feature(associated_type_defaults)]`
209
+ // where it could suggests `type A = Self::A`, thus recursing infinitely
210
+ let applicability = if self . tcx ( ) . features ( ) . associated_type_defaults {
211
+ Applicability :: Unspecified
212
+ } else {
213
+ Applicability :: MaybeIncorrect
214
+ } ;
218
215
219
- let applicability = if self . tcx ( ) . features ( ) . associated_type_defaults {
220
- Applicability :: Unspecified // `type A = Self::B` would suggest `type A = Self::A`
216
+ err. span_suggestion (
217
+ assoc_name. span ,
218
+ format ! ( "`{ty_param_name}` has the following associated type" ) ,
219
+ all_candidate_names. first ( ) . unwrap ( ) . to_string ( ) ,
220
+ applicability,
221
+ ) ;
221
222
} else {
222
- Applicability :: MaybeIncorrect
223
- } ;
224
-
225
- err. span_suggestions (
226
- assoc_name. span ,
227
- msg,
228
- all_candidate_names. iter ( ) . map ( |symbol| symbol. to_string ( ) ) ,
229
- applicability,
230
- ) ;
223
+ err. span_label ( assoc_name. span , format ! ( "associated type `{assoc_name}` not found" ) ) ;
224
+ }
231
225
232
226
err. emit ( )
233
227
}
0 commit comments