Skip to content

Commit a4c3288

Browse files
committed
Change the sigs of set_print/set_panic to allow restoring the default objects
1 parent 183b2dd commit a4c3288

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

src/librustc_driver/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
10751075
}
10761076

10771077
let thread = cfg.spawn(move || {
1078-
io::set_panic(box err);
1078+
io::set_panic(Some(box err));
10791079
f()
10801080
});
10811081

@@ -1121,7 +1121,7 @@ fn exit_on_err() -> ! {
11211121
// Panic so the process returns a failure code, but don't pollute the
11221122
// output with some unnecessary panic messages, we've already
11231123
// printed everything that we needed to.
1124-
io::set_panic(box io::sink());
1124+
io::set_panic(Some(box io::sink()));
11251125
panic!();
11261126
}
11271127

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
228228
let codemap = Rc::new(CodeMap::new());
229229
let emitter = errors::emitter::EmitterWriter::new(box Sink(data.clone()),
230230
Some(codemap.clone()));
231-
let old = io::set_panic(box Sink(data.clone()));
231+
let old = io::set_panic(Some(box Sink(data.clone())));
232232
let _bomb = Bomb(data.clone(), old.unwrap_or(box io::stdout()));
233233

234234
// Compile the code

src/libstd/io/stdio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ impl<'a> Write for StderrLock<'a> {
593593
with a more general mechanism",
594594
issue = "0")]
595595
#[doc(hidden)]
596-
pub fn set_panic(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
596+
pub fn set_panic(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> {
597597
use panicking::LOCAL_STDERR;
598598
use mem;
599599
LOCAL_STDERR.with(move |slot| {
600-
mem::replace(&mut *slot.borrow_mut(), Some(sink))
600+
mem::replace(&mut *slot.borrow_mut(), sink)
601601
}).and_then(|mut s| {
602602
let _ = s.flush();
603603
Some(s)
@@ -617,10 +617,10 @@ pub fn set_panic(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
617617
with a more general mechanism",
618618
issue = "0")]
619619
#[doc(hidden)]
620-
pub fn set_print(sink: Box<Write + Send>) -> Option<Box<Write + Send>> {
620+
pub fn set_print(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> {
621621
use mem;
622622
LOCAL_STDOUT.with(move |slot| {
623-
mem::replace(&mut *slot.borrow_mut(), Some(sink))
623+
mem::replace(&mut *slot.borrow_mut(), sink)
624624
}).and_then(|mut s| {
625625
let _ = s.flush();
626626
Some(s)

src/libtest/lib.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ pub fn run_test(opts: &TestOpts,
12001200

12011201
let result_guard = cfg.spawn(move || {
12021202
if !nocapture {
1203-
io::set_print(box Sink(data2.clone()));
1204-
io::set_panic(box Sink(data2));
1203+
io::set_print(Some(box Sink(data2.clone())));
1204+
io::set_panic(Some(box Sink(data2)));
12051205
}
12061206
testfn()
12071207
})
@@ -1213,8 +1213,8 @@ pub fn run_test(opts: &TestOpts,
12131213
} else {
12141214
let oldio = if !nocapture {
12151215
Some((
1216-
io::set_print(box Sink(data2.clone())),
1217-
io::set_panic(box Sink(data2))
1216+
io::set_print(Some(box Sink(data2.clone()))),
1217+
io::set_panic(Some(box Sink(data2)))
12181218
))
12191219
} else {
12201220
None
@@ -1227,12 +1227,8 @@ pub fn run_test(opts: &TestOpts,
12271227
}));
12281228

12291229
if let Some((printio, panicio)) = oldio {
1230-
if let Some(printio) = printio {
1231-
io::set_print(printio);
1232-
}
1233-
if let Some(panicio) = panicio {
1234-
io::set_panic(panicio);
1235-
}
1230+
io::set_print(printio);
1231+
io::set_panic(panicio);
12361232
};
12371233

12381234
let test_result = calc_result(&desc, result);

src/test/run-pass/task-stderr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
let data = Arc::new(Mutex::new(Vec::new()));
3131
let sink = Sink(data.clone());
3232
let res = thread::Builder::new().spawn(move|| -> () {
33-
io::set_panic(Box::new(sink));
33+
io::set_panic(Some(Box::new(sink)));
3434
panic!("Hello, world!")
3535
}).unwrap().join();
3636
assert!(res.is_err());

0 commit comments

Comments
 (0)