Skip to content

Commit bdf2a8a

Browse files
committed
Auto merge of #2247 - dtolnay-contrib:rustfmt2, r=RalfJung
Format tests with rustfmt (101-150 of 300) Extracted from #2097. Like #2244, these are "easy" cases that do not involve moving around comments.
2 parents 4d712a3 + 6b8c371 commit bdf2a8a

Some content is hidden

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

50 files changed

+395
-273
lines changed

tests/pass/generator.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#![feature(generators, generator_trait, never_type)]
22

3-
use std::ops::{GeneratorState::{self, *}, Generator};
4-
use std::pin::Pin;
5-
use std::sync::atomic::{AtomicUsize, Ordering};
63
use std::fmt::Debug;
74
use std::mem::ManuallyDrop;
5+
use std::ops::{
6+
Generator,
7+
GeneratorState::{self, *},
8+
};
9+
use std::pin::Pin;
810
use std::ptr;
11+
use std::sync::atomic::{AtomicUsize, Ordering};
912

1013
fn basic() {
1114
fn finish<T>(mut amt: usize, mut t: T) -> T::Return
12-
where T: Generator<Yield = usize>
15+
where
16+
T: Generator<Yield = usize>,
1317
{
1418
// We are not moving the `t` around until it gets dropped, so this is okay.
1519
let mut t = unsafe { Pin::new_unchecked(&mut t) };
@@ -23,7 +27,7 @@ fn basic() {
2327
}
2428
GeneratorState::Complete(ret) => {
2529
assert_eq!(amt, 0);
26-
return ret
30+
return ret;
2731
}
2832
}
2933
}
@@ -46,7 +50,7 @@ fn basic() {
4650
assert_eq!(x, 2);
4751
});
4852

