Skip to content

Commit bdf2a8a

Browse files
committed
Auto merge of rust-lang#2247 - dtolnay-contrib:rustfmt2, r=RalfJung
Format tests with rustfmt (101-150 of 300) Extracted from rust-lang#2097. Like rust-lang/miri#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

+21-9
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

+4-4
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

+5-5
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

+4-5
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

+7-3
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

+2-2
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

+5-3
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

+2-3
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

-1
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

+14-8
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
}

tests/pass/issues/issue-23261.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
struct Foo<T: ?Sized> {
44
a: i32,
5-
inner: T
5+
inner: T,
66
}
77

88
trait Get {

tests/pass/issues/issue-27901.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
trait Stream { type Item; }
2-
impl<'a> Stream for &'a str { type Item = u8; }
1+
trait Stream {
2+
type Item;
3+
}
4+
impl<'a> Stream for &'a str {
5+
type Item = u8;
6+
}
37
fn f<'s>(s: &'s str) -> (&'s str, <&'s str as Stream>::Item) {
48
(s, 42)
59
}

tests/pass/issues/issue-29746.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ macro_rules! zip {
2525
}
2626

2727
fn main() {
28-
let p1 = vec![1i32, 2].into_iter();
29-
let p2 = vec!["10", "20"].into_iter();
30-
let p3 = vec![100u16, 200].into_iter();
28+
let p1 = vec![1i32, 2].into_iter();
29+
let p2 = vec!["10", "20"].into_iter();
30+
let p3 = vec![100u16, 200].into_iter();
3131
let p4 = vec![1000i64, 2000].into_iter();
3232

33-
let e = zip!([p1,p2,p3,p4]).collect::<Vec<_>>();
34-
assert_eq!(e[0], (1i32,"10",100u16,1000i64));
33+
let e = zip!([p1, p2, p3, p4]).collect::<Vec<_>>();
34+
assert_eq!(e[0], (1i32, "10", 100u16, 1000i64));
3535
}

tests/pass/issues/issue-30530.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ pub enum Handler {
2121
}
2222

2323
fn main() {
24-
#[allow(unused_must_use)] {
24+
#[allow(unused_must_use)]
25+
{
2526
take(Handler::Default, Box::new(main));
2627
}
2728
}

tests/pass/issues/issue-34571.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ enum Foo {
55

66
fn main() {
77
match Foo::Foo(1) {
8-
_ => ()
8+
_ => (),
99
}
1010
}

tests/pass/issues/issue-36278-prefix-nesting.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ struct P<T: ?Sized>([u8; SZ], T);
99
type Ack<T> = P<P<T>>;
1010

1111
fn main() {
12-
let size_of_sized; let size_of_unsized;
12+
let size_of_sized;
13+
let size_of_unsized;
1314
let x: Box<Ack<[u8; 0]>> = Box::new(P([0; SZ], P([0; SZ], [0; 0])));
1415
size_of_sized = mem::size_of_val::<Ack<_>>(&x);
1516
let align_of_sized = mem::align_of_val::<Ack<_>>(&x);
16-
let y: Box<Ack<[u8 ]>> = x;
17+
let y: Box<Ack<[u8]>> = x;
1718
size_of_unsized = mem::size_of_val::<Ack<_>>(&y);
1819
assert_eq!(size_of_sized, size_of_unsized);
1920
assert_eq!(align_of_sized, 1);

tests/pass/issues/issue-5917.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
2-
struct T (&'static [isize]);
3-
static STATIC : T = T (&[5, 4, 3]);
4-
pub fn main () {
1+
struct T(&'static [isize]);
2+
static STATIC: T = T(&[5, 4, 3]);
3+
pub fn main() {
54
let T(ref v) = STATIC;
65
assert_eq!(v[0], 5);
76
}

tests/pass/issues/issue-miri-133.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ struct S<U, V> {
44
_u: U,
55
size_of_u: usize,
66
_v: V,
7-
size_of_v: usize
7+
size_of_v: usize,
88
}
99

1010
impl<U, V> S<U, V> {
1111
fn new(u: U, v: V) -> Self {
12-
S {
13-
_u: u,
14-
size_of_u: size_of::<U>(),
15-
_v: v,
16-
size_of_v: size_of::<V>()
17-
}
12+
S { _u: u, size_of_u: size_of::<U>(), _v: v, size_of_v: size_of::<V>() }
1813
}
1914
}
2015

tests/pass/issues/issue-miri-2068-2.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
use std::mem::MaybeUninit;
44

5-
fn main() { unsafe {
6-
let mut x = MaybeUninit::<i64>::uninit();
7-
// Put in a ptr.
8-
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
9-
// Overwrite parts of that pointer with 'uninit' through a Scalar.
10-
let ptr = x.as_mut_ptr().cast::<i32>();
11-
*ptr = MaybeUninit::uninit().assume_init();
12-
// Reading this back should hence work fine.
13-
let _c = *ptr;
14-
} }
5+
fn main() {
6+
unsafe {
7+
let mut x = MaybeUninit::<i64>::uninit();
8+
// Put in a ptr.
9+
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
10+
// Overwrite parts of that pointer with 'uninit' through a Scalar.
11+
let ptr = x.as_mut_ptr().cast::<i32>();
12+
*ptr = MaybeUninit::uninit().assume_init();
13+
// Reading this back should hence work fine.
14+
let _c = *ptr;
15+
}
16+
}

0 commit comments

Comments
 (0)