@@ -21,12 +21,11 @@ use crate::{
21
21
FluentBundle , LazyFallbackBundle , Level , MultiSpan , Subdiag , SubstitutionHighlight ,
22
22
SuggestionStyle , TerminalUrl ,
23
23
} ;
24
- use rustc_lint_defs:: pluralize;
25
-
26
24
use derive_setters:: Setters ;
27
25
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap , FxIndexSet } ;
28
26
use rustc_data_structures:: sync:: { DynSend , IntoDynSyncSend , Lrc } ;
29
27
use rustc_error_messages:: { FluentArgs , SpanLabel } ;
28
+ use rustc_lint_defs:: pluralize;
30
29
use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
31
30
use std:: borrow:: Cow ;
32
31
use std:: cmp:: { max, min, Reverse } ;
@@ -35,7 +34,7 @@ use std::io::prelude::*;
35
34
use std:: io:: { self , IsTerminal } ;
36
35
use std:: iter;
37
36
use std:: path:: Path ;
38
- use termcolor:: { Ansi , Buffer , BufferWriter , ColorChoice , ColorSpec , StandardStream } ;
37
+ use termcolor:: { Buffer , BufferWriter , ColorChoice , ColorSpec , StandardStream } ;
39
38
use termcolor:: { Color , WriteColor } ;
40
39
41
40
/// Default column width, used in tests and when terminal dimensions cannot be determined.
@@ -58,18 +57,6 @@ impl HumanReadableErrorType {
58
57
HumanReadableErrorType :: AnnotateSnippet ( cc) => ( false , cc) ,
59
58
}
60
59
}
61
- pub fn new_emitter (
62
- self ,
63
- mut dst : Box < dyn WriteColor + Send > ,
64
- fallback_bundle : LazyFallbackBundle ,
65
- ) -> HumanEmitter {
66
- let ( short, color_config) = self . unzip ( ) ;
67
- let color = color_config. suggests_using_colors ( ) ;
68
- if !dst. supports_color ( ) && color {
69
- dst = Box :: new ( Ansi :: new ( dst) ) ;
70
- }
71
- HumanEmitter :: new ( dst, fallback_bundle) . short_message ( short)
72
- }
73
60
}
74
61
75
62
#[ derive( Clone , Copy , Debug ) ]
@@ -130,8 +117,8 @@ impl Margin {
130
117
fn was_cut_right ( & self , line_len : usize ) -> bool {
131
118
let right =
132
119
if self . computed_right == self . span_right || self . computed_right == self . label_right {
133
- // Account for the "..." padding given above. Otherwise we end up with code lines that
134
- // do fit but end in "..." as if they were trimmed.
120
+ // Account for the "..." padding given above. Otherwise we end up with code lines
121
+ // that do fit but end in "..." as if they were trimmed.
135
122
self . computed_right - 6
136
123
} else {
137
124
self . computed_right
@@ -628,12 +615,6 @@ impl ColorConfig {
628
615
ColorConfig :: Auto => ColorChoice :: Never ,
629
616
}
630
617
}
631
- fn suggests_using_colors ( self ) -> bool {
632
- match self {
633
- ColorConfig :: Always | ColorConfig :: Auto => true ,
634
- ColorConfig :: Never => false ,
635
- }
636
- }
637
618
}
638
619
639
620
/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
@@ -657,19 +638,14 @@ pub struct HumanEmitter {
657
638
}
658
639
659
640
#[ derive( Debug ) ]
660
- pub struct FileWithAnnotatedLines {
661
- pub file : Lrc < SourceFile > ,
662
- pub lines : Vec < Line > ,
641
+ pub ( crate ) struct FileWithAnnotatedLines {
642
+ pub ( crate ) file : Lrc < SourceFile > ,
643
+ pub ( crate ) lines : Vec < Line > ,
663
644
multiline_depth : usize ,
664
645
}
665
646
666
647
impl HumanEmitter {
667
- pub fn stderr ( color_config : ColorConfig , fallback_bundle : LazyFallbackBundle ) -> HumanEmitter {
668
- let dst = from_stderr ( color_config) ;
669
- Self :: create ( dst, fallback_bundle)
670
- }
671
-
672
- fn create ( dst : Destination , fallback_bundle : LazyFallbackBundle ) -> HumanEmitter {
648
+ pub fn new ( dst : Destination , fallback_bundle : LazyFallbackBundle ) -> HumanEmitter {
673
649
HumanEmitter {
674
650
dst : IntoDynSyncSend ( dst) ,
675
651
sm : None ,
@@ -686,13 +662,6 @@ impl HumanEmitter {
686
662
}
687
663
}
688
664
689
- pub fn new (
690
- dst : Box < dyn WriteColor + Send > ,
691
- fallback_bundle : LazyFallbackBundle ,
692
- ) -> HumanEmitter {
693
- Self :: create ( dst, fallback_bundle)
694
- }
695
-
696
665
fn maybe_anonymized ( & self , line_num : usize ) -> Cow < ' static , str > {
697
666
if self . ui_testing {
698
667
Cow :: Borrowed ( ANONYMIZED_LINE_NUM )
@@ -724,8 +693,9 @@ impl HumanEmitter {
724
693
. skip ( left)
725
694
. take_while ( |ch| {
726
695
// Make sure that the trimming on the right will fall within the terminal width.
727
- // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char` is.
728
- // For now, just accept that sometimes the code line will be longer than desired.
696
+ // FIXME: `unicode_width` sometimes disagrees with terminals on how wide a `char`
697
+ // is. For now, just accept that sometimes the code line will be longer than
698
+ // desired.
729
699
let next = unicode_width:: UnicodeWidthChar :: width ( * ch) . unwrap_or ( 1 ) ;
730
700
if taken + next > right - left {
731
701
return false ;
@@ -2228,8 +2198,8 @@ impl HumanEmitter {
2228
2198
buffer. puts ( * row_num - 1 , max_line_num_len + 3 , & line, Style :: NoStyle ) ;
2229
2199
* row_num += 1 ;
2230
2200
}
2231
- // If the last line is exactly equal to the line we need to add, we can skip both of them.
2232
- // This allows us to avoid output like the following:
2201
+ // If the last line is exactly equal to the line we need to add, we can skip both of
2202
+ // them. This allows us to avoid output like the following:
2233
2203
// 2 - &
2234
2204
// 2 + if true { true } else { false }
2235
2205
// 3 - if true { true } else { false }
@@ -2586,6 +2556,7 @@ fn num_overlap(
2586
2556
let extra = if inclusive { 1 } else { 0 } ;
2587
2557
( b_start..b_end + extra) . contains ( & a_start) || ( a_start..a_end + extra) . contains ( & b_start)
2588
2558
}
2559
+
2589
2560
fn overlaps ( a1 : & Annotation , a2 : & Annotation , padding : usize ) -> bool {
2590
2561
num_overlap (
2591
2562
a1. start_col . display ,
@@ -2632,7 +2603,7 @@ fn emit_to_destination(
2632
2603
Ok ( ( ) )
2633
2604
}
2634
2605
2635
- pub type Destination = Box < ( dyn WriteColor + Send ) > ;
2606
+ pub type Destination = Box < dyn WriteColor + Send > ;
2636
2607
2637
2608
struct Buffy {
2638
2609
buffer_writer : BufferWriter ,
@@ -2674,7 +2645,7 @@ impl WriteColor for Buffy {
2674
2645
}
2675
2646
}
2676
2647
2677
- fn from_stderr ( color : ColorConfig ) -> Destination {
2648
+ pub fn stderr_destination ( color : ColorConfig ) -> Destination {
2678
2649
let choice = color. to_color_choice ( ) ;
2679
2650
// On Windows we'll be performing global synchronization on the entire
2680
2651
// system for emitting rustc errors, so there's no need to buffer
0 commit comments