@@ -165,10 +165,10 @@ impl DiagnosticStyledString {
165165 DiagnosticStyledString ( vec ! [ ] )
166166 }
167167 pub fn push_normal < S : Into < String > > ( & mut self , t : S ) {
168- self . 0 . push ( StringPart :: normal ( t. into ( ) ) ) ;
168+ self . 0 . push ( StringPart :: normal ( t) ) ;
169169 }
170170 pub fn push_highlighted < S : Into < String > > ( & mut self , t : S ) {
171- self . 0 . push ( StringPart :: highlighted ( t. into ( ) ) ) ;
171+ self . 0 . push ( StringPart :: highlighted ( t) ) ;
172172 }
173173 pub fn push < S : Into < String > > ( & mut self , t : S , highlight : bool ) {
174174 if highlight {
@@ -178,11 +178,11 @@ impl DiagnosticStyledString {
178178 }
179179 }
180180 pub fn normal < S : Into < String > > ( t : S ) -> DiagnosticStyledString {
181- DiagnosticStyledString ( vec ! [ StringPart :: normal( t. into ( ) ) ] )
181+ DiagnosticStyledString ( vec ! [ StringPart :: normal( t) ] )
182182 }
183183
184184 pub fn highlighted < S : Into < String > > ( t : S ) -> DiagnosticStyledString {
185- DiagnosticStyledString ( vec ! [ StringPart :: highlighted( t. into ( ) ) ] )
185+ DiagnosticStyledString ( vec ! [ StringPart :: highlighted( t) ] )
186186 }
187187
188188 pub fn content ( & self ) -> String {
@@ -197,12 +197,12 @@ pub struct StringPart {
197197}
198198
199199impl StringPart {
200- fn normal ( content : String ) -> StringPart {
201- StringPart { content, style : Style :: NoStyle }
200+ pub fn normal < S : Into < String > > ( content : S ) -> StringPart {
201+ StringPart { content : content . into ( ) , style : Style :: NoStyle }
202202 }
203203
204- fn highlighted ( content : String ) -> StringPart {
205- StringPart { content, style : Style :: Highlight }
204+ pub fn highlighted < S : Into < String > > ( content : S ) -> StringPart {
205+ StringPart { content : content . into ( ) , style : Style :: Highlight }
206206 }
207207}
208208
@@ -391,13 +391,16 @@ impl Diagnostic {
391391 } else {
392392 ( 0 , found_label. len ( ) - expected_label. len ( ) )
393393 } ;
394- let mut msg: Vec < _ > =
395- vec ! [ ( format!( "{}{} `" , " " . repeat( expected_padding) , expected_label) , Style :: NoStyle ) ] ;
396- msg. extend ( expected. 0 . into_iter ( ) . map ( |p| ( p. content , p. style ) ) ) ;
397- msg. push ( ( format ! ( "`{expected_extra}\n " ) , Style :: NoStyle ) ) ;
398- msg. push ( ( format ! ( "{}{} `" , " " . repeat( found_padding) , found_label) , Style :: NoStyle ) ) ;
399- msg. extend ( found. 0 . into_iter ( ) . map ( |p| ( p. content , p. style ) ) ) ;
400- msg. push ( ( format ! ( "`{found_extra}" ) , Style :: NoStyle ) ) ;
394+ let mut msg = vec ! [ StringPart :: normal( format!(
395+ "{}{} `" ,
396+ " " . repeat( expected_padding) ,
397+ expected_label
398+ ) ) ] ;
399+ msg. extend ( expected. 0 . into_iter ( ) ) ;
400+ msg. push ( StringPart :: normal ( format ! ( "`{expected_extra}\n " ) ) ) ;
401+ msg. push ( StringPart :: normal ( format ! ( "{}{} `" , " " . repeat( found_padding) , found_label) ) ) ;
402+ msg. extend ( found. 0 . into_iter ( ) ) ;
403+ msg. push ( StringPart :: normal ( format ! ( "`{found_extra}" ) ) ) ;
401404
402405 // For now, just attach these as notes.
403406 self . highlighted_note ( msg) ;
@@ -406,9 +409,9 @@ impl Diagnostic {
406409
407410 pub fn note_trait_signature ( & mut self , name : Symbol , signature : String ) -> & mut Self {
408411 self . highlighted_note ( vec ! [
409- ( format!( "`{name}` from trait: `" ) , Style :: NoStyle ) ,
410- ( signature , Style :: Highlight ) ,
411- ( "`" . to_string ( ) , Style :: NoStyle ) ,
412+ StringPart :: normal ( format!( "`{name}` from trait: `" ) ) ,
413+ StringPart :: highlighted ( signature ) ,
414+ StringPart :: normal ( "`" ) ,
412415 ] ) ;
413416 self
414417 }
@@ -420,10 +423,7 @@ impl Diagnostic {
420423 self
421424 }
422425
423- fn highlighted_note < M : Into < SubdiagnosticMessage > > (
424- & mut self ,
425- msg : Vec < ( M , Style ) > ,
426- ) -> & mut Self {
426+ fn highlighted_note ( & mut self , msg : Vec < StringPart > ) -> & mut Self {
427427 self . sub_with_highlights ( Level :: Note , msg, MultiSpan :: new ( ) ) ;
428428 self
429429 }
@@ -492,7 +492,7 @@ impl Diagnostic {
492492 }
493493
494494 /// Add a help message attached to this diagnostic with a customizable highlighted message.
495- pub fn highlighted_help ( & mut self , msg : Vec < ( String , Style ) > ) -> & mut Self {
495+ pub fn highlighted_help ( & mut self , msg : Vec < StringPart > ) -> & mut Self {
496496 self . sub_with_highlights ( Level :: Help , msg, MultiSpan :: new ( ) ) ;
497497 self
498498 }
@@ -941,15 +941,10 @@ impl Diagnostic {
941941
942942 /// Convenience function for internal use, clients should use one of the
943943 /// public methods above.
944- fn sub_with_highlights < M : Into < SubdiagnosticMessage > > (
945- & mut self ,
946- level : Level ,
947- messages : Vec < ( M , Style ) > ,
948- span : MultiSpan ,
949- ) {
944+ fn sub_with_highlights ( & mut self , level : Level , messages : Vec < StringPart > , span : MultiSpan ) {
950945 let messages = messages
951946 . into_iter ( )
952- . map ( |m| ( self . subdiagnostic_message_to_diagnostic_message ( m. 0 ) , m. 1 ) )
947+ . map ( |m| ( self . subdiagnostic_message_to_diagnostic_message ( m. content ) , m. style ) )
953948 . collect ( ) ;
954949 let sub = SubDiagnostic { level, messages, span } ;
955950 self . children . push ( sub) ;
0 commit comments