10
10
11
11
use self :: Destination :: * ;
12
12
13
- use syntax_pos:: { COMMAND_LINE_SP , DUMMY_SP , FileMap , Span , MultiSpan , LineInfo , CharPos } ;
14
- use registry;
13
+ use syntax_pos:: { COMMAND_LINE_SP , DUMMY_SP , FileMap , Span , MultiSpan , CharPos } ;
15
14
16
- use check_old_school;
17
15
use { Level , CodeSuggestion , DiagnosticBuilder , CodeMapper } ;
18
16
use RenderSpan :: * ;
19
- use snippet:: { StyledString , Style , FormatMode , Annotation , Line } ;
17
+ use snippet:: { StyledString , Style , Annotation , Line } ;
20
18
use styled_buffer:: StyledBuffer ;
21
19
22
- use std:: cmp;
23
20
use std:: io:: prelude:: * ;
24
21
use std:: io;
25
22
use std:: rc:: Rc ;
@@ -33,18 +30,7 @@ pub trait Emitter {
33
30
34
31
impl Emitter for EmitterWriter {
35
32
fn emit ( & mut self , db : & DiagnosticBuilder ) {
36
- // Pick old school mode either from env or let the test dictate the format
37
- let old_school = match self . format_mode {
38
- FormatMode :: NewErrorFormat => false ,
39
- FormatMode :: OriginalErrorFormat => true ,
40
- FormatMode :: EnvironmentSelected => check_old_school ( )
41
- } ;
42
-
43
- if old_school {
44
- self . emit_messages_old_school ( db) ;
45
- } else {
46
- self . emit_messages_default ( db) ;
47
- }
33
+ self . emit_messages_default ( db) ;
48
34
}
49
35
}
50
36
@@ -70,11 +56,7 @@ impl ColorConfig {
70
56
71
57
pub struct EmitterWriter {
72
58
dst : Destination ,
73
- registry : Option < registry:: Registry > ,
74
59
cm : Option < Rc < CodeMapper > > ,
75
-
76
- // For now, allow an old-school mode while we transition
77
- format_mode : FormatMode
78
60
}
79
61
80
62
struct FileWithAnnotatedLines {
@@ -99,33 +81,23 @@ macro_rules! println_maybe_styled {
99
81
100
82
impl EmitterWriter {
101
83
pub fn stderr ( color_config : ColorConfig ,
102
- registry : Option < registry:: Registry > ,
103
- code_map : Option < Rc < CodeMapper > > ,
104
- format_mode : FormatMode )
84
+ code_map : Option < Rc < CodeMapper > > )
105
85
-> EmitterWriter {
106
86
if color_config. use_color ( ) {
107
87
let dst = Destination :: from_stderr ( ) ;
108
88
EmitterWriter { dst : dst,
109
- registry : registry,
110
- cm : code_map,
111
- format_mode : format_mode. clone ( ) }
89
+ cm : code_map}
112
90
} else {
113
91
EmitterWriter { dst : Raw ( Box :: new ( io:: stderr ( ) ) ) ,
114
- registry : registry,
115
- cm : code_map,
116
- format_mode : format_mode. clone ( ) }
92
+ cm : code_map}
117
93
}
118
94
}
119
95
120
96
pub fn new ( dst : Box < Write + Send > ,
121
- registry : Option < registry:: Registry > ,
122
- code_map : Option < Rc < CodeMapper > > ,
123
- format_mode : FormatMode )
97
+ code_map : Option < Rc < CodeMapper > > )
124
98
-> EmitterWriter {
125
99
EmitterWriter { dst : Raw ( dst) ,
126
- registry : registry,
127
- cm : code_map,
128
- format_mode : format_mode. clone ( ) }
100
+ cm : code_map}
129
101
}
130
102
131
103
fn preprocess_annotations ( & self , msp : & MultiSpan ) -> Vec < FileWithAnnotatedLines > {
@@ -668,240 +640,6 @@ impl EmitterWriter {
668
640
_ => ( )
669
641
}
670
642
}
671
- fn emit_message_old_school ( & mut self ,
672
- msp : & MultiSpan ,
673
- msg : & str ,
674
- code : & Option < String > ,
675
- level : & Level ,
676
- show_snippet : bool )
677
- -> io:: Result < ( ) > {
678
- let mut buffer = StyledBuffer :: new ( ) ;
679
-
680
- let loc = match msp. primary_span ( ) {
681
- Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => "" . to_string ( ) ,
682
- Some ( ps) => if let Some ( ref cm) = self . cm {
683
- cm. span_to_string ( ps)
684
- } else {
685
- "" . to_string ( )
686
- } ,
687
- None => {
688
- "" . to_string ( )
689
- }
690
- } ;
691
- if loc != "" {
692
- buffer. append ( 0 , & loc, Style :: NoStyle ) ;
693
- buffer. append ( 0 , " " , Style :: NoStyle ) ;
694
- }
695
- buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
696
- buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
697
- buffer. append ( 0 , msg, Style :: HeaderMsg ) ;
698
- buffer. append ( 0 , " " , Style :: NoStyle ) ;
699
- match code {
700
- & Some ( ref code) => {
701
- buffer. append ( 0 , "[" , Style :: ErrorCode ) ;
702
- buffer. append ( 0 , & code, Style :: ErrorCode ) ;
703
- buffer. append ( 0 , "]" , Style :: ErrorCode ) ;
704
- }
705
- _ => { }
706
- }
707
-
708
- if !show_snippet {
709
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
710
- return Ok ( ( ) ) ;
711
- }
712
-
713
- // Watch out for various nasty special spans; don't try to
714
- // print any filename or anything for those.
715
- match msp. primary_span ( ) {
716
- Some ( COMMAND_LINE_SP ) | Some ( DUMMY_SP ) => {
717
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
718
- return Ok ( ( ) ) ;
719
- }
720
- _ => { }
721
- }
722
-
723
- let annotated_files = self . preprocess_annotations ( msp) ;
724
-
725
- if let ( Some ( ref cm) , Some ( ann_file) , Some ( ref primary_span) ) =
726
- ( self . cm . as_ref ( ) , annotated_files. first ( ) , msp. primary_span ( ) . as_ref ( ) ) {
727
-
728
- // Next, print the source line and its squiggle
729
- // for old school mode, we will render them to the buffer, then insert the file loc
730
- // (or space the same amount) in front of the line and the squiggle
731
- let source_string = ann_file. file . get_line ( ann_file. lines [ 0 ] . line_index - 1 )
732
- . unwrap_or ( "" ) ;
733
-
734
- let line_offset = buffer. num_lines ( ) ;
735
-
736
- let lo = cm. lookup_char_pos ( primary_span. lo ) ;
737
- //Before each secondary line in old skool-mode, print the label
738
- //as an old-style note
739
- let file_pos = format ! ( "{}:{} " , lo. file. name. clone( ) , lo. line) ;
740
- let file_pos_len = file_pos. len ( ) ;
741
-
742
- // First create the source line we will highlight.
743
- buffer. puts ( line_offset, 0 , & file_pos, Style :: FileNameStyle ) ;
744
- buffer. puts ( line_offset, file_pos_len, & source_string, Style :: Quotation ) ;
745
- // Sort the annotations by (start, end col)
746
- let annotations = ann_file. lines [ 0 ] . annotations . clone ( ) ;
747
-
748
- // Next, create the highlight line.
749
- for annotation in & annotations {
750
- for p in annotation. start_col ..annotation. end_col {
751
- if p == annotation. start_col {
752
- buffer. putc ( line_offset + 1 ,
753
- file_pos_len + p,
754
- '^' ,
755
- if annotation. is_primary {
756
- Style :: UnderlinePrimary
757
- } else {
758
- Style :: OldSchoolNote
759
- } ) ;
760
- } else {
761
- buffer. putc ( line_offset + 1 ,
762
- file_pos_len + p,
763
- '~' ,
764
- if annotation. is_primary {
765
- Style :: UnderlinePrimary
766
- } else {
767
- Style :: OldSchoolNote
768
- } ) ;
769
- }
770
- }
771
- }
772
- }
773
- if let Some ( ref primary_span) = msp. primary_span ( ) . as_ref ( ) {
774
- self . render_macro_backtrace_old_school ( primary_span, & mut buffer) ?;
775
- }
776
-
777
- match code {
778
- & Some ( ref code) if self . registry . as_ref ( )
779
- . and_then ( |registry| registry. find_description ( code) )
780
- . is_some ( ) => {
781
- let msg = "run `rustc --explain " . to_string ( ) + & code. to_string ( ) +
782
- "` to see a detailed explanation" ;
783
-
784
- let line_offset = buffer. num_lines ( ) ;
785
- buffer. append ( line_offset, & loc, Style :: NoStyle ) ;
786
- buffer. append ( line_offset, " " , Style :: NoStyle ) ;
787
- buffer. append ( line_offset, & Level :: Help . to_string ( ) , Style :: Level ( Level :: Help ) ) ;
788
- buffer. append ( line_offset, ": " , Style :: HeaderMsg ) ;
789
- buffer. append ( line_offset, & msg, Style :: HeaderMsg ) ;
790
- }
791
- _ => ( )
792
- }
793
-
794
- // final step: take our styled buffer, render it, then output it
795
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
796
- Ok ( ( ) )
797
- }
798
- fn emit_suggestion_old_school ( & mut self ,
799
- suggestion : & CodeSuggestion ,
800
- level : & Level ,
801
- msg : & str )
802
- -> io:: Result < ( ) > {
803
- use std:: borrow:: Borrow ;
804
-
805
- let primary_span = suggestion. msp . primary_span ( ) . unwrap ( ) ;
806
- if let Some ( ref cm) = self . cm {
807
- let mut buffer = StyledBuffer :: new ( ) ;
808
-
809
- let loc = cm. span_to_string ( primary_span) ;
810
-
811
- if loc != "" {
812
- buffer. append ( 0 , & loc, Style :: NoStyle ) ;
813
- buffer. append ( 0 , " " , Style :: NoStyle ) ;
814
- }
815
-
816
- buffer. append ( 0 , & level. to_string ( ) , Style :: Level ( level. clone ( ) ) ) ;
817
- buffer. append ( 0 , ": " , Style :: HeaderMsg ) ;
818
- buffer. append ( 0 , msg, Style :: HeaderMsg ) ;
819
-
820
- let lines = cm. span_to_lines ( primary_span) . unwrap ( ) ;
821
-
822
- assert ! ( !lines. lines. is_empty( ) ) ;
823
-
824
- let complete = suggestion. splice_lines ( cm. borrow ( ) ) ;
825
- let line_count = cmp:: min ( lines. lines . len ( ) , MAX_HIGHLIGHT_LINES ) ;
826
- let display_lines = & lines. lines [ ..line_count] ;
827
-
828
- let fm = & * lines. file ;
829
- // Calculate the widest number to format evenly
830
- let max_digits = line_num_max_digits ( display_lines. last ( ) . unwrap ( ) ) ;
831
-
832
- // print the suggestion without any line numbers, but leave
833
- // space for them. This helps with lining up with previous
834
- // snippets from the actual error being reported.
835
- let mut lines = complete. lines ( ) ;
836
- let mut row_num = 1 ;
837
- for line in lines. by_ref ( ) . take ( MAX_HIGHLIGHT_LINES ) {
838
- buffer. append ( row_num, & fm. name , Style :: FileNameStyle ) ;
839
- for _ in 0 ..max_digits+2 {
840
- buffer. append ( row_num, & " " , Style :: NoStyle ) ;
841
- }
842
- buffer. append ( row_num, line, Style :: NoStyle ) ;
843
- row_num += 1 ;
844
- }
845
-
846
- // if we elided some lines, add an ellipsis
847
- if let Some ( _) = lines. next ( ) {
848
- buffer. append ( row_num, "..." , Style :: NoStyle ) ;
849
- }
850
- emit_to_destination ( & buffer. render ( ) , level, & mut self . dst ) ?;
851
- }
852
- Ok ( ( ) )
853
- }
854
-
855
- fn emit_messages_old_school ( & mut self , db : & DiagnosticBuilder ) {
856
- match self . emit_message_old_school ( & db. span ,
857
- & db. message ,
858
- & db. code ,
859
- & db. level ,
860
- true ) {
861
- Ok ( ( ) ) => {
862
- for child in & db. children {
863
- let ( span, show_snippet) = if child. span . primary_spans ( ) . is_empty ( ) {
864
- ( db. span . clone ( ) , false )
865
- } else {
866
- ( child. span . clone ( ) , true )
867
- } ;
868
-
869
- match child. render_span {
870
- Some ( FullSpan ( _) ) => {
871
- match self . emit_message_old_school ( & span,
872
- & child. message ,
873
- & None ,
874
- & child. level ,
875
- show_snippet) {
876
- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
877
- _ => ( )
878
- }
879
- } ,
880
- Some ( Suggestion ( ref cs) ) => {
881
- match self . emit_suggestion_old_school ( cs,
882
- & child. level ,
883
- & child. message ) {
884
- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
885
- _ => ( )
886
- }
887
- } ,
888
- None => {
889
- match self . emit_message_old_school ( & span,
890
- & child. message ,
891
- & None ,
892
- & child. level ,
893
- show_snippet) {
894
- Err ( e) => panic ! ( "failed to emit error: {}" , e) ,
895
- _ => ( )
896
- }
897
- }
898
- }
899
- }
900
- }
901
- Err ( e) => panic ! ( "failed to emit error: {}" , e)
902
- }
903
- }
904
-
905
643
fn render_macro_backtrace_old_school ( & mut self ,
906
644
sp : & Span ,
907
645
buffer : & mut StyledBuffer ) -> io:: Result < ( ) > {
@@ -958,16 +696,6 @@ fn emit_to_destination(rendered_buffer: &Vec<Vec<StyledString>>,
958
696
Ok ( ( ) )
959
697
}
960
698
961
- fn line_num_max_digits ( line : & LineInfo ) -> usize {
962
- let mut max_line_num = line. line_index + 1 ;
963
- let mut digits = 0 ;
964
- while max_line_num > 0 {
965
- max_line_num /= 10 ;
966
- digits += 1 ;
967
- }
968
- digits
969
- }
970
-
971
699
#[ cfg( unix) ]
972
700
fn stderr_isatty ( ) -> bool {
973
701
use libc;
0 commit comments