From c5ad97da258bb47cba2f888cee73b0f4b5289d58 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:53:21 +0100 Subject: [PATCH 1/4] Use IsTerminal in rustc_errors --- Cargo.lock | 1 - compiler/rustc_errors/Cargo.toml | 1 - compiler/rustc_errors/src/emitter.rs | 6 +++--- compiler/rustc_errors/src/lib.rs | 1 + 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5acab8139c98..6c0bb32dec71e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3452,7 +3452,6 @@ name = "rustc_errors" version = "0.0.0" dependencies = [ "annotate-snippets", - "atty", "rustc_ast", "rustc_ast_pretty", "rustc_data_structures", diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index 7803a0792e12c..eb560a68b5697 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target" } rustc_hir = { path = "../rustc_hir" } rustc_lint_defs = { path = "../rustc_lint_defs" } unicode-width = "0.1.4" -atty = "0.2" termcolor = "1.0" annotate-snippets = "0.9" termize = "0.1.1" diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index cd6413bc3ec62..12a93fbedf900 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -28,8 +28,8 @@ use rustc_error_messages::FluentArgs; use rustc_span::hygiene::{ExpnKind, MacroKind}; use std::borrow::Cow; use std::cmp::{max, min, Reverse}; -use std::io; use std::io::prelude::*; +use std::io::{self, IsTerminal}; use std::iter; use std::path::Path; use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream}; @@ -619,14 +619,14 @@ impl ColorConfig { fn to_color_choice(self) -> ColorChoice { match self { ColorConfig::Always => { - if atty::is(atty::Stream::Stderr) { + if io::stderr().is_terminal() { ColorChoice::Always } else { ColorChoice::AlwaysAnsi } } ColorConfig::Never => ColorChoice::Never, - ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto, + ColorConfig::Auto if io::stderr().is_terminal() => ColorChoice::Auto, ColorConfig::Auto => ColorChoice::Never, } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 9fafbe4bd407e..814dba10484eb 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -5,6 +5,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(drain_filter)] #![feature(if_let_guard)] +#![feature(is_terminal)] #![feature(adt_const_params)] #![feature(let_chains)] #![feature(never_type)] From 34f61dd56718261548f58e9cd6bb9c4146825a1e Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:55:18 +0100 Subject: [PATCH 2/4] Use IsTerminal in rustc_driver --- compiler/rustc_driver/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 7d5604fcabcc9..d1d590d2d08dd 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -5,6 +5,7 @@ //! This API is completely unstable and subject to change. #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(is_terminal)] #![feature(once_cell)] #![recursion_limit = "256"] #![allow(rustc::potential_query_instability)] @@ -26,7 +27,6 @@ use rustc_feature::find_gated_cfg; use rustc_interface::util::{self, collect_crate_types, get_codegen_backend}; use rustc_interface::{interface, Queries}; use rustc_lint::LintStore; -use rustc_log::stdout_isatty; use rustc_metadata::locator; use rustc_save_analysis as save; use rustc_save_analysis::DumpHandler; @@ -47,7 +47,7 @@ use std::default::Default; use std::env; use std::ffi::OsString; use std::fs; -use std::io::{self, Read, Write}; +use std::io::{self, IsTerminal, Read, Write}; use std::panic::{self, catch_unwind}; use std::path::PathBuf; use std::process::{self, Command, Stdio}; @@ -538,7 +538,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) { } text.push('\n'); } - if stdout_isatty() { + if io::stdout().is_terminal() { show_content_with_pager(&text); } else { print!("{}", text); From d60ba29b10e2c4741bbd8701c74b85c09b70e03d Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:55:44 +0100 Subject: [PATCH 3/4] Use IsTerminal in rustc_log --- Cargo.lock | 1 - compiler/rustc_log/Cargo.toml | 1 - compiler/rustc_log/src/lib.rs | 7 ++++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c0bb32dec71e..bf5ff830acc47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3724,7 +3724,6 @@ dependencies = [ name = "rustc_log" version = "0.0.0" dependencies = [ - "atty", "rustc_span", "tracing", "tracing-subscriber", diff --git a/compiler/rustc_log/Cargo.toml b/compiler/rustc_log/Cargo.toml index 1b2cde605556d..3c50827c1abc3 100644 --- a/compiler/rustc_log/Cargo.toml +++ b/compiler/rustc_log/Cargo.toml @@ -4,7 +4,6 @@ version = "0.0.0" edition = "2021" [dependencies] -atty = "0.2" tracing = "0.1.28" tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] } tracing-tree = "0.2.0" diff --git a/compiler/rustc_log/src/lib.rs b/compiler/rustc_log/src/lib.rs index 458f5e87baeac..ddf29c488c933 100644 --- a/compiler/rustc_log/src/lib.rs +++ b/compiler/rustc_log/src/lib.rs @@ -40,10 +40,11 @@ #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] +#![feature(is_terminal)] use std::env::{self, VarError}; use std::fmt::{self, Display}; -use std::io; +use std::io::{self, IsTerminal}; use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter}; use tracing_subscriber::layer::SubscriberExt; @@ -93,11 +94,11 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> { } pub fn stdout_isatty() -> bool { - atty::is(atty::Stream::Stdout) + io::stdout().is_terminal() } pub fn stderr_isatty() -> bool { - atty::is(atty::Stream::Stderr) + io::stderr().is_terminal() } #[derive(Debug)] From e3d44dd4bdd901d284ec47a29e0bb7d825f9786b Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sun, 16 Oct 2022 14:56:03 +0100 Subject: [PATCH 4/4] Use IsTerminal in librustdoc --- Cargo.lock | 1 - src/librustdoc/Cargo.toml | 1 - src/librustdoc/lib.rs | 5 +++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf5ff830acc47..6630b6479dc48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4272,7 +4272,6 @@ version = "0.0.0" dependencies = [ "arrayvec", "askama", - "atty", "expect-test", "itertools", "minifier", diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 7bc35c7d5516f..63ccee14caa9d 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -9,7 +9,6 @@ path = "lib.rs" [dependencies] arrayvec = { version = "0.7", default-features = false } askama = { version = "0.11", default-features = false, features = ["config"] } -atty = "0.2" itertools = "0.10.1" minifier = "0.2.2" once_cell = "1.10.0" diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ef01b854e5a69..7276b9ce0ee7d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -8,6 +8,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(drain_filter)] +#![feature(is_terminal)] #![feature(let_chains)] #![feature(test)] #![feature(never_type)] @@ -69,7 +70,7 @@ extern crate jemalloc_sys; use std::default::Default; use std::env::{self, VarError}; -use std::io; +use std::io::{self, IsTerminal}; use std::process; use rustc_driver::abort_on_err; @@ -180,7 +181,7 @@ fn init_logging() { let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() { Ok("always") => true, Ok("never") => false, - Ok("auto") | Err(VarError::NotPresent) => atty::is(atty::Stream::Stdout), + Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(), Ok(value) => early_error( ErrorOutputType::default(), &format!("invalid log color value '{}': expected one of always, never, or auto", value),