Skip to content

Commit d682a68

Browse files
authored
Rollup merge of #80897 - camelid:atty, r=jyn514
driver: Use `atty` instead of rolling our own Fixes #80888. Rationale: - `atty` is widely used in the Rust ecosystem - We already use it (in `rustc_errors` and other places) - We shouldn't be rolling our own TTY detector when there's a widely-used, well-tested package that we can use
2 parents 7c79e5b + 8c43160 commit d682a68

File tree

3 files changed

+4
-33
lines changed

3 files changed

+4
-33
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3652,6 +3652,7 @@ dependencies = [
36523652
name = "rustc_driver"
36533653
version = "0.0.0"
36543654
dependencies = [
3655+
"atty",
36553656
"libc",
36563657
"rustc_ast",
36573658
"rustc_ast_pretty",

compiler/rustc_driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ crate-type = ["dylib"]
99

1010
[dependencies]
1111
libc = "0.2"
12+
atty = "0.2"
1213
tracing = { version = "0.1.18" }
1314
tracing-subscriber = { version = "0.2.13", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
1415
tracing-tree = "0.1.6"

compiler/rustc_driver/src/lib.rs

+2-33
Original file line numberDiff line numberDiff line change
@@ -546,43 +546,12 @@ impl Compilation {
546546
#[derive(Copy, Clone)]
547547
pub struct RustcDefaultCalls;
548548

549-
// FIXME remove these and use winapi 0.3 instead
550-
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs
551-
#[cfg(unix)]
552-
fn stdout_isatty() -> bool {
553-
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
554-
}
555-
556-
#[cfg(windows)]
557549
fn stdout_isatty() -> bool {
558-
use winapi::um::consoleapi::GetConsoleMode;
559-
use winapi::um::processenv::GetStdHandle;
560-
use winapi::um::winbase::STD_OUTPUT_HANDLE;
561-
562-
unsafe {
563-
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
564-
let mut out = 0;
565-
GetConsoleMode(handle, &mut out) != 0
566-
}
550+
atty::is(atty::Stream::Stdout)
567551
}
568552

569-
// FIXME remove these and use winapi 0.3 instead
570-
#[cfg(unix)]
571-
fn stderr_isatty() -> bool {
572-
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
573-
}
574-
575-
#[cfg(windows)]
576553
fn stderr_isatty() -> bool {
577-
use winapi::um::consoleapi::GetConsoleMode;
578-
use winapi::um::processenv::GetStdHandle;
579-
use winapi::um::winbase::STD_ERROR_HANDLE;
580-
581-
unsafe {
582-
let handle = GetStdHandle(STD_ERROR_HANDLE);
583-
let mut out = 0;
584-
GetConsoleMode(handle, &mut out) != 0
585-
}
554+
atty::is(atty::Stream::Stderr)
586555
}
587556

588557
fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {

0 commit comments

Comments
 (0)