diff options
| author | Stjepan Glavina <stjepang@gmail.com> | 2018-02-28 18:59:12 +0100 |
|---|---|---|
| committer | Stjepan Glavina <stjepang@gmail.com> | 2018-02-28 18:59:12 +0100 |
| commit | 27fae2b24af48041ceea6e04c7f217d3db372164 (patch) | |
| tree | a5359a056d41e36b704766733e8657c282cac07d /src/libstd/io | |
| parent | c99f4c4c5b9f968b82037cf643b6662b140d9b1f (diff) | |
| download | rust-27fae2b24af48041ceea6e04c7f217d3db372164.tar.gz rust-27fae2b24af48041ceea6e04c7f217d3db372164.zip | |
Remove thread_local_state
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/stdio.rs | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index f01ca18851d..b8fb83ad465 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -18,8 +18,6 @@ use sync::{Arc, Mutex, MutexGuard}; use sys::stdio; use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; use thread::LocalKey; -#[allow(deprecated)] -use thread::LocalKeyState; /// Stdout used by print! and println! macros thread_local! { @@ -670,25 +668,26 @@ pub fn set_print(sink: Option<Box<Write + Send>>) -> Option<Box<Write + Send>> { /// thread, it will just fall back to the global stream. /// /// However, if the actual I/O causes an error, this function does panic. -#[allow(deprecated)] -fn print_to<T>(args: fmt::Arguments, - local_s: &'static LocalKey<RefCell<Option<Box<Write+Send>>>>, - global_s: fn() -> T, - label: &str) where T: Write { - let result = match local_s.state() { - LocalKeyState::Uninitialized | - LocalKeyState::Destroyed => global_s().write_fmt(args), - LocalKeyState::Valid => { - local_s.with(|s| { - if let Ok(mut borrowed) = s.try_borrow_mut() { - if let Some(w) = borrowed.as_mut() { - return w.write_fmt(args); - } - } - global_s().write_fmt(args) - }) +fn print_to<T>( + args: fmt::Arguments, + local_s: &'static LocalKey<RefCell<Option<Box<Write+Send>>>>, + global_s: fn() -> T, + label: &str, +) +where + T: Write, +{ + let result = local_s.try_with(|s| { + if let Ok(mut borrowed) = s.try_borrow_mut() { + if let Some(w) = borrowed.as_mut() { + return w.write_fmt(args); + } } - }; + global_s().write_fmt(args) + }).unwrap_or_else(|_| { + global_s().write_fmt(args) + }); + if let Err(e) = result { panic!("failed printing to {}: {}", label, e); } |
