Skip to content

Commit b94887a

Browse files
Rollup merge of #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
2 parents d2418cb + 70ba8c1 commit b94887a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+315
-247
lines changed

Diff for: tests/ui/threads-sendsync/child-outlives-parent.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use std::thread;
88

9-
fn child2(_s: String) { }
9+
fn child2(_s: String) {}
1010

1111
pub fn main() {
12-
let _x = thread::spawn(move|| child2("hi".to_string()));
12+
let _x = thread::spawn(move || child2("hi".to_string()));
1313
}

Diff for: tests/ui/threads-sendsync/clone-with-exterior.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use std::thread;
77

88
struct Pair {
99
a: isize,
10-
b: isize
10+
b: isize,
1111
}
1212

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

16-
thread::spawn(move|| {
16+
thread::spawn(move || {
1717
assert_eq!(z.a, 10);
1818
assert_eq!(z.b, 12);
19-
}).join();
19+
})
20+
.join();
2021
}

Diff for: tests/ui/threads-sendsync/comm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#![allow(unused_must_use)]
33
//@ needs-threads
44

5-
use std::thread;
65
use std::sync::mpsc::{channel, Sender};
6+
use std::thread;
77

88
pub fn main() {
99
let (tx, rx) = channel();
10-
let t = thread::spawn(move || { child(&tx) });
10+
let t = thread::spawn(move || child(&tx));
1111
let y = rx.recv().unwrap();
1212
println!("received");
1313
println!("{}", y);

Diff for: tests/ui/threads-sendsync/issue-24313.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
//@ needs-threads
33
//@ ignore-sgx no processes
44

5-
use std::thread;
6-
use std::env;
75
use std::process::Command;
6+
use std::{env, thread};
87

98
struct Handle(i32);
109

1110
impl Drop for Handle {
12-
fn drop(&mut self) { panic!(); }
11+
fn drop(&mut self) {
12+
panic!();
13+
}
1314
}
1415

1516
thread_local!(static HANDLE: Handle = Handle(0));
@@ -19,14 +20,15 @@ fn main() {
1920
if args.len() == 1 {
2021
let out = Command::new(&args[0]).arg("test").output().unwrap();
2122
let stderr = std::str::from_utf8(&out.stderr).unwrap();
22-
assert!(stderr.contains("explicit panic"),
23-
"bad failure message:\n{}\n", stderr);
23+
assert!(stderr.contains("explicit panic"), "bad failure message:\n{}\n", stderr);
2424
} else {
2525
// TLS dtors are not always run on process exit
2626
thread::spawn(|| {
2727
HANDLE.with(|h| {
2828
println!("{}", h.0);
2929
});
30-
}).join().unwrap();
30+
})
31+
.join()
32+
.unwrap();
3133
}
3234
}

Diff for: tests/ui/threads-sendsync/issue-29488.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ fn main() {
1919
thread::spawn(|| {
2020
FOO.with(|_| {});
2121
println!("test1");
22-
}).join().unwrap();
22+
})
23+
.join()
24+
.unwrap();
2325
}

Diff for: tests/ui/threads-sendsync/issue-4446.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ pub fn main() {
99

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

12-
thread::spawn(move|| {
12+
thread::spawn(move || {
1313
println!("{}", rx.recv().unwrap());
14-
}).join().ok().unwrap();
14+
})
15+
.join()
16+
.ok()
17+
.unwrap();
1518
}

