@@ -17,10 +17,7 @@ use rustc_errors::{
1717 json:: JsonEmitter ,
1818 translation:: Translator ,
1919} ;
20- use rustc_session:: {
21- config:: { self , ErrorOutputType } ,
22- parse:: ParseSess ,
23- } ;
20+ use rustc_session:: { config, parse:: ParseSess } ;
2421use rustc_span:: source_map:: SourceMap ;
2522
2623pub struct FluxSession {
@@ -75,43 +72,99 @@ impl FluxSession {
7572}
7673
7774fn emitter (
78- opts : & config:: Options ,
75+ sopts : & config:: Options ,
7976 source_map : Arc < SourceMap > ,
8077 fallback_fluent_bundle : LazyFallbackBundle ,
8178) -> Box < dyn Emitter + sync:: DynSend > {
82- let track_diagnostics = opts. unstable_opts . track_diagnostics ;
83-
8479 let translator = Translator { fluent_bundle : None , fallback_fluent_bundle } ;
85- match opts. error_format {
86- ErrorOutputType :: HumanReadable { kind, color_config } => {
80+
81+ // All the code below is copied from rustc
82+ let macro_backtrace = sopts. unstable_opts . macro_backtrace ;
83+ let track_diagnostics = sopts. unstable_opts . track_diagnostics ;
84+ let terminal_url = match sopts. unstable_opts . terminal_urls {
85+ rustc_errors:: TerminalUrl :: Auto => {
86+ match ( std:: env:: var ( "COLORTERM" ) . as_deref ( ) , std:: env:: var ( "TERM" ) . as_deref ( ) ) {
87+ ( Ok ( "truecolor" ) , Ok ( "xterm-256color" ) )
88+ if sopts. unstable_features . is_nightly_build ( ) =>
89+ {
90+ rustc_errors:: TerminalUrl :: Yes
91+ }
92+ _ => rustc_errors:: TerminalUrl :: No ,
93+ }
94+ }
95+ t => t,
96+ } ;
97+
98+ let source_map = if sopts. unstable_opts . link_only { None } else { Some ( source_map) } ;
99+
100+ match sopts. error_format {
101+ config:: ErrorOutputType :: HumanReadable { kind, color_config } => {
102+ let short = kind. short ( ) ;
103+
87104 if let HumanReadableErrorType :: AnnotateSnippet = kind {
88105 let emitter =
89- AnnotateSnippetEmitter :: new ( Some ( source_map) , translator, false , false ) ;
90- Box :: new ( emitter)
106+ AnnotateSnippetEmitter :: new ( stderr_destination ( color_config) , translator)
107+ . sm ( source_map)
108+ . short_message ( short)
109+ . diagnostic_width ( sopts. diagnostic_width )
110+ . macro_backtrace ( macro_backtrace)
111+ . track_diagnostics ( track_diagnostics)
112+ . terminal_url ( terminal_url)
113+ . theme ( if let HumanReadableErrorType :: Unicode = kind {
114+ rustc_errors:: emitter:: OutputTheme :: Unicode
115+ } else {
116+ rustc_errors:: emitter:: OutputTheme :: Ascii
117+ } )
118+ . ignored_directories_in_source_blocks (
119+ sopts
120+ . unstable_opts
121+ . ignore_directory_in_diagnostics_source_blocks
122+ . clone ( ) ,
123+ ) ;
124+ Box :: new ( emitter. ui_testing ( sopts. unstable_opts . ui_testing ) )
91125 } else {
92- let dst = stderr_destination ( color_config) ;
93- let emitter = HumanEmitter :: new ( dst , translator )
94- . sm ( Some ( source_map ) )
95- . short_message ( kind . short ( ) )
96- . diagnostic_width ( opts . diagnostic_width )
126+ let emitter = HumanEmitter :: new ( stderr_destination ( color_config) , translator )
127+ . sm ( source_map )
128+ . short_message ( short )
129+ . diagnostic_width ( sopts . diagnostic_width )
130+ . macro_backtrace ( macro_backtrace )
97131 . track_diagnostics ( track_diagnostics)
98- . terminal_url ( opts. unstable_opts . terminal_urls ) ;
99- Box :: new ( emitter)
132+ . terminal_url ( terminal_url)
133+ . theme ( if let HumanReadableErrorType :: Unicode = kind {
134+ rustc_errors:: emitter:: OutputTheme :: Unicode
135+ } else {
136+ rustc_errors:: emitter:: OutputTheme :: Ascii
137+ } )
138+ . ignored_directories_in_source_blocks (
139+ sopts
140+ . unstable_opts
141+ . ignore_directory_in_diagnostics_source_blocks
142+ . clone ( ) ,
143+ ) ;
144+ Box :: new ( emitter. ui_testing ( sopts. unstable_opts . ui_testing ) )
100145 }
101146 }
102- ErrorOutputType :: Json { pretty, json_rendered, color_config } => {
147+ config :: ErrorOutputType :: Json { pretty, json_rendered, color_config } => {
103148 Box :: new (
104149 JsonEmitter :: new (
105150 Box :: new ( io:: BufWriter :: new ( io:: stderr ( ) ) ) ,
106- Some ( source_map) ,
151+ source_map,
107152 translator,
108153 pretty,
109154 json_rendered,
110155 color_config,
111156 )
157+ . ui_testing ( sopts. unstable_opts . ui_testing )
158+ . ignored_directories_in_source_blocks (
159+ sopts
160+ . unstable_opts
161+ . ignore_directory_in_diagnostics_source_blocks
162+ . clone ( ) ,
163+ )
164+ . diagnostic_width ( sopts. diagnostic_width )
165+ . macro_backtrace ( macro_backtrace)
112166 . track_diagnostics ( track_diagnostics)
113- . diagnostic_width ( opts. diagnostic_width )
114- . terminal_url ( opts. unstable_opts . terminal_urls ) ,
167+ . terminal_url ( terminal_url) ,
115168 )
116169 }
117170 }
0 commit comments