From cb56b2d1522e83c5bb0613abcf78b686e994df9e Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 1 Mar 2018 00:07:27 +0100 Subject: [PATCH] Fix a bug introduced in previous commit --- src/libstd/io/stdio.rs | 4 ++-- src/libstd/thread/local.rs | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index b8fb83ad4659..1f73054e3bee 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -663,8 +663,8 @@ pub fn set_print(sink: Option>) -> Option> { /// /// This function is used to print error messages, so it takes extra /// care to avoid causing a panic when `local_stream` is unusable. -/// For instance, if the TLS key for the local stream is uninitialized -/// or already destroyed, or if the local stream is locked by another +/// For instance, if the TLS key for the local stream is +/// already destroyed, or if the local stream is locked by another /// thread, it will just fall back to the global stream. /// /// However, if the actual I/O causes an error, this function does panic. diff --git a/src/libstd/thread/local.rs b/src/libstd/thread/local.rs index 25fedcb27726..99479bc56eff 100644 --- a/src/libstd/thread/local.rs +++ b/src/libstd/thread/local.rs @@ -272,7 +272,7 @@ impl LocalKey { /// /// This will lazily initialize the value if this thread has not referenced /// this key yet. If the key has been destroyed (which may happen if this is called - /// in a destructor), this function will return a ThreadLocalError. + /// in a destructor), this function will return a `ThreadLocalError`. /// /// # Panics /// @@ -484,11 +484,7 @@ mod tests { assert!(FOO.try_with(|_| ()).is_err()); } } - fn foo() -> Foo { - assert!(FOO.try_with(|_| ()).is_err()); - Foo - } - thread_local!(static FOO: Foo = foo()); + thread_local!(static FOO: Foo = Foo); thread::spawn(|| { assert!(FOO.try_with(|_| ()).is_ok()); @@ -520,6 +516,7 @@ mod tests { impl Drop for S1 { fn drop(&mut self) { unsafe { + HITS += 1; if K2.try_with(|_| ()).is_err() { assert_eq!(HITS, 3); } else {