Skip to content

Commit 4db3688

Browse files
committed
Simplify process access to stderr
1 parent fa1ecaf commit 4db3688

File tree

5 files changed

+11
-33
lines changed

5 files changed

+11
-33
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
@@ -24,7 +24,6 @@ use crate::{
2424
command,
2525
config::{new_toolchain_with_reason, ActiveReason, Cfg},
2626
currentprocess::{
27-
filesource::StderrSource,
2827
process,
2928
terminalsource::{self, ColorableTerminal},
3029
},

src/currentprocess.rs

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

@@ -82,7 +76,6 @@ pub trait CurrentProcess:
8276
CurrentProcess,
8377
CurrentDirSource,
8478
VarSource,
85-
StderrSource,
8679
StdinSource,
8780
ProcessSource
8881
)]
@@ -129,6 +122,14 @@ impl Process {
129122
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stdout.clone())),
130123
}
131124
}
125+
126+
pub(crate) fn stderr(&self) -> Box<dyn filesource::Writer> {
127+
match self {
128+
Process::OSProcess(_) => Box::new(io::stderr()),
129+
#[cfg(feature = "test")]
130+
Process::TestProcess(p) => Box::new(filesource::TestWriter(p.stderr.clone())),
131+
}
132+
}
132133
}
133134

134135
/// Obtain the current instance of CurrentProcess

src/currentprocess/filesource.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ pub trait Writer: Write + Send + Sync {
6060
fn terminal(&self) -> ColorableTerminal;
6161
}
6262

63-
// -------------- stderr -------------------------------
64-
65-
/// Stand-in for std::io::stderr.
66-
#[enum_dispatch]
67-
pub trait StderrSource {
68-
fn stderr(&self) -> Box<dyn Writer>;
69-
}
70-
7163
// ----------------- OS support for writers -----------------
7264

7365
impl WriterLock for io::StdoutLock<'_> {}
@@ -110,12 +102,6 @@ impl Writer for io::Stderr {
110102
}
111103
}
112104

113-
impl StderrSource for super::OSProcess {
114-
fn stderr(&self) -> Box<dyn Writer> {
115-
Box::new(io::stderr())
116-
}
117-
}
118-
119105
#[cfg(feature = "test")]
120106
pub(crate) use self::test_support::*;
121107

@@ -229,10 +215,4 @@ mod test_support {
229215
Ok(())
230216
}
231217
}
232-
233-
impl StderrSource for TestProcess {
234-
fn stderr(&self) -> Box<dyn Writer> {
235-
Box::new(TestWriter(self.stderr.clone()))
236-
}
237-
}
238218
}

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, process, varsource::VarSource};
14+
use crate::currentprocess::{process, 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)