@@ -192,6 +192,8 @@ pub trait Emitter {
192
192
true
193
193
}
194
194
195
+ fn source_map ( & self ) -> Option < & Lrc < SourceMapperDyn > > ;
196
+
195
197
/// Formats the substitutions of the primary_span
196
198
///
197
199
/// The are a lot of conditions to this method, but in short:
@@ -204,7 +206,7 @@ pub trait Emitter {
204
206
/// we return the original `primary_span` and the original suggestions.
205
207
fn primary_span_formatted < ' a > (
206
208
& mut self ,
207
- db : & ' a Diagnostic
209
+ db : & ' a Diagnostic ,
208
210
) -> ( MultiSpan , & ' a [ CodeSuggestion ] ) {
209
211
let mut primary_span = db. span . clone ( ) ;
210
212
if let Some ( ( sugg, rest) ) = db. suggestions . split_first ( ) {
@@ -234,7 +236,20 @@ pub trait Emitter {
234
236
format ! ( "help: {}" , sugg. msg)
235
237
} else {
236
238
// Show the default suggestion text with the substitution
237
- format ! ( "help: {}: `{}`" , sugg. msg, substitution)
239
+ format ! (
240
+ "help: {}{}: `{}`" ,
241
+ sugg. msg,
242
+ if self . source_map( ) . as_ref( ) . map( |sm| substitution. to_lowercase( ) == sm
243
+ . span_to_snippet( sugg. substitutions[ 0 ] . parts[ 0 ] . span)
244
+ . unwrap( )
245
+ . to_lowercase( ) ) . unwrap_or( false )
246
+ {
247
+ " (notice the capitalization)"
248
+ } else {
249
+ ""
250
+ } ,
251
+ substitution,
252
+ )
238
253
} ;
239
254
primary_span. push_span_label ( sugg. substitutions [ 0 ] . parts [ 0 ] . span , msg) ;
240
255
@@ -382,6 +397,10 @@ pub trait Emitter {
382
397
}
383
398
384
399
impl Emitter for EmitterWriter {
400
+ fn source_map ( & self ) -> Option < & Lrc < SourceMapperDyn > > {
401
+ self . sm . as_ref ( )
402
+ }
403
+
385
404
fn emit_diagnostic ( & mut self , db : & Diagnostic ) {
386
405
let mut children = db. children . clone ( ) ;
387
406
let ( mut primary_span, suggestions) = self . primary_span_formatted ( & db) ;
@@ -1461,7 +1480,9 @@ impl EmitterWriter {
1461
1480
let suggestions = suggestion. splice_lines ( & * * sm) ;
1462
1481
1463
1482
let mut row_num = 2 ;
1464
- for & ( ref complete, ref parts) in suggestions. iter ( ) . take ( MAX_SUGGESTIONS ) {
1483
+ let mut notice_capitalization = false ;
1484
+ for ( complete, parts, only_capitalization) in suggestions. iter ( ) . take ( MAX_SUGGESTIONS ) {
1485
+ notice_capitalization |= only_capitalization;
1465
1486
// Only show underline if the suggestion spans a single line and doesn't cover the
1466
1487
// entirety of the code output. If you have multiple replacements in the same line
1467
1488
// of code, show the underline.
@@ -1552,7 +1573,10 @@ impl EmitterWriter {
1552
1573
}
1553
1574
if suggestions. len ( ) > MAX_SUGGESTIONS {
1554
1575
let msg = format ! ( "and {} other candidates" , suggestions. len( ) - MAX_SUGGESTIONS ) ;
1555
- buffer. puts ( row_num, 0 , & msg, Style :: NoStyle ) ;
1576
+ buffer. puts ( row_num, max_line_num_len + 3 , & msg, Style :: NoStyle ) ;
1577
+ } else if notice_capitalization {
1578
+ let msg = "notice the capitalization difference" ;
1579
+ buffer. puts ( row_num, max_line_num_len + 3 , & msg, Style :: NoStyle ) ;
1556
1580
}
1557
1581
emit_to_destination ( & buffer. render ( ) , level, & mut self . dst , self . short_message ) ?;
1558
1582
Ok ( ( ) )
0 commit comments