@@ -1408,49 +1408,58 @@ impl EmitterWriter {
1408
1408
if !sm. ensure_source_file_source_present ( annotated_file. file . clone ( ) ) {
1409
1409
if !self . short_message {
1410
1410
// We'll just print an unannotated message.
1411
- for ( annotation_id, line) in annotated_file. lines . into_iter ( ) . enumerate ( ) {
1411
+ for ( annotation_id, line) in annotated_file. lines . iter ( ) . enumerate ( ) {
1412
1412
let mut annotations = line. annotations . clone ( ) ;
1413
1413
annotations. sort_by_key ( |a| Reverse ( a. start_col ) ) ;
1414
1414
let mut line_idx = buffer. num_lines ( ) ;
1415
- buffer. append (
1416
- line_idx,
1417
- & format ! (
1418
- "{}:{}:{}" ,
1419
- sm. filename_for_diagnostics( & annotated_file. file. name) ,
1420
- sm. doctest_offset_line( & annotated_file. file. name, line. line_index) ,
1421
- annotations[ 0 ] . start_col + 1 ,
1422
- ) ,
1423
- Style :: LineAndColumn ,
1424
- ) ;
1425
- if annotation_id == 0 {
1426
- buffer. prepend ( line_idx, "--> " , Style :: LineNumber ) ;
1415
+
1416
+ let labels: Vec < _ > = annotations
1417
+ . iter ( )
1418
+ . filter_map ( |a| Some ( ( a. label . as_ref ( ) ?, a. is_primary ) ) )
1419
+ . filter ( |( l, _) | !l. is_empty ( ) )
1420
+ . collect ( ) ;
1421
+
1422
+ if annotation_id == 0 || !labels. is_empty ( ) {
1423
+ buffer. append (
1424
+ line_idx,
1425
+ & format ! (
1426
+ "{}:{}:{}" ,
1427
+ sm. filename_for_diagnostics( & annotated_file. file. name) ,
1428
+ sm. doctest_offset_line(
1429
+ & annotated_file. file. name,
1430
+ line. line_index
1431
+ ) ,
1432
+ annotations[ 0 ] . start_col + 1 ,
1433
+ ) ,
1434
+ Style :: LineAndColumn ,
1435
+ ) ;
1436
+ if annotation_id == 0 {
1437
+ buffer. prepend ( line_idx, "--> " , Style :: LineNumber ) ;
1438
+ } else {
1439
+ buffer. prepend ( line_idx, "::: " , Style :: LineNumber ) ;
1440
+ }
1427
1441
for _ in 0 ..max_line_num_len {
1428
1442
buffer. prepend ( line_idx, " " , Style :: NoStyle ) ;
1429
1443
}
1430
1444
line_idx += 1 ;
1431
- } ;
1432
- for ( i, annotation) in annotations. into_iter ( ) . enumerate ( ) {
1433
- if let Some ( label) = & annotation. label {
1434
- let style = if annotation. is_primary {
1435
- Style :: LabelPrimary
1436
- } else {
1437
- Style :: LabelSecondary
1438
- } ;
1439
- if annotation_id == 0 {
1440
- buffer. prepend ( line_idx, " |" , Style :: LineNumber ) ;
1441
- for _ in 0 ..max_line_num_len {
1442
- buffer. prepend ( line_idx, " " , Style :: NoStyle ) ;
1443
- }
1444
- line_idx += 1 ;
1445
- buffer. append ( line_idx + i, " = note: " , style) ;
1446
- for _ in 0 ..max_line_num_len {
1447
- buffer. prepend ( line_idx, " " , Style :: NoStyle ) ;
1448
- }
1449
- } else {
1450
- buffer. append ( line_idx + i, ": " , style) ;
1451
- }
1452
- buffer. append ( line_idx + i, label, style) ;
1445
+ }
1446
+ for ( label, is_primary) in labels. into_iter ( ) {
1447
+ let style = if is_primary {
1448
+ Style :: LabelPrimary
1449
+ } else {
1450
+ Style :: LabelSecondary
1451
+ } ;
1452
+ buffer. prepend ( line_idx, " |" , Style :: LineNumber ) ;
1453
+ for _ in 0 ..max_line_num_len {
1454
+ buffer. prepend ( line_idx, " " , Style :: NoStyle ) ;
1455
+ }
1456
+ line_idx += 1 ;
1457
+ buffer. append ( line_idx, " = note: " , style) ;
1458
+ for _ in 0 ..max_line_num_len {
1459
+ buffer. prepend ( line_idx, " " , Style :: NoStyle ) ;
1453
1460
}
1461
+ buffer. append ( line_idx, label, style) ;
1462
+ line_idx += 1 ;
1454
1463
}
1455
1464
}
1456
1465
}
0 commit comments