@@ -4,7 +4,7 @@ use std::ptr;
4
4
use rustc_ast:: { self as ast, Path } ;
5
5
use rustc_ast_pretty:: pprust;
6
6
use rustc_data_structures:: fx:: FxHashSet ;
7
- use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
7
+ use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder , SuggestionStyle } ;
8
8
use rustc_feature:: BUILTIN_ATTRIBUTES ;
9
9
use rustc_hir:: def:: Namespace :: { self , * } ;
10
10
use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind , NonMacroAttrKind } ;
@@ -211,10 +211,14 @@ impl<'a> Resolver<'a> {
211
211
) ;
212
212
err. span_label ( span, format ! ( "not a member of trait `{}`" , trait_) ) ;
213
213
if let Some ( candidate) = candidate {
214
- err. span_suggestion (
214
+ let sugg = candidate. to_ident_string ( ) ;
215
+ err. span_suggestion_hide_inline (
215
216
method. span ,
216
- "there is an associated function with a similar name" ,
217
- candidate. to_ident_string ( ) ,
217
+ & format ! (
218
+ "did you mean `{}`? (a similarly named associated function)" ,
219
+ & sugg
220
+ ) ,
221
+ sugg,
218
222
Applicability :: MaybeIncorrect ,
219
223
) ;
220
224
}
@@ -231,10 +235,11 @@ impl<'a> Resolver<'a> {
231
235
) ;
232
236
err. span_label ( span, format ! ( "not a member of trait `{}`" , trait_) ) ;
233
237
if let Some ( candidate) = candidate {
234
- err. span_suggestion (
238
+ let sugg = candidate. to_ident_string ( ) ;
239
+ err. span_suggestion_hide_inline (
235
240
type_. span ,
236
- "there is an associated type with a similar name" ,
237
- candidate . to_ident_string ( ) ,
241
+ & format ! ( "did you mean `{}`? (a similarly named associated type)" , & sugg ) ,
242
+ sugg ,
238
243
Applicability :: MaybeIncorrect ,
239
244
) ;
240
245
}
@@ -251,10 +256,14 @@ impl<'a> Resolver<'a> {
251
256
) ;
252
257
err. span_label ( span, format ! ( "not a member of trait `{}`" , trait_) ) ;
253
258
if let Some ( candidate) = candidate {
254
- err. span_suggestion (
259
+ let sugg = candidate. to_ident_string ( ) ;
260
+ err. span_suggestion_hide_inline (
255
261
const_. span ,
256
- "there is an associated constant with a similar name" ,
257
- candidate. to_ident_string ( ) ,
262
+ & format ! (
263
+ "did you mean `{}`? (a similarly named associated constant)" ,
264
+ & sugg
265
+ ) ,
266
+ sugg,
258
267
Applicability :: MaybeIncorrect ,
259
268
) ;
260
269
}
@@ -339,9 +348,9 @@ impl<'a> Resolver<'a> {
339
348
// A reachable label with a similar name exists.
340
349
Some ( ( ident, true ) ) => {
341
350
err. span_label ( ident. span , "a label with a similar name is reachable" ) ;
342
- err. span_suggestion (
351
+ err. span_suggestion_hide_inline (
343
352
span,
344
- "try using similarly named label" ,
353
+ & format ! ( "did you mean `{}`? (a similarly named label)" , ident ) ,
345
354
ident. name . to_string ( ) ,
346
355
Applicability :: MaybeIncorrect ,
347
356
) ;
@@ -583,9 +592,9 @@ impl<'a> Resolver<'a> {
583
592
// A reachable label with a similar name exists.
584
593
Some ( ( ident, true ) ) => {
585
594
err. span_label ( ident. span , "a label with a similar name is reachable" ) ;
586
- err. span_suggestion (
595
+ err. span_suggestion_hide_inline (
587
596
span,
588
- "try using similarly named label" ,
597
+ & format ! ( "did you mean `{}`? (a similarly named label)" , ident ) ,
589
598
ident. name . to_string ( ) ,
590
599
Applicability :: MaybeIncorrect ,
591
600
) ;
@@ -1157,21 +1166,26 @@ impl<'a> Resolver<'a> {
1157
1166
) ,
1158
1167
) ;
1159
1168
}
1160
- let msg = match suggestion. target {
1161
- SuggestionTarget :: SimilarlyNamed => format ! (
1162
- "{} {} with a similar name exists" ,
1163
- suggestion. res. article( ) ,
1164
- suggestion. res. descr( )
1169
+ let ( msg, style) = match suggestion. target {
1170
+ SuggestionTarget :: SimilarlyNamed => (
1171
+ format ! (
1172
+ "did you mean `{}`? (a similarly named {})" ,
1173
+ suggestion. candidate,
1174
+ suggestion. res. descr( )
1175
+ ) ,
1176
+ SuggestionStyle :: HideCodeInline ,
1177
+ ) ,
1178
+ SuggestionTarget :: SingleItem => (
1179
+ format ! ( "maybe you meant this {}" , suggestion. res. descr( ) ) ,
1180
+ SuggestionStyle :: ShowCode ,
1165
1181
) ,
1166
- SuggestionTarget :: SingleItem => {
1167
- format ! ( "maybe you meant this {}" , suggestion. res. descr( ) )
1168
- }
1169
1182
} ;
1170
- err. span_suggestion (
1183
+ err. span_suggestion_with_style (
1171
1184
span,
1172
1185
& msg,
1173
1186
suggestion. candidate . to_string ( ) ,
1174
1187
Applicability :: MaybeIncorrect ,
1188
+ style,
1175
1189
) ;
1176
1190
true
1177
1191
}
0 commit comments