about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorStjepan Glavina <stjepang@gmail.com>2018-02-28 18:59:12 +0100
committerStjepan Glavina <stjepang@gmail.com>2018-02-28 18:59:12 +0100
commit27fae2b24af48041ceea6e04c7f217d3db372164 (patch)
treea5359a056d41e36b704766733e8657c282cac07d /src/libstd/io
parentc99f4c4c5b9f968b82037cf643b6662b140d9b1f (diff)
downloadrust-27fae2b24af48041ceea6e04c7f217d3db372164.tar.gz
rust-27fae2b24af48041ceea6e04c7f217d3db372164.zip
Remove thread_local_state
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/stdio.rs39
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);
     }