@@ -21,12 +21,11 @@ use crate::{
2121 FluentBundle , LazyFallbackBundle , Level , MultiSpan , Subdiag , SubstitutionHighlight ,
2222 SuggestionStyle , TerminalUrl ,
2323} ;
24- use rustc_lint_defs:: pluralize;
25-
2624use derive_setters:: Setters ;
2725use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap , FxIndexSet } ;
2826use rustc_data_structures:: sync:: { DynSend , IntoDynSyncSend , Lrc } ;
2927use rustc_error_messages:: { FluentArgs , SpanLabel } ;
28+ use rustc_lint_defs:: pluralize;
3029use rustc_span:: hygiene:: { ExpnKind , MacroKind } ;
3130use std:: borrow:: Cow ;
3231use std:: cmp:: { max, min, Reverse } ;
@@ -35,7 +34,7 @@ use std::io::prelude::*;
3534use std:: io:: { self , IsTerminal } ;
3635use std:: iter;
3736use std:: path:: Path ;
38- use termcolor:: { Ansi , Buffer , BufferWriter , ColorChoice , ColorSpec , StandardStream } ;
37+ use termcolor:: { Buffer , BufferWriter , ColorChoice , ColorSpec , StandardStream } ;
3938use termcolor:: { Color , WriteColor } ;
4039
4140/// Default column width, used in tests and when terminal dimensions cannot be determined.
@@ -58,18 +57,6 @@ impl HumanReadableErrorType {
5857 HumanReadableErrorType :: AnnotateSnippet ( cc) => ( false , cc) ,
5958 }
6059 }
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- }
7360}
7461
7562#[ derive( Clone , Copy , Debug ) ]
@@ -130,8 +117,8 @@ impl Margin {
130117 fn was_cut_right ( & self , line_len : usize ) -> bool {
131118 let right =
132119 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.
135122 self . computed_right - 6
136123 } else {
137124 self . computed_right
@@ -628,12 +615,6 @@ impl ColorConfig {
628615 ColorConfig :: Auto => ColorChoice :: Never ,
629616 }
630617 }
631- fn suggests_using_colors ( self ) -> bool {
632- match self {
633- ColorConfig :: Always | ColorConfig :: Auto => true ,
634- ColorConfig :: Never => false ,
635- }
636- }
637618}
638619
639620/// Handles the writing of `HumanReadableErrorType::Default` and `HumanReadableErrorType::Short`
@@ -657,19 +638,14 @@ pub struct HumanEmitter {
657638}
658639
659640#[ 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 > ,
663644 multiline_depth : usize ,
664645}
665646
666647impl 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 {
673649 HumanEmitter {
674650 dst : IntoDynSyncSend ( dst) ,
675651 sm : None ,
@@ -686,13 +662,6 @@ impl HumanEmitter {
686662 }
687663 }
688664
689- pub fn new (
690- dst : Box < dyn WriteColor + Send > ,
691- fallback_bundle : LazyFallbackBundle ,
692- ) -> HumanEmitter {
693- Self :: create ( dst, fallback_bundle)
694- }
695-
696665 fn maybe_anonymized ( & self , line_num : usize ) -> Cow < ' static , str > {
697666 if self . ui_testing {
698667 Cow :: Borrowed ( ANONYMIZED_LINE_NUM )
@@ -724,8 +693,9 @@ impl HumanEmitter {
724693 . skip ( left)
725694 . take_while ( |ch| {
726695 // 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.
729699 let next = unicode_width:: UnicodeWidthChar :: width ( * ch) . unwrap_or ( 1 ) ;
730700 if taken + next > right - left {
731701 return false ;
@@ -2228,8 +2198,8 @@ impl HumanEmitter {
22282198 buffer. puts ( * row_num - 1 , max_line_num_len + 3 , & line, Style :: NoStyle ) ;
22292199 * row_num += 1 ;
22302200 }
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:
22332203 // 2 - &
22342204 // 2 + if true { true } else { false }
22352205 // 3 - if true { true } else { false }
@@ -2586,6 +2556,7 @@ fn num_overlap(
25862556 let extra = if inclusive { 1 } else { 0 } ;
25872557 ( b_start..b_end + extra) . contains ( & a_start) || ( a_start..a_end + extra) . contains ( & b_start)
25882558}
2559+
25892560fn overlaps ( a1 : & Annotation , a2 : & Annotation , padding : usize ) -> bool {
25902561 num_overlap (
25912562 a1. start_col . display ,
@@ -2632,7 +2603,7 @@ fn emit_to_destination(
26322603 Ok ( ( ) )
26332604}
26342605
2635- pub type Destination = Box < ( dyn WriteColor + Send ) > ;
2606+ pub type Destination = Box < dyn WriteColor + Send > ;
26362607
26372608struct Buffy {
26382609 buffer_writer : BufferWriter ,
@@ -2674,7 +2645,7 @@ impl WriteColor for Buffy {
26742645 }
26752646}
26762647
2677- fn from_stderr ( color : ColorConfig ) -> Destination {
2648+ pub fn stderr_destination ( color : ColorConfig ) -> Destination {
26782649 let choice = color. to_color_choice ( ) ;
26792650 // On Windows we'll be performing global synchronization on the entire
26802651 // system for emitting rustc errors, so there's no need to buffer
0 commit comments