Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #75683

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift click to select a range
e720f42
See also X-Link mem::{swap, take, replace}
Havvy Aug 2, 2020
7835c8c
docs(marker/copy): clarify that `&T` is also `Copy`
janriemer Aug 2, 2020
9b0f3d1
Fix documentation error
jack-champagne Aug 13, 2020
a876b3d
docs(marker/copy): provide example for `&T` being `Copy`
janriemer Aug 16, 2020
43dec0e
rephrase: struct -> type
janriemer Aug 16, 2020
dce8644
add back emojis that have been removed accidentally
janriemer Aug 16, 2020
9061da2
add empty line above code block
janriemer Aug 16, 2020
56daf63
docs: add `derive` for struct
janriemer Aug 16, 2020
3b2c0a9
Minor changes to Ipv4Addr
tesuji Aug 14, 2020
b0eb55a
Add test demonstrating the issue.
jumbatm Aug 15, 2020
db75313
Fix stack overflow for recursive types.
jumbatm Aug 15, 2020
154b74e
Actually introduce a cycle in Reffy test.
jumbatm Aug 16, 2020
a1fa4e0
Remove unnecessary rebinding of def ids.
jumbatm Aug 16, 2020
80c2c80
Remove structural equiv check for Array const.
jumbatm Aug 16, 2020
bca48ad
Reduce indentation by replacing match arm w/ early return.
jumbatm Aug 16, 2020
6c57de1
Don't memoize seen types.
jumbatm Aug 16, 2020
7708abb
Avoid double hashset lookup.
jumbatm Aug 16, 2020
1321a2d
Also accept Refs for is_primitive_or_pointer
jumbatm Aug 16, 2020
bc15dd6
Wrap recursion in `ensure_sufficient_stack`.
jumbatm Aug 17, 2020
431a465
Move to intra doc links for keyword documentation
poliorcetics Aug 17, 2020
a4995fc
Refactor `impl_for_type` into a separate function
jyn514 Aug 17, 2020
833bbb1
Say `tcx.lang_items()` less
jyn514 Aug 17, 2020
dae3a4f
Return all impls, not just the primary one
jyn514 Aug 17, 2020
c6ac860
impl_for_type -> PrimitiveType::impls
jyn514 Aug 17, 2020
3b1d2e3
Allow reusing the code in `collect_trait_impls`
jyn514 Aug 17, 2020
1b74f04
Use `impls` for intra doc links as well
jyn514 Aug 17, 2020
2858074
xpy fmt
jyn514 Aug 17, 2020
7be824e
Add a test
jyn514 Aug 17, 2020
38b920d
Capture output from threads spawned in tests
tmandry Aug 5, 2020
8c4641b
BTreeMap: check some invariants, avoid recursion in depth first search
ssomers Aug 18, 2020
d9d84dc
Add doc examples count for --show-coverage
GuillaumeGomez Aug 18, 2020
f957bae
Update rustdoc-ui tests
GuillaumeGomez Aug 18, 2020
522d177
docs: add another `derive` for `Copy`able struct
Aug 18, 2020
9a8e3d8
Rollup merge of #75038 - rust-lang:Havvy-patch-1, r=steveklabnik
tmandry Aug 18, 2020
7b4ff26
Rollup merge of #75049 - janriemer:patch-1, r=poliorcetics
tmandry Aug 18, 2020
81f62a9
Rollup merge of #75110 - lzutao:ip-endianness, r=Mark-Simulacrum
tmandry Aug 18, 2020
ad4610d
Rollup merge of #75172 - tmandry:test-thread-capture, r=dtolnay
tmandry Aug 18, 2020
816e701
Rollup merge of #75480 - ssomers:btree_check_invariant, r=Mark-Simula…
tmandry Aug 18, 2020
bc4b517
Rollup merge of #75499 - jack-champagne:jack-champagne/issue-75412, r…
tmandry Aug 18, 2020
7e283e9
Rollup merge of #75554 - jumbatm:fix-clashing-extern-decl-overflow, r…
tmandry Aug 18, 2020
7e09c7e
Rollup merge of #75646 - poliorcetics:intra-links-keywords, r=jyn514
tmandry Aug 18, 2020
9360e87
Rollup merge of #75649 - jyn514:inherent-lang-impls, r=GuillaumeGomez
tmandry Aug 18, 2020
2a5b4b2
Rollup merge of #75665 - GuillaumeGomez:doc-examples-coverage, r=jyn514
tmandry Aug 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Capture output from threads spawned in tests
Fixes #42474.
  • Loading branch information
