diff options
| author | Lee Bousfield <ljbousfield@gmail.com> | 2017-07-11 11:04:19 -0400 |
|---|---|---|
| committer | Lee Bousfield <ljbousfield@gmail.com> | 2017-07-11 11:04:19 -0400 |
| commit | 8b5549defb629210a8ffc1af08b3209e084fbfd8 (patch) | |
| tree | 95bed7600a6ff2e3425884c6feb63f16d54f3da3 /src/libstd | |
| parent | a45c8b09e86ea4eed283a6163b44c493d15ee5c3 (diff) | |
| download | rust-8b5549defb629210a8ffc1af08b3209e084fbfd8.tar.gz rust-8b5549defb629210a8ffc1af08b3209e084fbfd8.zip | |
Fix @alexcrichton comments
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/stdio.rs | 22 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 2 |
2 files changed, 15 insertions, 9 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index d71fa133454..fb489bf487b 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -17,7 +17,7 @@ use io::{self, Initializer, BufReader, LineWriter}; use sync::{Arc, Mutex, MutexGuard}; use sys::stdio; use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard}; -use thread::LocalKey; +use thread::{LocalKey, LocalKeyState}; /// Stdout used by print! and println! macros thread_local! { @@ -674,14 +674,20 @@ 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); - } + 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) + }) } - global_s().write_fmt(args) - }).unwrap_or_else(|_| global_s().write_fmt(args)); + }; if let Err(e) = result { panic!("failed printing to {}: {}", label, e); } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index f4fe52ca3b3..07a3a01ce86 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -159,7 +159,7 @@ use time::Duration; #[macro_use] mod local; #[stable(feature = "rust1", since = "1.0.0")] -pub use self::local::{LocalKey, LocalKeyState}; +pub use self::local::{LocalKey, LocalKeyState, AccessError}; // The types used by the thread_local! macro to access TLS keys. Note that there // are two types, the "OS" type and the "fast" type. The OS thread local key |
