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