Skip to content

Commit 4166ce8

Browse files
authored
Rollup merge of rust-lang#66892 - dtolnay:fmt5, r=KodrAus
Format libcore with rustfmt (including tests and benches) Important: two small non-rustfmt changes that will need close review: - I added `#[rustfmt::skip]` to two manually arranged tables in src/libcore/benches/ascii.rs; see first commit in the PR. - I added `// ignore-tidy-filelength` to src/libcore/ptr/mod.rs because rustfmt puts it over tidy's 3000 line limit; see second commit in the PR. I filed rust-lang#66891 to follow up on breaking up that file. For now though having it be formatted is more important than having it below the line limit. --- As with my previous formatting PRs, I am avoiding causing merge conflicts in other PRs by only touches those files that are not involved in any currently open PR. Files that appear in new PRs between when this PR is opened and when it makes it to the top of the bors queue will be reverted from this PR. The list of files involved in open PRs is determined by querying GitHub's GraphQL API [with this script](https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8). With the list of files from the script in outstanding_files, the relevant commands were: ``` $ find src/libcore -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libcore outstanding_files | xargs git checkout -- ``` To confirm no funny business: ``` $ git checkout $THIS_COMMIT^ $ git show --pretty= --name-only $THIS_COMMIT \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ git diff $THIS_COMMIT # there should be no difference ``` r? @Dylan-DPC
2 parents 7de9402 + c737169 commit 4166ce8

Some content is hidden

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

49 files changed

+1311
-1171
lines changed

src/libcore/benches/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::any::*;
2-
use test::{Bencher, black_box};
2+
use test::{black_box, Bencher};
33

