@@ -4,7 +4,7 @@ use std::ptr;
44use rustc_ast:: { self as ast, Path } ;
55use rustc_ast_pretty:: pprust;
66use rustc_data_structures:: fx:: FxHashSet ;
7- use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder } ;
7+ use rustc_errors:: { struct_span_err, Applicability , DiagnosticBuilder , SuggestionStyle } ;
88use rustc_feature:: BUILTIN_ATTRIBUTES ;
99use rustc_hir:: def:: Namespace :: { self , * } ;
1010use rustc_hir:: def:: { self , CtorKind , CtorOf , DefKind , NonMacroAttrKind } ;
@@ -211,10 +211,14 @@ impl<'a> Resolver<'a> {
211211 ) ;
212212 err. span_label ( span, format ! ( "not a member of trait `{}`" , trait_) ) ;
213213 if let Some ( candidate) = candidate {
214- err. span_suggestion (
214+ let sugg = candidate. to_ident_string ( ) ;
215+ err. span_suggestion_hide_inline (
215216 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,
218222 Applicability :: MaybeIncorrect ,
219223 ) ;
220224 }
@@ -231,10 +235,11 @@ impl<'a> Resolver<'a> {
231235 ) ;
232236 err. span_label ( span, format ! ( "not a member of trait `{}`" , trait_) ) ;
233237 if let Some ( candidate) = candidate {
234- err. span_suggestion (
238+ let sugg = candidate. to_ident_string ( ) ;
239+ err. span_suggestion_hide_inline (
235240 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 ,
238243 Applicability :: MaybeIncorrect ,
239244 ) ;
240245 }
@@ -251,10 +256,14 @@ impl<'a> Resolver<'a> {
251256 ) ;
252257 err. span_label ( span, format ! ( "not a member of trait `{}`" , trait_) ) ;
253258 if let Some ( candidate) = candidate {
254- err. span_suggestion (
259+ let sugg = candidate. to_ident_string ( ) ;
260+ err. span_suggestion_hide_inline (
255261 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,
258267 Applicability :: MaybeIncorrect ,
259268 ) ;
260269 }
@@ -339,9 +348,9 @@ impl<'a> Resolver<'a> {
339348 // A reachable label with a similar name exists.
340349 Some ( ( ident, true ) ) => {
341350 err. span_label ( ident. span , "a label with a similar name is reachable" ) ;
342- err. span_suggestion (
351+ err. span_suggestion_hide_inline (
343352 span,
344- "try using similarly named label" ,
353+ & format ! ( "did you mean `{}`? (a similarly named label)" , ident ) ,
345354 ident. name . to_string ( ) ,
346355 Applicability :: MaybeIncorrect ,
347356 ) ;
@@ -583,9 +592,9 @@ impl<'a> Resolver<'a> {
583592 // A reachable label with a similar name exists.
584593 Some ( ( ident, true ) ) => {
585594 err. span_label ( ident. span , "a label with a similar name is reachable" ) ;
586- err. span_suggestion (
595+ err. span_suggestion_hide_inline (
587596 span,
588- "try using similarly named label" ,
597+ & format ! ( "did you mean `{}`? (a similarly named label)" , ident ) ,
589598 ident. name . to_string ( ) ,
590599 Applicability :: MaybeIncorrect ,
591600 ) ;
@@ -1157,21 +1166,26 @@ impl<'a> Resolver<'a> {
11571166 ) ,
11581167 ) ;
11591168 }
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 ,
11651181 ) ,
1166- SuggestionTarget :: SingleItem => {
1167- format ! ( "maybe you meant this {}" , suggestion. res. descr( ) )
1168- }
11691182 } ;
1170- err. span_suggestion (
1183+ err. span_suggestion_with_style (
11711184 span,
11721185 & msg,
11731186 suggestion. candidate . to_string ( ) ,
11741187 Applicability :: MaybeIncorrect ,
1188+ style,
11751189 ) ;
11761190 true
11771191 }
0 commit comments