@@ -165,10 +165,10 @@ impl DiagnosticStyledString {
165
165
DiagnosticStyledString ( vec ! [ ] )
166
166
}
167
167
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) ) ;
169
169
}
170
170
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) ) ;
172
172
}
173
173
pub fn push < S : Into < String > > ( & mut self , t : S , highlight : bool ) {
174
174
if highlight {
@@ -178,11 +178,11 @@ impl DiagnosticStyledString {
178
178
}
179
179
}
180
180
pub fn normal < S : Into < String > > ( t : S ) -> DiagnosticStyledString {
181
- DiagnosticStyledString ( vec ! [ StringPart :: normal( t. into ( ) ) ] )
181
+ DiagnosticStyledString ( vec ! [ StringPart :: normal( t) ] )
182
182
}
183
183
184
184
pub fn highlighted < S : Into < String > > ( t : S ) -> DiagnosticStyledString {
185
- DiagnosticStyledString ( vec ! [ StringPart :: highlighted( t. into ( ) ) ] )
185
+ DiagnosticStyledString ( vec ! [ StringPart :: highlighted( t) ] )
186
186
}
187
187
188
188
pub fn content ( & self ) -> String {
@@ -197,12 +197,12 @@ pub struct StringPart {
197
197
}
198
198
199
199
impl 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 }
202
202
}
203
203
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 }
206
206
}
207
207
}
208
208
@@ -391,13 +391,16 @@ impl Diagnostic {
391
391
} else {
392
392
( 0 , found_label. len ( ) - expected_label. len ( ) )
393
393
} ;
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}" ) ) ) ;
401
404
402
405
// For now, just attach these as notes.
403
406
self . highlighted_note ( msg) ;
@@ -406,9 +409,9 @@ impl Diagnostic {
406
409
407
410
pub fn note_trait_signature ( & mut self , name : Symbol , signature : String ) -> & mut Self {
408
411
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 ( "`" ) ,
412
415
] ) ;
413
416
self
414
417
}
@@ -420,10 +423,7 @@ impl Diagnostic {
420
423
self
421
424
}
422
425
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 {
427
427
self . sub_with_highlights ( Level :: Note , msg, MultiSpan :: new ( ) ) ;
428
428
self
429
429
}
@@ -492,7 +492,7 @@ impl Diagnostic {
492
492
}
493
493
494
494
/// 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 {
496
496
self . sub_with_highlights ( Level :: Help , msg, MultiSpan :: new ( ) ) ;
497
497
self
498
498
}
@@ -941,15 +941,10 @@ impl Diagnostic {
941
941
942
942
/// Convenience function for internal use, clients should use one of the
943
943
/// 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 ) {
950
945
let messages = messages
951
946
. 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 ) )
953
948
. collect ( ) ;
954
949
let sub = SubDiagnostic { level, messages, span } ;
955
950
self . children . push ( sub) ;
0 commit comments