44
#[bench]
55
fn bench_downcast_ref(b: &mut Bencher) {

src/libcore/benches/ascii.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,9 @@
2222
//
2323
// Therefore:
2424
fn branchless_to_ascii_upper_case(byte: u8) -> u8 {
25-
byte &
26-
!(
27-
(
28-
byte.wrapping_add(0x1f) &
29-
!byte.wrapping_add(0x05) &
30-
0x80
31-
) >> 2
32-
)
25+
byte & !((byte.wrapping_add(0x1f) & !byte.wrapping_add(0x05) & 0x80) >> 2)
3326
}
3427

35-
3628
macro_rules! benches {
3729
($( fn $name: ident($arg: ident: &mut [u8]) $body: block )+ @iter $( $is_: ident, )+) => {
3830
benches! {@
@@ -254,12 +246,15 @@ benches! {
254246
}
255247

256248
macro_rules! repeat {
257-
($s: expr) => { concat!($s, $s, $s, $s, $s, $s, $s, $s, $s, $s) }
249+
($s: expr) => {
250+
concat!($s, $s, $s, $s, $s, $s, $s, $s, $s, $s)
251+
};
258252
}
259253

260254
const SHORT: &'static str = "Alice's";
261255
const MEDIUM: &'static str = "Alice's Adventures in Wonderland";
262-
const LONG: &'static str = repeat!(r#"
256+
const LONG: &'static str = repeat!(
257+
r#"
263258
La Guida di Bragia, a Ballad Opera for the Marionette Theatre (around 1850)
264259
Alice's Adventures in Wonderland (1865)
265260
Phantasmagoria and Other Poems (1869)
@@ -275,8 +270,10 @@ const LONG: &'static str = repeat!(r#"
275270
What the Tortoise Said to Achilles (1895)
276271
Three Sunsets and Other Poems (1898)
277272
The Manlet (1903)[106]
278-
"#);
273+
"#
274+
);
279275

276+
#[rustfmt::skip]
280277
const ASCII_UPPERCASE_MAP: [u8; 256] = [
281278
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
282279
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -330,6 +327,7 @@ enum AsciiCharacterClass {
330327
}
331328
use self::AsciiCharacterClass::*;
332329

330+
#[rustfmt::skip]
333331
static ASCII_CHARACTER_CLASS: [AsciiCharacterClass; 256] = [
334332
// _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _a _b _c _d _e _f
335333
C, C, C, C, C, C, C, C, C, Cw,Cw,C, Cw,Cw,C, C, // 0_

src/libcore/benches/char/methods.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ fn bench_to_digit_radix_36(b: &mut Bencher) {
2525

2626
#[bench]
2727
fn bench_to_digit_radix_var(b: &mut Bencher) {
28-
b.iter(|| CHARS.iter().cycle()
29-
.zip(RADIX.iter().cycle())
30-
.take(10_000)
31-
.map(|(c, radix)| c.to_digit(*radix)).min())
28+
b.iter(|| {
29+
CHARS
30+
.iter()
31+
.cycle()
32+
.zip(RADIX.iter().cycle())
33+
.take(10_000)
34+
.map(|(c, radix)| c.to_digit(*radix))
35+
.min()
36+
})
3237
}

src/libcore/benches/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::io::{self, Write as IoWrite};
21
use std::fmt::{self, Write as FmtWrite};
2+
use std::io::{self, Write as IoWrite};
33
use test::Bencher;
44

55
#[bench]

src/libcore/benches/hash/sip.rs

+15-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(deprecated)]
22

33
use core::hash::*;
4-
use test::{Bencher, black_box};
4+
use test::{black_box, Bencher};
55

66
fn hash_bytes<H: Hasher>(mut s: H, x: &[u8]) -> u64 {
77
Hasher::write(&mut s, x);
@@ -44,11 +44,11 @@ fn bench_str_over_8_bytes(b: &mut Bencher) {
4444
#[bench]
4545
fn bench_long_str(b: &mut Bencher) {
4646
let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
47-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
48-
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
49-
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
50-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
51-
officia deserunt mollit anim id est laborum.";
47+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
48+
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
49+
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
50+
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
51+
officia deserunt mollit anim id est laborum.";
5252
b.iter(|| {
5353
assert_eq!(hash(&s), 17717065544121360093);
5454
})
@@ -58,9 +58,7 @@ officia deserunt mollit anim id est laborum.";
5858
fn bench_u32(b: &mut Bencher) {
5959
let u = 162629500u32;
6060
let u = black_box(u);
61-
b.iter(|| {
62-
hash(&u)
63-
});
61+
b.iter(|| hash(&u));
6462
b.bytes = 8;
6563
}
6664

@@ -70,72 +68,56 @@ fn bench_u32_keyed(b: &mut Bencher) {
7068
let u = black_box(u);
7169
let k1 = black_box(0x1);
7270
let k2 = black_box(0x2);
73-
b.iter(|| {
74-
hash_with(SipHasher::new_with_keys(k1, k2), &u)
75-
});
71+
b.iter(|| hash_with(SipHasher::new_with_keys(k1, k2), &u));
7672
b.bytes = 8;
7773
}
7874

7975
#[bench]
8076
fn bench_u64(b: &mut Bencher) {
8177
let u = 16262950014981195938u64;
8278
let u = black_box(u);
83-
b.iter(|| {
84-
hash(&u)
85-
});
79+
b.iter(|| hash(&u));
8680
b.bytes = 8;
8781
}
8882

8983
#[bench]
9084
fn bench_bytes_4(b: &mut Bencher) {
9185
let data = black_box([b' '; 4]);
92-
b.iter(|| {
93-
hash_bytes(SipHasher::default(), &data)
94-
});
86+
b.iter(|| hash_bytes(SipHasher::default(), &data));
9587
b.bytes = 4;
9688
}
9789

9890
#[bench]
9991
fn bench_bytes_7(b: &mut Bencher) {
10092
let data = black_box([b' '; 7]);
101-
b.iter(|| {
102-
hash_bytes(SipHasher::default(), &data)
103-
});
93+
b.iter(|| hash_bytes(SipHasher::default(), &data));
10494
b.bytes = 7;
10595
}
10696

10797
#[bench]
10898
fn bench_bytes_8(b: &mut Bencher) {
10999
let data = black_box([b' '; 8]);
110-
b.iter(|| {
111-
hash_bytes(SipHasher::default(), &data)
112-
});
100+
b.iter(|| hash_bytes(SipHasher::default(), &data));
113101
b.bytes = 8;
114102
}
115103

116104
#[bench]
117105
fn bench_bytes_a_16(b: &mut Bencher) {
118106
let data = black_box([b' '; 16]);
119-
b.iter(|| {
120-
hash_bytes(SipHasher::default(), &data)
121-
});
107+
b.iter(|| hash_bytes(SipHasher::default(), &data));
122108
b.bytes = 16;
123109
}
124110

125111
#[bench]
126112
fn bench_bytes_b_32(b: &mut Bencher) {
127113
let data = black_box([b' '; 32]);
128-
b.iter(|| {
129-
hash_bytes(SipHasher::default(), &data)
130-
});
114+
b.iter(|| hash_bytes(SipHasher::default(), &data));
131115
b.bytes = 32;
132116
}
133117

134118
#[bench]
135119
fn bench_bytes_c_128(b: &mut Bencher) {
136120
let data = black_box([b' '; 128]);
137-
b.iter(|| {
138-
hash_bytes(SipHasher::default(), &data)
139-
});
121+
b.iter(|| hash_bytes(SipHasher::default(), &data));
140122
b.bytes = 128;
141123
}

src/libcore/benches/iter.rs

+33-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::iter::*;
2-
use test::{Bencher, black_box};
2+
use test::{black_box, Bencher};
33

44
#[bench]
55
fn bench_rposition(b: &mut Bencher) {
@@ -14,7 +14,11 @@ fn bench_skip_while(b: &mut Bencher) {
1414
b.iter(|| {
1515
let it = 0..100;
1616
let mut sum = 0;
17-
it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
17+
it.skip_while(|&x| {
18+
sum += x;
19+
sum < 4000
20+
})
21+
.all(|_| true);
1822
});
1923
}
2024

@@ -29,7 +33,9 @@ fn bench_multiple_take(b: &mut Bencher) {
2933
});
3034
}
3135

32-
fn scatter(x: i32) -> i32 { (x * 31) % 127 }
36+
fn scatter(x: i32) -> i32 {
37+
(x * 31) % 127
38+
}
3339

3440
#[bench]
3541
fn bench_max_by_key(b: &mut Bencher) {
@@ -76,23 +82,21 @@ pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
7682
fn bench_zip_copy(b: &mut Bencher) {
7783
let source = vec![0u8; 16 * 1024];
7884
let mut dst = black_box(vec![0u8; 16 * 1024]);
79-
b.iter(|| {
80-
copy_zip(&source, &mut dst)
81-
})
85+
b.iter(|| copy_zip(&source, &mut dst))
8286
}
8387

8488
#[bench]
8589
fn bench_zip_add(b: &mut Bencher) {
8690
let source = vec![1.; 16 * 1024];
8791
let mut dst = vec![0.; 16 * 1024];
88-
b.iter(|| {
89-
add_zip(&source, &mut dst)
90-
});
92+
b.iter(|| add_zip(&source, &mut dst));
9193
}
9294

9395
/// `Iterator::for_each` implemented as a plain loop.
94-
fn for_each_loop<I, F>(iter: I, mut f: F) where
95-
I: Iterator, F: FnMut(I::Item)
96+
fn for_each_loop<I, F>(iter: I, mut f: F)
97+
where
98+
I: Iterator,
99+
F: FnMut(I::Item),
96100
{
97101
for item in iter {
98102
f(item);
@@ -101,8 +105,10 @@ fn for_each_loop<I, F>(iter: I, mut f: F) where
101105

102106
/// `Iterator::for_each` implemented with `fold` for internal iteration.
103107
/// (except when `by_ref()` effectively disables that optimization.)
104-
fn for_each_fold<I, F>(iter: I, mut f: F) where
105-
I: Iterator, F: FnMut(I::Item)
108+
fn for_each_fold<I, F>(iter: I, mut f: F)
109+
where
110+
I: Iterator,
111+
F: FnMut(I::Item),
106112
{
107113
iter.fold((), move |(), item| f(item));
108114
}
@@ -137,25 +143,20 @@ fn bench_for_each_chain_ref_fold(b: &mut Bencher) {
137143
});
138144
}
139145

140-
141146
/// Helper to benchmark `sum` for iterators taken by value which
142147
/// can optimize `fold`, and by reference which cannot.
143148
macro_rules! bench_sums {
144149
($bench_sum:ident, $bench_ref_sum:ident, $iter:expr) => {
145150
#[bench]
146151
fn $bench_sum(b: &mut Bencher) {
147-
b.iter(|| -> i64 {
148-
$iter.map(black_box).sum()
149-
});
152+
b.iter(|| -> i64 { $iter.map(black_box).sum() });
150153
}
151154

152155
#[bench]
153156
fn $bench_ref_sum(b: &mut Bencher) {
154-
b.iter(|| -> i64 {
155-
$iter.map(black_box).by_ref().sum()
156-
});
157+
b.iter(|| -> i64 { $iter.map(black_box).by_ref().sum() });
157158
}
158-
}
159+
};
159160
}
160161

161162
bench_sums! {
@@ -286,7 +287,10 @@ fn bench_zip_then_skip(b: &mut Bencher) {
286287
let t: Vec<_> = (0..100_000).collect();
287288

288289
b.iter(|| {
289-
let s = v.iter().zip(t.iter()).skip(10000)
290+
let s = v
291+
.iter()
292+
.zip(t.iter())
293+
.skip(10000)
290294
.take_while(|t| *t.0 < 10100)
291295
.map(|(a, b)| *a + *b)
292296
.sum::<u64>();
@@ -299,7 +303,10 @@ fn bench_skip_then_zip(b: &mut Bencher) {
299303
let t: Vec<_> = (0..100_000).collect();
300304

301305
b.iter(|| {
302-
let s = v.iter().skip(10000).zip(t.iter().skip(10000))
306+
let s = v
307+
.iter()
308+
.skip(10000)
309+
.zip(t.iter().skip(10000))
303310
.take_while(|t| *t.0 < 10100)
304311
.map(|(a, b)| *a + *b)
305312
.sum::<u64>();
@@ -309,23 +316,17 @@ fn bench_skip_then_zip(b: &mut Bencher) {
309316

310317
#[bench]
311318
fn bench_filter_count(b: &mut Bencher) {
312-
b.iter(|| {
313-
(0i64..1000000).map(black_box).filter(|x| x % 3 == 0).count()
314-
})
319+
b.iter(|| (0i64..1000000).map(black_box).filter(|x| x % 3 == 0).count())
315320
}
316321

317322
#[bench]
318323
fn bench_filter_ref_count(b: &mut Bencher) {
319-
b.iter(|| {
320-
(0i64..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
321-
})
324+
b.iter(|| (0i64..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count())
322325
}
323326

324327
#[bench]
325328
fn bench_filter_chain_count(b: &mut Bencher) {
326-
b.iter(|| {
327-
(0i64..1000000).chain(0..1000000).map(black_box).filter(|x| x % 3 == 0).count()
328-
})
329+
b.iter(|| (0i64..1000000).chain(0..1000000).map(black_box).filter(|x| x % 3 == 0).count())
329330
}
330331

331332
#[bench]

src/libcore/benches/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ extern crate test;
66
mod any;
77
mod ascii;
88
mod char;
9+
mod fmt;
910
mod hash;
1011
mod iter;
1112
mod num;
1213
mod ops;
1314
mod slice;
14-
mod fmt;

src/libcore/benches/num/flt2dec/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ mod strategy {
33
mod grisu;
44
}
55

6+
use core::num::flt2dec::MAX_SIG_DIGITS;
7+
use core::num::flt2dec::{decode, DecodableFloat, Decoded, FullDecoded};
68
use std::f64;
79
use std::io::Write;
810
use std::vec::Vec;
911
use test::Bencher;
10-
use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
11-
use core::num::flt2dec::MAX_SIG_DIGITS;
1212

1313
pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
1414
match decode(v).1 {
1515
FullDecoded::Finite(decoded) => decoded,
16-
full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
16+
full_decoded => panic!("expected finite, got {:?} instead", full_decoded),
1717
}
1818
}
1919

0 commit comments

Comments
 (0)