@@ -71,7 +71,8 @@ extern crate tikv_jemalloc_sys;
71
71
use tikv_jemalloc_sys as jemalloc_sys;
72
72
73
73
use std:: default:: Default ;
74
- use std:: env;
74
+ use std:: env:: { self , VarError } ;
75
+ use std:: io;
75
76
use std:: process;
76
77
77
78
use rustc_driver:: { abort_on_err, describe_lints} ;
@@ -179,47 +180,20 @@ pub fn main() {
179
180
}
180
181
181
182
fn init_logging ( ) {
182
- use std:: io;
183
-
184
- // FIXME remove these and use winapi 0.3 instead
185
- // Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs, rustc_driver/lib.rs
186
- #[ cfg( unix) ]
187
- fn stdout_isatty ( ) -> bool {
188
- extern crate libc;
189
- unsafe { libc:: isatty ( libc:: STDOUT_FILENO ) != 0 }
190
- }
191
-
192
- #[ cfg( windows) ]
193
- fn stdout_isatty ( ) -> bool {
194
- extern crate winapi;
195
- use winapi:: um:: consoleapi:: GetConsoleMode ;
196
- use winapi:: um:: processenv:: GetStdHandle ;
197
- use winapi:: um:: winbase:: STD_OUTPUT_HANDLE ;
198
-
199
- unsafe {
200
- let handle = GetStdHandle ( STD_OUTPUT_HANDLE ) ;
201
- let mut out = 0 ;
202
- GetConsoleMode ( handle, & mut out) != 0
203
- }
204
- }
205
-
206
- let color_logs = match std:: env:: var ( "RUSTDOC_LOG_COLOR" ) {
207
- Ok ( value) => match value. as_ref ( ) {
208
- "always" => true ,
209
- "never" => false ,
210
- "auto" => stdout_isatty ( ) ,
211
- _ => early_error (
212
- ErrorOutputType :: default ( ) ,
213
- & format ! (
214
- "invalid log color value '{}': expected one of always, never, or auto" ,
215
- value
216
- ) ,
217
- ) ,
218
- } ,
219
- Err ( std:: env:: VarError :: NotPresent ) => stdout_isatty ( ) ,
220
- Err ( std:: env:: VarError :: NotUnicode ( _value) ) => early_error (
183
+ let color_logs = match std:: env:: var ( "RUSTDOC_LOG_COLOR" ) . as_deref ( ) {
184
+ Ok ( "always" ) => true ,
185
+ Ok ( "never" ) => false ,
186
+ Ok ( "auto" ) | Err ( VarError :: NotPresent ) => atty:: is ( atty:: Stream :: Stdout ) ,
187
+ Ok ( value) => early_error (
188
+ ErrorOutputType :: default ( ) ,
189
+ & format ! ( "invalid log color value '{}': expected one of always, never, or auto" , value) ,
190
+ ) ,
191
+ Err ( VarError :: NotUnicode ( value) ) => early_error (
221
192
ErrorOutputType :: default ( ) ,
222
- "non-Unicode log color value: expected one of always, never, or auto" ,
193
+ & format ! (
194
+ "invalid log color value '{}': expected one of always, never, or auto" ,
195
+ value. to_string_lossy( )
196
+ ) ,
223
197
) ,
224
198
} ;
225
199
let filter = tracing_subscriber:: EnvFilter :: from_env ( "RUSTDOC_LOG" ) ;
0 commit comments