Skip to content

Commit

Permalink
Unrolled build for rust-lang#129494
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#129494 - tshepang:fmt-threads-sendsync, r=Nadrieril

format code in tests/ui/threads-sendsync

was thinking of fixing formatting for 1 test in the directory, but found a bunch of them to also be in need
  • Loading branch information
rust-timer authored Aug 29, 2024
2 parents acb4e8b + 70ba8c1 commit c881c4e
Show file tree
Hide file tree
Showing 54 changed files with 315 additions and 247 deletions.
4 changes: 2 additions & 2 deletions tests/ui/threads-sendsync/child-outlives-parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use std::thread;

fn child2(_s: String) { }
fn child2(_s: String) {}

pub fn main() {
let _x = thread::spawn(move|| child2("hi".to_string()));
let _x = thread::spawn(move || child2("hi".to_string()));
}
9 changes: 5 additions & 4 deletions tests/ui/threads-sendsync/clone-with-exterior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use std::thread;

struct Pair {
a: isize,
b: isize
b: isize,
}

pub fn main() {
let z: Box<_> = Box::new(Pair { a : 10, b : 12});
let z: Box<_> = Box::new(Pair { a: 10, b: 12 });

thread::spawn(move|| {
thread::spawn(move || {
assert_eq!(z.a, 10);
assert_eq!(z.b, 12);
}).join();
})
.join();
}
4 changes: 2 additions & 2 deletions tests/ui/threads-sendsync/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#![allow(unused_must_use)]
//@ needs-threads

use std::thread;
use std::sync::mpsc::{channel, Sender};
use std::thread;