tmandry committed Aug 18, 2020
commit 38b920d16f092b9d8142a075ab1a3552567db9b5
6 changes: 3 additions & 3 deletions library/std/src/io/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 210,13 @@ impl<B: BufRead ?Sized> BufRead for Box<B> {
#[cfg(test)]
/// This impl is only used by printing logic, so any error returned is always
/// of kind `Other`, and should be ignored.
impl Write for Box<dyn (::realstd::io::Write) Send> {
impl Write for dyn ::realstd::io::LocalOutput {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
(**self).write(buf).map_err(|_| ErrorKind::Other.into())
(*self).write(buf).map_err(|_| ErrorKind::Other.into())
}

fn flush(&mut self) -> io::Result<()> {
(**self).flush().map_err(|_| ErrorKind::Other.into())
(*self).flush().map_err(|_| ErrorKind::Other.into())
}
}

Expand Down
4 changes: 3 additions & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 274,12 @@ pub use self::stdio::{StderrLock, StdinLock, StdoutLock};
pub use self::stdio::{_eprint, _print};
#[unstable(feature = "libstd_io_internals", issue = "42788")]
#[doc(no_inline, hidden)]
pub use self::stdio::{set_panic, set_print};
pub use self::stdio::{set_panic, set_print, LocalOutput};
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::util::{copy, empty, repeat, sink, Empty, Repeat, Sink};

pub(crate) use self::stdio::clone_io;

mod buffered;
mod cursor;
mod error;
Expand Down
33 changes: 28 additions & 5 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 13,14 @@ use crate::thread::LocalKey;

thread_local! {
/// Stdout used by print! and println! macros
static LOCAL_STDOUT: RefCell<Option<Box<dyn Write Send>>> = {
static LOCAL_STDOUT: RefCell<Option<Box<dyn LocalOutput>>> = {
RefCell::new(None)
}
}

thread_local! {
/// Stderr used by eprint! and eprintln! macros, and panics
static LOCAL_STDERR: RefCell<Option<Box<dyn Write Send>>> = {
static LOCAL_STDERR: RefCell<Option<Box<dyn LocalOutput>>> = {
RefCell::new(None)
}
}
Expand Down Expand Up @@ -903,6 903,18 @@ impl fmt::Debug for StderrLock<'_> {
}
}

/// A writer than can be cloned to new threads.
#[unstable(
feature = "set_stdio",
reason = "this trait may disappear completely or be replaced \
with a more general mechanism",
issue = "none"
)]
#[doc(hidden)]
pub trait LocalOutput: Write Send {
fn clone_box(&self) -> Box<dyn LocalOutput>;
}

