Skip to content

Commit 62ea0c8

Browse files
committed
Auto merge of #2144 - matthiaskrgr:stderrfix, r=RalfJung
mute_stdout_stderr: mute stderr instead of stdin should fix #2143 note: this is entirely untested, I was getting tons of errors on `cargo test` because of some missing setup. I hope that CI can tell me if this works or not 🙈 r? `@oli-obk`
2 parents e3227cf + 89da571 commit 62ea0c8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/shims/posix/fs.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ trait FileDescriptor: std::fmt::Debug {
3131
communicate_allowed: bool,
3232
bytes: &mut [u8],
3333
) -> InterpResult<'tcx, io::Result<usize>>;
34+
3435
fn write<'tcx>(
3536
&self,
3637
communicate_allowed: bool,
3738
bytes: &[u8],
3839
) -> InterpResult<'tcx, io::Result<usize>>;
40+
3941
fn seek<'tcx>(
4042
&mut self,
4143
communicate_allowed: bool,
4244
offset: SeekFrom,
4345
) -> InterpResult<'tcx, io::Result<u64>>;
46+
4447
fn close<'tcx>(
4548
self: Box<Self>,
4649
_communicate_allowed: bool,
@@ -304,14 +307,14 @@ pub struct FileHandler {
304307
impl<'tcx> FileHandler {
305308
pub(crate) fn new(mute_stdout_stderr: bool) -> FileHandler {
306309
let mut handles: BTreeMap<_, Box<dyn FileDescriptor>> = BTreeMap::new();
310+
handles.insert(0i32, Box::new(io::stdin()));
307311
if mute_stdout_stderr {
308-
handles.insert(0i32, Box::new(DummyOutput));
309312
handles.insert(1i32, Box::new(DummyOutput));
313+
handles.insert(2i32, Box::new(DummyOutput));
310314
} else {
311-
handles.insert(0i32, Box::new(io::stdin()));
312315
handles.insert(1i32, Box::new(io::stdout()));
316+
handles.insert(2i32, Box::new(io::stderr()));
313317
}
314-
handles.insert(2i32, Box::new(io::stderr()));
315318
FileHandler { handles }
316319
}
317320

tests/run-pass/hide_stdout.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-flags: -Zmiri-mute-stdout-stderr
22

33
fn main() {
4-
println!("cake");
4+
println!("print to stdout");
5+
eprintln!("print to stderr");
56
}

0 commit comments

Comments
 (0)