pub fn main() {
let (tx, rx) = channel();
let t = thread::spawn(move || { child(&tx) });
let t = thread::spawn(move || child(&tx));
let y = rx.recv().unwrap();
println!("received");
println!("{}", y);
Expand Down
14 changes: 8 additions & 6 deletions tests/ui/threads-sendsync/issue-24313.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
//@ needs-threads
//@ ignore-sgx no processes

use std::thread;
use std::env;
use std::process::Command;
use std::{env, thread};

struct Handle(i32);

impl Drop for Handle {
fn drop(&mut self) { panic!(); }
fn drop(&mut self) {
panic!();
}
}

thread_local!(static HANDLE: Handle = Handle(0));
Expand All @@ -19,14 +20,15 @@ fn main() {
if args.len() == 1 {
let out = Command::new(&args[0]).arg("test").output().unwrap();
let stderr = std::str::from_utf8(&out.stderr).unwrap();
assert!(stderr.contains("explicit panic"),
"bad failure message:\n{}\n", stderr);
assert!(stderr.contains("explicit panic"), "bad failure message:\n{}\n", stderr);
} else {
// TLS dtors are not always run on process exit
thread::spawn(|| {
HANDLE.with(|h| {
println!("{}", h.0);
});
}).join().unwrap();
})
.join()
.unwrap();
}
}
4 changes: 3 additions & 1 deletion tests/ui/threads-sendsync/issue-29488.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ fn main() {
thread::spawn(|| {
FOO.with(|_| {});
println!("test1");
}).join().unwrap();
})
.join()
.unwrap();
}
7 changes: 5 additions & 2 deletions tests/ui/threads-sendsync/issue-4446.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ pub fn main() {

tx.send("hello, world").unwrap();

thread::spawn(move|| {
thread::spawn(move || {
println!("{}", rx.recv().unwrap());
}).join().ok().unwrap();
})
.join()
.ok()
.unwrap();
}
2 changes: 1 addition & 1 deletion tests/ui/threads-sendsync/issue-4448.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::thread;
pub fn main() {
let (tx, rx) = channel::<&'static str>();

let t = thread::spawn(move|| {
let t = thread::spawn(move || {
assert_eq!(rx.recv().unwrap(), "hello, world");
});

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/threads-sendsync/issue-8827.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//@ run-pass
//@ needs-threads

use std::thread;
use std::sync::mpsc::{channel, Receiver};
use std::thread;

fn periodical(n: isize) -> Receiver<bool> {
let (chan, port) = channel();
thread::spawn(move|| {
thread::spawn(move || {
loop {
for _ in 1..n {
match chan.send(false) {
Expand All @@ -16,7 +16,7 @@ fn periodical(n: isize) -> Receiver<bool> {
}
match chan.send(true) {
Ok(()) => {}
Err(..) => break
Err(..) => break,
}
}
});
Expand All @@ -25,7 +25,7 @@ fn periodical(n: isize) -> Receiver<bool> {

fn integers() -> Receiver<isize> {
let (chan, port) = channel();
thread::spawn(move|| {
thread::spawn(move || {
let mut i = 1;
loop {
match chan.send(i) {
Expand All @@ -47,7 +47,7 @@ fn main() {
(_, true, true) => println!("FizzBuzz"),
(_, true, false) => println!("Fizz"),
(_, false, true) => println!("Buzz"),
(i, false, false) => println!("{}", i)
(i, false, false) => println!("{}", i),
}
}
}
6 changes: 3 additions & 3 deletions tests/ui/threads-sendsync/issue-9396.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
#![allow(deprecated)]
//@ needs-threads

use std::sync::mpsc::{TryRecvError, channel};
use std::sync::mpsc::{channel, TryRecvError};
use std::thread;

pub fn main() {
let (tx, rx) = channel();
let t = thread::spawn(move||{
let t = thread::spawn(move || {
thread::sleep_ms(10);
tx.send(()).unwrap();
});
loop {
match rx.try_recv() {
Ok(()) => break,
Err(TryRecvError::Empty) => {}
Err(TryRecvError::Disconnected) => unreachable!()
Err(TryRecvError::Disconnected) => unreachable!(),
}
}
t.join();
Expand Down
17 changes: 4 additions & 13 deletions tests/ui/threads-sendsync/mpsc_stress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
//@ compile-flags:--test
//@ needs-threads

use std::sync::mpsc::channel;
use std::sync::mpsc::TryRecvError;
use std::sync::mpsc::RecvError;
use std::sync::mpsc::RecvTimeoutError;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{channel, RecvError, RecvTimeoutError, TryRecvError};
use std::sync::Arc;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;

use std::thread;
use std::time::Duration;


/// Simple thread synchronization utility
struct Barrier {
// Not using mutex/condvar for precision
Expand Down Expand Up @@ -42,7 +36,6 @@ impl Barrier {
}
}


fn shared_close_sender_does_not_lose_messages_iter() {
let (tb, rb) = Barrier::new2();

Expand Down Expand Up @@ -71,7 +64,6 @@ fn shared_close_sender_does_not_lose_messages() {
});
}


// https://github.com/rust-lang/rust/issues/39364
fn concurrent_recv_timeout_and_upgrade_iter() {
// 1 us
Expand All @@ -85,8 +77,8 @@ fn concurrent_recv_timeout_and_upgrade_iter() {
match rx.recv_timeout(sleep) {
Ok(_) => {
break;
},
Err(_) => {},
}
Err(_) => {}
}
}
});
Expand All @@ -105,7 +97,6 @@ fn concurrent_recv_timeout_and_upgrade() {
});
}


fn concurrent_writes_iter() {
const THREADS: usize = 4;
const PER_THR: usize = 100;
Expand Down
17 changes: 7 additions & 10 deletions tests/ui/threads-sendsync/send-is-not-static-par-for.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//@ run-pass
#![allow(unused_imports)]
use std::thread;
use std::sync::Mutex;
use std::thread;

fn par_for<I, F>(iter: I, f: F)
where I: Iterator,
I::Item: Send,
F: Fn(I::Item) + Sync
where
I: Iterator,
I::Item: Send,
F: Fn(I::Item) + Sync,
{
for item in iter {
f(item)
Expand All @@ -15,9 +16,7 @@ fn par_for<I, F>(iter: I, f: F)

fn sum(x: &[i32]) {
let sum_lengths = Mutex::new(0);
par_for(x.windows(4), |x| {
*sum_lengths.lock().unwrap() += x.len()
});
par_for(x.windows(4), |x| *sum_lengths.lock().unwrap() += x.len());

assert_eq!(*sum_lengths.lock().unwrap(), (x.len() - 3) * 4);
}
Expand All @@ -26,9 +25,7 @@ fn main() {
let mut elements = [0; 20];

// iterators over references into this stack frame
par_for(elements.iter_mut().enumerate(), |(i, x)| {
*x = i as i32
});
par_for(elements.iter_mut().enumerate(), |(i, x)| *x = i as i32);

sum(&elements)
}
10 changes: 4 additions & 6 deletions tests/ui/threads-sendsync/send-resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@
//@ pretty-expanded FIXME #23616
//@ needs-threads

use std::thread;
use std::sync::mpsc::channel;
use std::thread;

struct test {
f: isize,
f: isize,
}

impl Drop for test {
fn drop(&mut self) {}
}

fn test(f: isize) -> test {
test {
f: f
}
test { f: f }
}

pub fn main() {
let (tx, rx) = channel();

let t = thread::spawn(move|| {
let t = thread::spawn(move || {
let (tx2, rx2) = channel();
tx.send(tx2).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/threads-sendsync/send-type-inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::sync::mpsc::{channel, Sender};
// tests that ctrl's type gets inferred properly
struct Command<K, V> {
key: K,
val: V
val: V,
}

fn cache_server<K:Send+'static,V:Send+'static>(mut tx: Sender<Sender<Command<K, V>>>) {
fn cache_server<K: Send + 'static, V: Send + 'static>(mut tx: Sender<Sender<Command<K, V>>>) {
let (tx1, _rx) = channel();
tx.send(tx1);
}
pub fn main() { }
pub fn main() {}
6 changes: 2 additions & 4 deletions tests/ui/threads-sendsync/send_str_hashmap.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//@ run-pass
use std::collections::HashMap;
use std::borrow::Cow;

use std::borrow::Cow::Borrowed as B;
use std::borrow::Cow::Owned as O;
use std::borrow::Cow::{Borrowed as B, Owned as O};
use std::collections::HashMap;

type SendStr = Cow<'static, str>;

Expand Down
13 changes: 6 additions & 7 deletions tests/ui/threads-sendsync/send_str_treemap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//@ run-pass
use std::collections::BTreeMap;
use std::borrow::Cow;

use std::borrow::Cow::{Owned as O, Borrowed as B};
use std::borrow::Cow::{Borrowed as B, Owned as O};
use std::collections::BTreeMap;

type SendStr = Cow<'static, str>;

Expand Down Expand Up @@ -51,8 +50,8 @@ fn main() {
assert_eq!(map.get(&O("def".to_string())), Some(&d));

assert!(map.remove(&B("foo")).is_some());
assert_eq!(map.into_iter().map(|(k, v)| format!("{}{}", k, v))
.collect::<Vec<String>>()
.concat(),
"abc50bcd51cde52def53".to_string());
assert_eq!(
map.into_iter().map(|(k, v)| format!("{}{}", k, v)).collect::<Vec<String>>().concat(),
"abc50bcd51cde52def53".to_string()
);
}
11 changes: 4 additions & 7 deletions tests/ui/threads-sendsync/sendable-class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
use std::sync::mpsc::channel;

struct foo {
i: isize,
j: char,
i: isize,
j: char,
}

fn foo(i:isize, j: char) -> foo {
foo {
i: i,
j: j
}
fn foo(i: isize, j: char) -> foo {
foo { i: i, j: j }
}

pub fn main() {
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/threads-sendsync/sendfn-is-a-block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//@ run-pass


fn test<F>(f: F) -> usize where F: FnOnce(usize) -> usize {
fn test<F>(f: F) -> usize
where
F: FnOnce(usize) -> usize,
{
return f(22);
}

Expand Down
Loading

0 comments on commit c881c4e

Please sign in to comment.