/// Resets the thread-local stderr handle to the specified writer
///
/// This will replace the current thread's stderr handle, returning the old
Expand All @@ -918,7 930,7 @@ impl fmt::Debug for StderrLock<'_> {
issue = "none"
)]
#[doc(hidden)]
pub fn set_panic(sink: Option<Box<dyn Write Send>>) -> Option<Box<dyn Write Send>> {
pub fn set_panic(sink: Option<Box<dyn LocalOutput>>) -> Option<Box<dyn LocalOutput>> {
use crate::mem;
LOCAL_STDERR.with(move |slot| mem::replace(&mut *slot.borrow_mut(), sink)).and_then(|mut s| {
let _ = s.flush();
Expand All @@ -941,14 953,25 @@ pub fn set_panic(sink: Option<Box<dyn Write Send>>) -> Option<Box<dyn Write
issue = "none"
)]
#[doc(hidden)]
pub fn set_print(sink: Option<Box<dyn Write Send>>) -> Option<Box<dyn Write Send>> {
pub fn set_print(sink: Option<Box<dyn LocalOutput>>) -> Option<Box<dyn LocalOutput>> {
use crate::mem;
LOCAL_STDOUT.with(move |slot| mem::replace(&mut *slot.borrow_mut(), sink)).and_then(|mut s| {
let _ = s.flush();
Some(s)
})
}

pub(crate) fn clone_io() -> (Option<Box<dyn LocalOutput>>, Option<Box<dyn LocalOutput>>) {
LOCAL_STDOUT.with(|stdout| {
LOCAL_STDERR.with(|stderr| {
(
stdout.borrow().as_ref().map(|o| o.clone_box()),
stderr.borrow().as_ref().map(|o| o.clone_box()),
)
})
})
}

/// Write `args` to output stream `local_s` if possible, `global_s`
/// otherwise. `label` identifies the stream in a panic message.
///
Expand All @@ -961,7 984,7 @@ pub fn set_print(sink: Option<Box<dyn Write Send>>) -> Option<Box<dyn Write
/// However, if the actual I/O causes an error, this function does panic.
fn print_to<T>(
args: fmt::Arguments<'_>,
local_s: &'static LocalKey<RefCell<Option<Box<dyn Write Send>>>>,
local_s: &'static LocalKey<RefCell<Option<Box<dyn LocalOutput>>>>,
global_s: fn() -> T,
label: &str,
) where
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 210,7 @@ fn default_hook(info: &PanicInfo<'_>) {

if let Some(mut local) = set_panic(None) {
// NB. In `cfg(test)` this uses the forwarding impl
// for `Box<dyn (::realstd::io::Write) Send>`.
// for `dyn ::realstd::io::LocalOutput`.
write(&mut local);
set_panic(Some(local));
} else if let Some(mut out) = panic_output() {
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 465,16 @@ impl Builder {
let my_packet: Arc<UnsafeCell<Option<Result<T>>>> = Arc::new(UnsafeCell::new(None));
let their_packet = my_packet.clone();

let (stdout, stderr) = crate::io::clone_io();

let main = move || {
if let Some(name) = their_thread.cname() {
imp::Thread::set_name(name);
}

crate::io::set_print(stdout);
crate::io::set_panic(stderr);

thread_info::set(imp::guard::current(), their_thread);
let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
crate::sys_common::backtrace::__rust_begin_short_backtrace(f)
Expand Down
7 changes: 7 additions & 0 deletions library/test/src/helpers/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,7 @@ use std::{
sync::{Arc, Mutex},
};

#[derive(Clone)]
pub struct Sink(Arc<Mutex<Vec<u8>>>);

impl Sink {
Expand All @@ -14,6 15,12 @@ impl Sink {
}
}

impl io::LocalOutput for Sink {
fn clone_box(&self) -> Box<dyn io::LocalOutput> {
Box::new(Self(self.0.clone()))
}
}

impl Write for Sink {
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
Write::write(&mut *self.0.lock().unwrap(), data)
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 100,11 @@ impl Write for Sink {
Ok(())
}
}
impl io::LocalOutput for Sink {
fn clone_box(&self) -> Box<dyn io::LocalOutput> {
Box::new(Self(self.0.clone()))
}
}

/// Like a `thread::Builder::spawn` followed by a `join()`, but avoids the need
/// for `'static` bounds.
Expand Down
19 changes: 17 additions & 2 deletions src/test/ui/panic-while-printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 5,7 @@

use std::fmt;
use std::fmt::{Display, Formatter};
use std::io::set_panic;
use std::io::{self, set_panic, LocalOutput, Write};

pub struct A;

Expand All @@ -15,8 15,23 @@ impl Display for A {
}
}

struct Sink;
impl Write for Sink {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
impl LocalOutput for Sink {
fn clone_box(&self) -> Box<dyn LocalOutput> {
Box::new(Sink)
}
}

fn main() {
set_panic(Some(Box::new(Vec::new())));
set_panic(Some(Box::new(Sink)));
assert!(std::panic::catch_unwind(|| {
eprintln!("{}", A);
})
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/test-thread-capture.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,30 @@
// compile-flags: --test
// run-fail
// run-flags: --test-threads=1
// check-run-results
// exec-env:RUST_BACKTRACE=0

#[test]
fn thready_pass() {
println!("fee");
std::thread::spawn(|| {
println!("fie");
println!("foe");
})
.join()
.unwrap();
println!("fum");
}

#[test]
fn thready_fail() {
println!("fee");
std::thread::spawn(|| {
println!("fie");
println!("foe");
})
.join()
.unwrap();
println!("fum");
panic!();
}
21 changes: 21 additions & 0 deletions src/test/ui/test-thread-capture.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 1,21 @@

running 2 tests
test thready_fail ... FAILED
test thready_pass ... ok

failures:

---- thready_fail stdout ----
fee
fie
foe
fum
thread 'main' panicked at 'explicit panic', $DIR/test-thread-capture.rs:29:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
thready_fail

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

30 changes: 30 additions & 0 deletions src/test/ui/test-thread-nocapture.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,30 @@
// compile-flags: --test
// run-fail
// run-flags: --test-threads=1 --nocapture
// check-run-results
// exec-env:RUST_BACKTRACE=0

#[test]
fn thready_pass() {
println!("fee");
std::thread::spawn(|| {
println!("fie");
println!("foe");
})
.join()
.unwrap();
println!("fum");
}

#[test]
fn thready_fail() {
println!("fee");
std::thread::spawn(|| {
println!("fie");
println!("foe");
})
.join()
.unwrap();
println!("fum");
panic!();
}
2 changes: 2 additions & 0 deletions src/test/ui/test-thread-nocapture.run.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,2 @@
thread 'main' panicked at 'explicit panic', $DIR/test-thread-nocapture.rs:29:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
20 changes: 20 additions & 0 deletions src/test/ui/test-thread-nocapture.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 1,20 @@

running 2 tests
test thready_fail ... fee
fie
foe
fum
FAILED
test thready_pass ... fee
fie
foe
fum
ok

failures:

failures:
thready_fail

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

5 changes: 5 additions & 0 deletions src/test/ui/threads-sendsync/task-stderr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 16,11 @@ impl Write for Sink {
}
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}
impl io::LocalOutput for Sink {
fn clone_box(&self) -> Box<dyn io::LocalOutput> {
Box::new(Sink(self.0.clone()))
}
}

fn main() {
let data = Arc::new(Mutex::new(Vec::new()));
Expand Down