@@ -304,6 +304,24 @@ impl Diagnostic {
304304 msg : & str ,
305305 suggestion : String ,
306306 applicability : Applicability ,
307+ ) -> & mut Self {
308+ self . span_suggestion_with_style (
309+ sp,
310+ msg,
311+ suggestion,
312+ applicability,
313+ SuggestionStyle :: ShowCode ,
314+ ) ;
315+ self
316+ }
317+
318+ pub fn span_suggestion_with_style (
319+ & mut self ,
320+ sp : Span ,
321+ msg : & str ,
322+ suggestion : String ,
323+ applicability : Applicability ,
324+ style : SuggestionStyle ,
307325 ) -> & mut Self {
308326 self . suggestions . push ( CodeSuggestion {
309327 substitutions : vec ! [ Substitution {
@@ -313,7 +331,7 @@ impl Diagnostic {
313331 } ] ,
314332 } ] ,
315333 msg : msg. to_owned ( ) ,
316- style : SuggestionStyle :: ShowCode ,
334+ style,
317335 applicability,
318336 } ) ;
319337 self
@@ -326,17 +344,13 @@ impl Diagnostic {
326344 suggestion : String ,
327345 applicability : Applicability ,
328346 ) -> & mut Self {
329- self . suggestions . push ( CodeSuggestion {
330- substitutions : vec ! [ Substitution {
331- parts: vec![ SubstitutionPart {
332- snippet: suggestion,
333- span: sp,
334- } ] ,
335- } ] ,
336- msg : msg. to_owned ( ) ,
337- style : SuggestionStyle :: ShowAlways ,
347+ self . span_suggestion_with_style (
348+ sp,
349+ msg,
350+ suggestion,
338351 applicability,
339- } ) ;
352+ SuggestionStyle :: ShowAlways ,
353+ ) ;
340354 self
341355 }
342356
@@ -369,17 +383,13 @@ impl Diagnostic {
369383 pub fn span_suggestion_short (
370384 & mut self , sp : Span , msg : & str , suggestion : String , applicability : Applicability
371385 ) -> & mut Self {
372- self . suggestions . push ( CodeSuggestion {
373- substitutions : vec ! [ Substitution {
374- parts: vec![ SubstitutionPart {
375- snippet: suggestion,
376- span: sp,
377- } ] ,
378- } ] ,
379- msg : msg. to_owned ( ) ,
380- style : SuggestionStyle :: HideCodeInline ,
386+ self . span_suggestion_with_style (
387+ sp,
388+ msg,
389+ suggestion,
381390 applicability,
382- } ) ;
391+ SuggestionStyle :: HideCodeInline ,
392+ ) ;
383393 self
384394 }
385395
@@ -392,17 +402,13 @@ impl Diagnostic {
392402 pub fn span_suggestion_hidden (
393403 & mut self , sp : Span , msg : & str , suggestion : String , applicability : Applicability
394404 ) -> & mut Self {
395- self . suggestions . push ( CodeSuggestion {
396- substitutions : vec ! [ Substitution {
397- parts: vec![ SubstitutionPart {
398- snippet: suggestion,
399- span: sp,
400- } ] ,
401- } ] ,
402- msg : msg. to_owned ( ) ,
403- style : SuggestionStyle :: HideCodeAlways ,
405+ self . span_suggestion_with_style (
406+ sp,
407+ msg,
408+ suggestion,
404409 applicability,
405- } ) ;
410+ SuggestionStyle :: HideCodeAlways ,
411+ ) ;
406412 self
407413 }
408414
@@ -413,17 +419,13 @@ impl Diagnostic {
413419 pub fn tool_only_span_suggestion (
414420 & mut self , sp : Span , msg : & str , suggestion : String , applicability : Applicability
415421 ) -> & mut Self {
416- self . suggestions . push ( CodeSuggestion {
417- substitutions : vec ! [ Substitution {
418- parts: vec![ SubstitutionPart {
419- snippet: suggestion,
420- span: sp,
421- } ] ,
422- } ] ,
423- msg : msg. to_owned ( ) ,
424- style : SuggestionStyle :: CompletelyHidden ,
422+ self . span_suggestion_with_style (
423+ sp,
424+ msg,
425+ suggestion,
425426 applicability,
426- } ) ;
427+ SuggestionStyle :: CompletelyHidden ,
428+ ) ;
427429 self
428430 }
429431
0 commit comments