49-
finish(7*8/2, || {
53+
finish(7 * 8 / 2, || {
5054
for i in 0..8 {
5155
yield i;
5256
}
@@ -67,7 +71,10 @@ fn basic() {
6771
});
6872

6973
finish(2, || {
70-
if { yield 1; false } {
74+
if {
75+
yield 1;
76+
false
77+
} {
7178
yield 1;
7279
panic!()
7380
}
@@ -90,7 +97,9 @@ fn basic() {
9097
let b = true;
9198
finish(1, || {
9299
yield 1;
93-
if b { return; }
100+
if b {
101+
return;
102+
}
94103
#[allow(unused)]
95104
let x = never();
96105
#[allow(unreachable_code)]
@@ -101,7 +110,10 @@ fn basic() {
101110
finish(3, || {
102111
yield 1;
103112
#[allow(unreachable_code)]
104-
let _x: (String, !) = (String::new(), { yield 2; return });
113+
let _x: (String, !) = (String::new(), {
114+
yield 2;
115+
return;
116+
});
105117
});
106118
}
107119

tests/pass/hashmap.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>
1717

1818
fn smoketest_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
1919
map.insert(0, 0);
20-
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
20+
assert_eq!(map.values().fold(0, |x, y| x + y), 0);
2121

2222
let num = 25;
2323
for i in 1..num {
2424
map.insert(i, i);
2525
}
26-
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
26+
assert_eq!(map.values().fold(0, |x, y| x + y), num * (num - 1) / 2); // check the right things are in the table now
2727

2828
// Inserting again replaces the existing entries
2929
for i in 0..num {
30-
map.insert(i, num-1-i);
30+
map.insert(i, num - 1 - i);
3131
}
32-
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
32+
assert_eq!(map.values().fold(0, |x, y| x + y), num * (num - 1) / 2);
3333

3434
test_all_refs(&mut 13, map.values_mut());
3535
}

tests/pass/integer-ops.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn main() {
4242
let m = -0xFEDCBA987654322i64;
4343
assert_eq!(n.rotate_right(4), m);
4444

45-
let n = 0x0123456789ABCDEFi64;
45+
let n = 0x0123456789ABCDEFi64;
4646
let m = -0x1032547698BADCFFi64;
4747
assert_eq!(n.swap_bytes(), m);
4848

@@ -169,9 +169,9 @@ pub fn main() {
169169
assert_eq!(0x10i32.overflowing_shr(4), (0x1, false));
170170
assert_eq!(0x10i32.overflowing_shr(36), (0x1, true));
171171

172-
assert_eq!(10i8.overflowing_abs(), (10,false));
173-
assert_eq!((-10i8).overflowing_abs(), (10,false));
174-
assert_eq!((-128i8).overflowing_abs(), (-128,true));
172+
assert_eq!(10i8.overflowing_abs(), (10, false));
173+
assert_eq!((-10i8).overflowing_abs(), (10, false));
174+
assert_eq!((-128i8).overflowing_abs(), (-128, true));
175175

176176
// Logarithms
177177
macro_rules! test_log {
@@ -180,7 +180,7 @@ pub fn main() {
180180
assert_eq!($type::MIN.checked_log10(), None);
181181
assert_eq!($type::MAX.checked_log2(), Some($max_log2));
182182
assert_eq!($type::MAX.checked_log10(), Some($max_log10));
183-
}
183+
};
184184
}
185185

186186
test_log!(i8, 6, 2);

tests/pass/intrinsics-math.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
// except according to those terms.
1010

1111
macro_rules! assert_approx_eq {
12-
($a:expr, $b:expr) => ({
12+
($a:expr, $b:expr) => {{
1313
let (a, b) = (&$a, &$b);
14-
assert!((*a - *b).abs() < 1.0e-6,
15-
"{} is not approximately equal to {}", *a, *b);
16-
})
14+
assert!((*a - *b).abs() < 1.0e-6, "{} is not approximately equal to {}", *a, *b);
15+
}};
1716
}
1817

1918
fn ldexp(a: f64, b: i32) -> f64 {
20-
extern {
19+
extern "C" {
2120
fn ldexp(x: f64, n: i32) -> f64;
2221
}
2322
unsafe { ldexp(a, b) }

tests/pass/intrinsics.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ fn main() {
2020
assert_eq!(size_of_val(&[1, 2, 3] as &[i32]), 12);
2121
assert_eq!(size_of_val("foobar"), 6);
2222

23-
unsafe { assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4); }
24-
unsafe { assert_eq!(size_of_val_raw(0x100 as *const i32), 4); }
23+
unsafe {
24+
assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4);
25+
}
26+
unsafe {
27+
assert_eq!(size_of_val_raw(0x100 as *const i32), 4);
28+
}
2529

2630
assert_eq!(intrinsics::type_name::<Option<i32>>(), "core::option::Option<i32>");
2731

@@ -33,7 +37,7 @@ fn main() {
3337
let _v = intrinsics::discriminant_value(&Some(()));
3438
let _v = intrinsics::discriminant_value(&0);
3539
let _v = intrinsics::discriminant_value(&true);
36-
let _v = intrinsics::discriminant_value(&vec![1,2,3]);
40+
let _v = intrinsics::discriminant_value(&vec![1, 2, 3]);
3741

3842
let addr = &13 as *const i32;
3943
let addr2 = (addr as usize).wrapping_add(usize::MAX).wrapping_add(1);

tests/pass/ints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn indirect_add() -> i64 {
1717
}
1818

1919
fn arith() -> i32 {
20-
3*3 + 4*4
20+
3 * 3 + 4 * 4
2121
}
2222

2323
fn match_int() -> i16 {
@@ -48,7 +48,7 @@ fn main() {
4848
assert_eq!(neg(), -1);
4949
assert_eq!(add(), 3);
5050
assert_eq!(indirect_add(), 3);
51-
assert_eq!(arith(), 5*5);
51+
assert_eq!(arith(), 5 * 5);
5252
assert_eq!(match_int(), 20);
5353
assert_eq!(match_int_range(), 4);
5454
assert_eq!(i64::MIN.overflowing_mul(-1), (i64::MIN, true));

tests/pass/issues/issue-15063.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#[allow(dead_code)]
2-
enum Two { A, B }
2+
enum Two {
3+
A,
4+
B,
5+
}
36
impl Drop for Two {
4-
fn drop(&mut self) {
5-
}
7+
fn drop(&mut self) {}
68
}
79
fn main() {
810
let _k = Two::A;

tests/pass/issues/issue-15080.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
let mut x: &[_] = &[1, 2, 3, 4];
33

4-
let mut result = vec!();
4+
let mut result = vec![];
55
loop {
66
x = match *x {
77
[1, n, 3, ref rest @ ..] => {
@@ -12,8 +12,7 @@ fn main() {
1212
result.push(n);
1313
rest
1414
}
15-
[] =>
16-
break
15+
[] => break,
1716
}
1817
}
1918
assert_eq!(result, [2, 4]);

tests/pass/issues/issue-15523-big.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fn main() {
2727
assert!(Eu64::Pos2 < Eu64::PosMax);
2828
assert!(Eu64::Pos1 < Eu64::PosMax);
2929

30-
3130
assert!(Ei64::Pos2 > Ei64::Pos1);
3231
assert!(Ei64::Pos2 > Ei64::Neg1);
3332
assert!(Ei64::Pos1 > Ei64::Neg1);

tests/pass/issues/issue-17877.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
fn main() {
2-
assert_eq!(match [0u8; 16*1024] {
3-
_ => 42_usize,
4-
}, 42_usize);
2+
assert_eq!(
3+
match [0u8; 16 * 1024] {
4+
_ => 42_usize,
5+
},
6+
42_usize,
7+
);
58

6-
assert_eq!(match [0u8; 16*1024] {
7-
[1, ..] => 0_usize,
8-
[0, ..] => 1_usize,
9-
_ => 2_usize
10-
}, 1_usize);
9+
assert_eq!(
10+
match [0u8; 16 * 1024] {
11+
[1, ..] => 0_usize,
12+
[0, ..] => 1_usize,
13+
_ => 2_usize,
14+
},
15+
1_usize,
16+
);
1117
}

0 commit comments

Comments
 (0)