Skip to content

Commit 648af17

Browse files
committed
Simplify process access to stderr
1 parent 9fcb23f commit 648af17

File tree

5 files changed

+11
-34
lines changed

5 files changed

+11
-34
lines changed

src/cli/log.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::fmt;
22
use std::io::Write;
33

4-
use crate::currentprocess::{
5-
filesource::StderrSource, process, terminalsource, varsource::VarSource,
6-
};
4+
use crate::currentprocess::{process, terminalsource, varsource::VarSource};
75

86
macro_rules! warn {
97
( $ ( $ arg : tt ) * ) => ( $crate::cli::log::warn_fmt ( format_args ! ( $ ( $ arg ) * ) ) )

src/cli/rustup_mode.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::{
2020
topical_doc,
2121
},
2222
command,
23-
currentprocess::filesource::StderrSource,
2423
dist::{
2524
dist::{PartialToolchainDesc, Profile, TargetTriple},
2625
manifest::{Component, ComponentStatus},

src/currentprocess.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ use varsource::*;
6565
/// and even there we should be doing debouncing and managing update rates).
6666
#[enum_dispatch]
6767
pub trait CurrentProcess:
68-
home::Env
69-
+ CurrentDirSource
70-
+ VarSource
71-
+ StderrSource
72-
+ StdinSource
73-
+ ProcessSource
74-
+ Debug
68+
home::Env + CurrentDirSource + VarSource + StdinSource + ProcessSource + Debug
7569
{
7670
}
7771

@@ -81,7 +75,6 @@ pub trait CurrentProcess:
8175
CurrentProcess,
8276
CurrentDirSource,
8377
VarSource,
84-
StderrSource,
8578
StdinSource,
8679
ProcessSource
8780
)]
@@ -128,6 +121,14 @@ impl Process {
128121
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stdout.clone())),
129122
}
130123
}
124+
125+
pub(crate) fn stderr(&self) -> Box<dyn filesource::Writer> {
126+
match self {
127+
Process::OSProcess(_) => Box::new(io::stderr()),
128+
#[cfg(feature = "test")]
129+
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stderr.clone())),
130+
}
131+
}
131132
}
132133

133134
/// Obtain the current instance of CurrentProcess

src/currentprocess/filesource.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ pub trait Writer: Write + Send + Sync {
107107
fn terminal(&self) -> ColorableTerminal;
108108
}
109109

110-
// -------------- stderr -------------------------------
111-
112-
/// Stand-in for std::io::stderr.
113-
#[enum_dispatch]
114-
pub trait StderrSource {
115-
fn stderr(&self) -> Box<dyn Writer>;
116-
}
117-
118110
// ----------------- OS support for writers -----------------
119111

120112
impl WriterLock for io::StdoutLock<'_> {}
@@ -157,12 +149,6 @@ impl Writer for io::Stderr {
157149
}
158150
}
159151

160-
impl StderrSource for super::OSProcess {
161-
fn stderr(&self) -> Box<dyn Writer> {
162-
Box::new(io::stderr())
163-
}
164-
}
165-
166152
// ----------------------- test support for writers ------------------
167153

168154
pub(super) struct TestWriterLock<'a> {
@@ -224,10 +210,3 @@ impl Write for TestWriter {
224210
Ok(())
225211
}
226212
}
227-
228-
#[cfg(feature = "test")]
229-
impl StderrSource for super::TestProcess {
230-
fn stderr(&self) -> Box<dyn Writer> {
231-
Box::new(TestWriter(self.stderr.clone()))
232-
}
233-
}

src/dist/component/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};
1111
use anyhow::{anyhow, bail, Context, Result};
1212
use tar::EntryType;
1313

14-
use crate::currentprocess::{filesource::StderrSource, varsource::VarSource};
14+
use crate::currentprocess::varsource::VarSource;
1515
use crate::diskio::{get_executor, CompletedIo, Executor, FileBuffer, Item, Kind, IO_CHUNK_SIZE};
1616
use crate::dist::component::components::*;
1717
use crate::dist::component::transaction::*;

0 commit comments

Comments
 (0)