Skip to content

Commit 52cc0d5

Browse files
authored
Rollup merge of #103117 - joshtriplett:use-is-terminal, r=eholk
Use `IsTerminal` in place of `atty` In any crate that can use nightly features, use `IsTerminal` rather than `atty`: - Use `IsTerminal` in `rustc_errors` - Use `IsTerminal` in `rustc_driver` - Use `IsTerminal` in `rustc_log` - Use `IsTerminal` in `librustdoc`
2 parents 5e6de23 + e3d44dd commit 52cc0d5

File tree

9 files changed

+14
-17
lines changed

9 files changed

+14
-17
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -3535,7 +3535,6 @@ name = "rustc_errors"
35353535
version = "0.0.0"
35363536
dependencies = [
35373537
"annotate-snippets",
3538-
"atty",
35393538
"rustc_ast",
35403539
"rustc_ast_pretty",
35413540
"rustc_data_structures",
@@ -3834,7 +3833,6 @@ dependencies = [
38343833
name = "rustc_log"
38353834
version = "0.0.0"
38363835
dependencies = [
3837-
"atty",
38383836
"rustc_span",
38393837
"tracing",
38403838
"tracing-subscriber",
@@ -4389,7 +4387,6 @@ version = "0.0.0"
43894387
dependencies = [
43904388
"arrayvec",
43914389
"askama",
4392-
"atty",
43934390
"expect-test",
43944391
"itertools",
43954392
"minifier",

compiler/rustc_driver/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! This API is completely unstable and subject to change.
66
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
8+
#![feature(is_terminal)]
89
#![feature(once_cell)]
910
#![feature(decl_macro)]
1011
#![recursion_limit = "256"]
@@ -27,7 +28,6 @@ use rustc_feature::find_gated_cfg;
2728
use rustc_interface::util::{self, collect_crate_types, get_codegen_backend};
2829
use rustc_interface::{interface, Queries};
2930
use rustc_lint::LintStore;
30-
use rustc_log::stdout_isatty;
3131
use rustc_metadata::locator;
3232
use rustc_save_analysis as save;
3333
use rustc_save_analysis::DumpHandler;
@@ -48,7 +48,7 @@ use std::default::Default;
4848
use std::env;
4949
use std::ffi::OsString;
5050
use std::fs;
51-
use std::io::{self, Read, Write};
51+
use std::io::{self, IsTerminal, Read, Write};
5252
use std::panic::{self, catch_unwind};
5353
use std::path::PathBuf;
5454
use std::process::{self, Command, Stdio};
@@ -515,7 +515,7 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
515515
}
516516
text.push('\n');
517517
}
518-
if stdout_isatty() {
518+
if io::stdout().is_terminal() {
519519
show_content_with_pager(&text);
520520
} else {
521521
print!("{}", text);

compiler/rustc_errors/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target" }
1818
rustc_hir = { path = "../rustc_hir" }
1919
rustc_lint_defs = { path = "../rustc_lint_defs" }
2020
unicode-width = "0.1.4"
21-
atty = "0.2"
2221
termcolor = "1.0"
2322
annotate-snippets = "0.9"
2423
termize = "0.1.1"

compiler/rustc_errors/src/emitter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use rustc_error_messages::FluentArgs;
2828
use rustc_span::hygiene::{ExpnKind, MacroKind};
2929
use std::borrow::Cow;
3030
use std::cmp::{max, min, Reverse};
31-
use std::io;
3231
use std::io::prelude::*;
32+
use std::io::{self, IsTerminal};
3333
use std::iter;
3434
use std::path::Path;
3535
use termcolor::{Ansi, BufferWriter, ColorChoice, ColorSpec, StandardStream};
@@ -619,14 +619,14 @@ impl ColorConfig {
619619
fn to_color_choice(self) -> ColorChoice {
620620
match self {
621621
ColorConfig::Always => {
622-
if atty::is(atty::Stream::Stderr) {
622+
if io::stderr().is_terminal() {
623623
ColorChoice::Always
624624
} else {
625625
ColorChoice::AlwaysAnsi
626626
}
627627
}
628628
ColorConfig::Never => ColorChoice::Never,
629-
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => ColorChoice::Auto,
629+
ColorConfig::Auto if io::stderr().is_terminal() => ColorChoice::Auto,
630630
ColorConfig::Auto => ColorChoice::Never,
631631
}
632632
}

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
66
#![feature(drain_filter)]
77
#![feature(if_let_guard)]
8+
#![feature(is_terminal)]
89
#![feature(adt_const_params)]
910
#![feature(let_chains)]
1011
#![feature(never_type)]

compiler/rustc_log/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
atty = "0.2"
87
tracing = "0.1.28"
98
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
109
tracing-tree = "0.2.0"

compiler/rustc_log/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@
4040
4141
#![deny(rustc::untranslatable_diagnostic)]
4242
#![deny(rustc::diagnostic_outside_of_impl)]
43+
#![feature(is_terminal)]
4344

4445
use std::env::{self, VarError};
4546
use std::fmt::{self, Display};
46-
use std::io;
47+
use std::io::{self, IsTerminal};
4748
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
4849
use tracing_subscriber::layer::SubscriberExt;
4950

@@ -93,11 +94,11 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
9394
}
9495

9596
pub fn stdout_isatty() -> bool {
96-
atty::is(atty::Stream::Stdout)
97+
io::stdout().is_terminal()
9798
}
9899

99100
pub fn stderr_isatty() -> bool {
100-
atty::is(atty::Stream::Stderr)
101+
io::stderr().is_terminal()
101102
}
102103

103104
#[derive(Debug)]

src/librustdoc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ path = "lib.rs"
99
[dependencies]
1010
arrayvec = { version = "0.7", default-features = false }
1111
askama = { version = "0.11", default-features = false, features = ["config"] }
12-
atty = "0.2"
1312
itertools = "0.10.1"
1413
minifier = "0.2.2"
1514
once_cell = "1.10.0"

src/librustdoc/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(box_patterns)]
99
#![feature(control_flow_enum)]
1010
#![feature(drain_filter)]
11+
#![feature(is_terminal)]
1112
#![feature(let_chains)]
1213
#![feature(test)]
1314
#![feature(never_type)]
@@ -69,7 +70,7 @@ extern crate jemalloc_sys;
6970

7071
use std::default::Default;
7172
use std::env::{self, VarError};
72-
use std::io;
73+
use std::io::{self, IsTerminal};
7374
use std::process;
7475

7576
use rustc_driver::abort_on_err;
@@ -179,7 +180,7 @@ fn init_logging() {
179180
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
180181
Ok("always") => true,
181182
Ok("never") => false,
182-
Ok("auto") | Err(VarError::NotPresent) => atty::is(atty::Stream::Stdout),
183+
Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(),
183184
Ok(value) => early_error(
184185
ErrorOutputType::default(),
185186
&format!("invalid log color value '{}': expected one of always, never, or auto", value),

0 commit comments

Comments
 (0)