Diff for: tests/ui/threads-sendsync/issue-4448.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::thread;
77
pub fn main() {
88
let (tx, rx) = channel::<&'static str>();
99

10-
let t = thread::spawn(move|| {
10+
let t = thread::spawn(move || {
1111
assert_eq!(rx.recv().unwrap(), "hello, world");
1212
});
1313

Diff for: tests/ui/threads-sendsync/issue-8827.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//@ run-pass
22
//@ needs-threads
33

4-
use std::thread;
54
use std::sync::mpsc::{channel, Receiver};
5+
use std::thread;
66

77
fn periodical(n: isize) -> Receiver<bool> {
88
let (chan, port) = channel();
9-
thread::spawn(move|| {
9+
thread::spawn(move || {
1010
loop {
1111
for _ in 1..n {
1212
match chan.send(false) {
@@ -16,7 +16,7 @@ fn periodical(n: isize) -> Receiver<bool> {
1616
}
1717
match chan.send(true) {
1818
Ok(()) => {}
19-
Err(..) => break
19+
Err(..) => break,
2020
}
2121
}
2222
});
@@ -25,7 +25,7 @@ fn periodical(n: isize) -> Receiver<bool> {
2525

2626
fn integers() -> Receiver<isize> {
2727
let (chan, port) = channel();
28-
thread::spawn(move|| {
28+
thread::spawn(move || {
2929
let mut i = 1;
3030
loop {
3131
match chan.send(i) {
@@ -47,7 +47,7 @@ fn main() {
4747
(_, true, true) => println!("FizzBuzz"),
4848
(_, true, false) => println!("Fizz"),
4949
(_, false, true) => println!("Buzz"),
50-
(i, false, false) => println!("{}", i)
50+
(i, false, false) => println!("{}", i),
5151
}
5252
}
5353
}

Diff for: tests/ui/threads-sendsync/issue-9396.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
#![allow(deprecated)]
44
//@ needs-threads
55

6-
use std::sync::mpsc::{TryRecvError, channel};
6+
use std::sync::mpsc::{channel, TryRecvError};
77
use std::thread;
88

99
pub fn main() {
1010
let (tx, rx) = channel();
11-
let t = thread::spawn(move||{
11+
let t = thread::spawn(move || {
1212
thread::sleep_ms(10);
1313
tx.send(()).unwrap();
1414
});
1515
loop {
1616
match rx.try_recv() {
1717
Ok(()) => break,
1818
Err(TryRecvError::Empty) => {}
19-
Err(TryRecvError::Disconnected) => unreachable!()
19+
Err(TryRecvError::Disconnected) => unreachable!(),
2020
}
2121
}
2222
t.join();

Diff for: tests/ui/threads-sendsync/mpsc_stress.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@
22
//@ compile-flags:--test
33
//@ needs-threads
44

5-
use std::sync::mpsc::channel;
6-
use std::sync::mpsc::TryRecvError;
7-
use std::sync::mpsc::RecvError;
8-
use std::sync::mpsc::RecvTimeoutError;
5+
use std::sync::atomic::{AtomicUsize, Ordering};
6+
use std::sync::mpsc::{channel, RecvError, RecvTimeoutError, TryRecvError};
97
use std::sync::Arc;
10-
use std::sync::atomic::AtomicUsize;
11-
use std::sync::atomic::Ordering;
12-
138
use std::thread;
149
use std::time::Duration;
1510

16-
1711
/// Simple thread synchronization utility
1812
struct Barrier {
1913
// Not using mutex/condvar for precision
@@ -42,7 +36,6 @@ impl Barrier {
4236
}
4337
}
4438

45-
4639
fn shared_close_sender_does_not_lose_messages_iter() {
4740
let (tb, rb) = Barrier::new2();
4841

@@ -71,7 +64,6 @@ fn shared_close_sender_does_not_lose_messages() {
7164
});
7265
}
7366

74-
7567
// https://github.com/rust-lang/rust/issues/39364
7668
fn concurrent_recv_timeout_and_upgrade_iter() {
7769
// 1 us
@@ -85,8 +77,8 @@ fn concurrent_recv_timeout_and_upgrade_iter() {
8577
match rx.recv_timeout(sleep) {
8678
Ok(_) => {
8779
break;
88-
},
89-
Err(_) => {},
80+
}
81+
Err(_) => {}
9082
}
9183
}
9284
});
@@ -105,7 +97,6 @@ fn concurrent_recv_timeout_and_upgrade() {
10597
});
10698
}
10799

108-
109100
fn concurrent_writes_iter() {
110101
const THREADS: usize = 4;
111102
const PER_THR: usize = 100;
+7-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
//@ run-pass
22
#![allow(unused_imports)]
3-
use std::thread;
43
use std::sync::Mutex;
4+
use std::thread;
55

66
fn par_for<I, F>(iter: I, f: F)
7-
where I: Iterator,
8-
I::Item: Send,
9-
F: Fn(I::Item) + Sync
7+
where
8+
I: Iterator,
9+
I::Item: Send,
10+
F: Fn(I::Item) + Sync,
1011
{
1112
for item in iter {
1213
f(item)
@@ -15,9 +16,7 @@ fn par_for<I, F>(iter: I, f: F)
1516

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

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

2827
// iterators over references into this stack frame
29-
par_for(elements.iter_mut().enumerate(), |(i, x)| {
30-
*x = i as i32
31-
});
28+
par_for(elements.iter_mut().enumerate(), |(i, x)| *x = i as i32);
3229

3330
sum(&elements)
3431
}

Diff for: tests/ui/threads-sendsync/send-resource.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@
66
//@ pretty-expanded FIXME #23616
77
//@ needs-threads
88

9-
use std::thread;
109
use std::sync::mpsc::channel;
10+
use std::thread;
1111

1212
struct test {
13-
f: isize,
13+
f: isize,
1414
}
1515

1616
impl Drop for test {
1717
fn drop(&mut self) {}
1818
}
1919

2020
fn test(f: isize) -> test {
21-
test {
22-
f: f
23-
}
21+
test { f: f }
2422
}
2523

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

29-
let t = thread::spawn(move|| {
27+
let t = thread::spawn(move || {
3028
let (tx2, rx2) = channel();
3129
tx.send(tx2).unwrap();
3230

Diff for: tests/ui/threads-sendsync/send-type-inference.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use std::sync::mpsc::{channel, Sender};
99
// tests that ctrl's type gets inferred properly
1010
struct Command<K, V> {
1111
key: K,
12-
val: V
12+
val: V,
1313
}
1414

15-
fn cache_server<K:Send+'static,V:Send+'static>(mut tx: Sender<Sender<Command<K, V>>>) {
15+
fn cache_server<K: Send + 'static, V: Send + 'static>(mut tx: Sender<Sender<Command<K, V>>>) {
1616
let (tx1, _rx) = channel();
1717
tx.send(tx1);
1818
}
19-
pub fn main() { }
19+
pub fn main() {}

Diff for: tests/ui/threads-sendsync/send_str_hashmap.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//@ run-pass
2-
use std::collections::HashMap;
32
use std::borrow::Cow;
4-
5-
use std::borrow::Cow::Borrowed as B;
6-
use std::borrow::Cow::Owned as O;
3+
use std::borrow::Cow::{Borrowed as B, Owned as O};
4+
use std::collections::HashMap;
75

86
type SendStr = Cow<'static, str>;
97

Diff for: tests/ui/threads-sendsync/send_str_treemap.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//@ run-pass
2-
use std::collections::BTreeMap;
32
use std::borrow::Cow;
4-
5-
use std::borrow::Cow::{Owned as O, Borrowed as B};
3+
use std::borrow::Cow::{Borrowed as B, Owned as O};
4+
use std::collections::BTreeMap;
65

76
type SendStr = Cow<'static, str>;
87

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

5352
assert!(map.remove(&B("foo")).is_some());
54-
assert_eq!(map.into_iter().map(|(k, v)| format!("{}{}", k, v))
55-
.collect::<Vec<String>>()
56-
.concat(),
57-
"abc50bcd51cde52def53".to_string());
53+
assert_eq!(
54+
map.into_iter().map(|(k, v)| format!("{}{}", k, v)).collect::<Vec<String>>().concat(),
55+
"abc50bcd51cde52def53".to_string()
56+
);
5857
}

Diff for: tests/ui/threads-sendsync/sendable-class.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@
1111
use std::sync::mpsc::channel;
1212

1313
struct foo {
14-
i: isize,
15-
j: char,
14+
i: isize,
15+
j: char,
1616
}
1717

18-
fn foo(i:isize, j: char) -> foo {
19-
foo {
20-
i: i,
21-
j: j
22-
}
18+
fn foo(i: isize, j: char) -> foo {
19+
foo { i: i, j: j }
2320
}
2421

2522
pub fn main() {

Diff for: tests/ui/threads-sendsync/sendfn-is-a-block.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//@ run-pass
22

3-
4-
fn test<F>(f: F) -> usize where F: FnOnce(usize) -> usize {
3+
fn test<F>(f: F) -> usize
4+
where
5+
F: FnOnce(usize) -> usize,
6+
{
57
return f(22);
68
}
79

0 commit comments

Comments
 (0)