From 76d468ae261bc45582588b972d6098c0edb0d698 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Thu, 9 Apr 2015 17:23:49 -0700 Subject: [PATCH] Ensure that .join().unwrap() works Makes `Any + Send` implement `Debug`. Fixes #21291 --- src/libcore/any.rs | 10 ++++++++++ src/test/run-pass/issue-21291.rs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/run-pass/issue-21291.rs diff --git a/src/libcore/any.rs b/src/libcore/any.rs index 687675f12ef..7025c76d92c 100644 --- a/src/libcore/any.rs +++ b/src/libcore/any.rs @@ -114,6 +114,16 @@ impl fmt::Debug for Any { } } +// Ensure that the result of e.g. joining a thread can be printed and +// hence used with `unwrap`. May eventually no longer be needed if +// dispatch works with upcasting. +#[stable(feature = "rust1", since = "1.0.0")] +impl fmt::Debug for Any + Send { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Any") + } +} + impl Any { /// Returns true if the boxed type is the same as `T` #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/test/run-pass/issue-21291.rs b/src/test/run-pass/issue-21291.rs new file mode 100644 index 00000000000..ec095d4895f --- /dev/null +++ b/src/test/run-pass/issue-21291.rs @@ -0,0 +1,17 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Regression test for unwrapping the result of `join`, issue #21291 + +use std::thread; + +fn main() { + thread::spawn(|| {}).join().unwrap() +}