Skip to content

Commit 04e69e4

Browse files
committed
Auto merge of #66691 - dtolnay:fmt0, r=sfackler
Format libcore with rustfmt I am interested in whether we can begin cautious incremental progress on #66688 and assess along the way whether we can keep the disruption sufficiently small. This PR applies rustfmt with default settings to files in src/libcore *that are not involved in any currently open PR* to minimize merge conflicts. The list of files involved in open PRs was 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: ```console $ find src/libcore -name '*.rs' | xargs rustfmt --edition=2018 $ rg libcore outstanding_files | xargs git checkout -- ``` Repeating this process several months apart should get us coverage of most of the rest of libcore.
2 parents 876a72a + 166471e commit 04e69e4

Some content is hidden

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

53 files changed

+1802
-1296
lines changed

src/libcore/ascii.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#![stable(feature = "core_ascii", since = "1.26.0")]
1313

1414
use crate::fmt;
15-
use crate::ops::Range;
1615
use crate::iter::FusedIterator;
16+
use crate::ops::Range;
1717
use crate::str::from_utf8_unchecked;
1818

1919
/// An iterator over the escaped version of a byte.
@@ -100,15 +100,15 @@ pub fn escape_default(c: u8) -> EscapeDefault {
100100
b'\\' => ([b'\\', b'\\', 0, 0], 2),
101101
b'\'' => ([b'\\', b'\'', 0, 0], 2),
102102
b'"' => ([b'\\', b'"', 0, 0], 2),
103-
b'\x20' ..= b'\x7e' => ([c, 0, 0, 0], 1),
103+
b'\x20'..=b'\x7e' => ([c, 0, 0, 0], 1),
104104
_ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4),
105105
};
106106

107107
return EscapeDefault { range: 0..len, data };
108108

109109
fn hexify(b: u8) -> u8 {
110110
match b {
111-
0 ..= 9 => b'0' + b,
111+
0..=9 => b'0' + b,
112112
_ => b'a' + b - 10,
113113
}
114114
}
@@ -117,9 +117,15 @@ pub fn escape_default(c: u8) -> EscapeDefault {
117117
#[stable(feature = "rust1", since = "1.0.0")]
118118
impl Iterator for EscapeDefault {
119119
type Item = u8;
120-
fn next(&mut self) -> Option<u8> { self.range.next().map(|i| self.data[i]) }
121-
fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
122-
fn last(mut self) -> Option<u8> { self.next_back() }
120+
fn next(&mut self) -> Option<u8> {
121+
self.range.next().map(|i| self.data[i])
122+
}
123+
fn size_hint(&self) -> (usize, Option<usize>) {
124+
self.range.size_hint()
125+
}
126+
fn last(mut self) -> Option<u8> {
127+
self.next_back()
128+
}
123129
}
124130
#[stable(feature = "rust1", since = "1.0.0")]
125131
impl DoubleEndedIterator for EscapeDefault {

src/libcore/char/convert.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ impl From<u8> for char {
158158
}
159159
}
160160

161-
162161
/// An error which can be returned when parsing a char.
163162
#[stable(feature = "char_from_str", since = "1.20.0")]
164163
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -167,16 +166,16 @@ pub struct ParseCharError {
167166
}
168167

169168
impl ParseCharError {
170-
#[unstable(feature = "char_error_internals",
171-
reason = "this method should not be available publicly",
172-
issue = "0")]
169+
#[unstable(
170+
feature = "char_error_internals",
171+
reason = "this method should not be available publicly",
172+
issue = "0"
173+
)]
173174
#[doc(hidden)]
174175
pub fn __description(&self) -> &str {
175176
match self.kind {
176-
CharErrorKind::EmptyString => {
177-
"cannot parse char from empty string"
178-
},
179-
CharErrorKind::TooManyChars => "too many characters in string"
177+
CharErrorKind::EmptyString => "cannot parse char from empty string",
178+
CharErrorKind::TooManyChars => "too many characters in string",
180179
}
181180
}
182181
}
@@ -194,7 +193,6 @@ impl fmt::Display for ParseCharError {
194193
}
195194
}
196195

197-
198196
#[stable(feature = "char_from_str", since = "1.20.0")]
199197
impl FromStr for char {
200198
type Err = ParseCharError;
@@ -203,18 +201,13 @@ impl FromStr for char {
203201
fn from_str(s: &str) -> Result<Self, Self::Err> {
204202
let mut chars = s.chars();
205203
match (chars.next(), chars.next()) {
206-
(None, _) => {
207-
Err(ParseCharError { kind: CharErrorKind::EmptyString })
208-
},
204+
(None, _) => Err(ParseCharError { kind: CharErrorKind::EmptyString }),
209205
(Some(c), None) => Ok(c),
210-
_ => {
211-
Err(ParseCharError { kind: CharErrorKind::TooManyChars })
212-
}
206+
_ => Err(ParseCharError { kind: CharErrorKind::TooManyChars }),
213207
}
214208
}
215209
}
216210

217-
218211
#[stable(feature = "try_from", since = "1.34.0")]
219212
impl TryFrom<u32> for char {
220213
type Error = CharTryFromError;
@@ -304,11 +297,7 @@ pub fn from_digit(num: u32, radix: u32) -> Option<char> {
304297
}
305298
if num < radix {
306299
let num = num as u8;
307-
if num < 10 {
308-
Some((b'0' + num) as char)
309-
} else {
310-
Some((b'a' + num - 10) as char)
311-
}
300+
if num < 10 { Some((b'0' + num) as char) } else { Some((b'a' + num - 10) as char) }
312301
} else {
313302
None
314303
}

src/libcore/char/decode.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use super::from_u32_unchecked;
88
#[stable(feature = "decode_utf16", since = "1.9.0")]
99
#[derive(Clone, Debug)]
1010
pub struct DecodeUtf16<I>
11-
where I: Iterator<Item = u16>
11+
where
12+
I: Iterator<Item = u16>,
1213
{
1314
iter: I,
1415
buf: Option<u16>,
@@ -70,10 +71,7 @@ pub struct DecodeUtf16Error {
7071
#[stable(feature = "decode_utf16", since = "1.9.0")]
7172
#[inline]
7273
pub fn decode_utf16<I: IntoIterator<Item = u16>>(iter: I) -> DecodeUtf16<I::IntoIter> {
73-
DecodeUtf16 {
74-
iter: iter.into_iter(),
75-
buf: None,
76-
}
74+
DecodeUtf16 { iter: iter.into_iter(), buf: None }
7775
}
7876

7977
#[stable(feature = "decode_utf16", since = "1.9.0")]
@@ -83,7 +81,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
8381
fn next(&mut self) -> Option<Result<char, DecodeUtf16Error>> {
8482
let u = match self.buf.take() {
8583
Some(buf) => buf,
86-
None => self.iter.next()?
84+
None => self.iter.next()?,
8785
};
8886

8987
if u < 0xD800 || 0xDFFF < u {

src/libcore/char/methods.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ impl char {
130130
}
131131
};
132132

133-
if val < radix {
134-
Some(val)
135-
} else {
136-
None
137-
}
133+
if val < radix { Some(val) } else { None }
138134
}
139135

140136
/// Returns an iterator that yields the hexadecimal Unicode escape of a
@@ -950,11 +946,7 @@ impl char {
950946
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
951947
#[inline]
952948
pub fn to_ascii_uppercase(&self) -> char {
953-
if self.is_ascii() {
954-
(*self as u8).to_ascii_uppercase() as char
955-
} else {
956-
*self
957-
}
949+
if self.is_ascii() { (*self as u8).to_ascii_uppercase() as char } else { *self }
958950
}
959951

960952
/// Makes a copy of the value in its ASCII lower case equivalent.
@@ -982,11 +974,7 @@ impl char {
982974
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
983975
#[inline]
984976
pub fn to_ascii_lowercase(&self) -> char {
985-
if self.is_ascii() {
986-
(*self as u8).to_ascii_lowercase() as char
987-
} else {
988-
*self
989-
}
977+
if self.is_ascii() { (*self as u8).to_ascii_lowercase() as char } else { *self }
990978
}
991979

992980
/// Checks that two values are an ASCII case-insensitive match.

src/libcore/char/mod.rs

+40-41
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ mod decode;
2424
mod methods;
2525

2626
// stable re-exports
27-
#[stable(feature = "rust1", since = "1.0.0")]
28-
pub use self::convert::{from_u32, from_digit};
2927
#[stable(feature = "char_from_unchecked", since = "1.5.0")]
3028
pub use self::convert::from_u32_unchecked;
31-
#[stable(feature = "char_from_str", since = "1.20.0")]
32-
pub use self::convert::ParseCharError;
3329
#[stable(feature = "try_from", since = "1.34.0")]
3430
pub use self::convert::CharTryFromError;
31+
#[stable(feature = "char_from_str", since = "1.20.0")]
32+
pub use self::convert::ParseCharError;
33+
#[stable(feature = "rust1", since = "1.0.0")]
34+
pub use self::convert::{from_digit, from_u32};
3535
#[stable(feature = "decode_utf16", since = "1.9.0")]
3636
pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error};
3737

@@ -45,13 +45,13 @@ use crate::fmt::{self, Write};
4545
use crate::iter::FusedIterator;
4646

4747
// UTF-8 ranges and tags for encoding characters
48-
const TAG_CONT: u8 = 0b1000_0000;
49-
const TAG_TWO_B: u8 = 0b1100_0000;
50-
const TAG_THREE_B: u8 = 0b1110_0000;
51-
const TAG_FOUR_B: u8 = 0b1111_0000;
52-
const MAX_ONE_B: u32 = 0x80;
53-
const MAX_TWO_B: u32 = 0x800;
54-
const MAX_THREE_B: u32 = 0x10000;
48+
const TAG_CONT: u8 = 0b1000_0000;
49+
const TAG_TWO_B: u8 = 0b1100_0000;
50+
const TAG_THREE_B: u8 = 0b1110_0000;
51+
const TAG_FOUR_B: u8 = 0b1111_0000;
52+
const MAX_ONE_B: u32 = 0x80;
53+
const MAX_TWO_B: u32 = 0x800;
54+
const MAX_THREE_B: u32 = 0x10000;
5555

5656
/*
5757
Lu Uppercase_Letter an uppercase letter
@@ -190,11 +190,11 @@ impl Iterator for EscapeUnicode {
190190
match self.state {
191191
EscapeUnicodeState::Done => None,
192192

193-
EscapeUnicodeState::RightBrace |
194-
EscapeUnicodeState::Value |
195-
EscapeUnicodeState::LeftBrace |
196-
EscapeUnicodeState::Type |
197-
EscapeUnicodeState::Backslash => Some('}'),
193+
EscapeUnicodeState::RightBrace
194+
| EscapeUnicodeState::Value
195+
| EscapeUnicodeState::LeftBrace
196+
| EscapeUnicodeState::Type
197+
| EscapeUnicodeState::Backslash => Some('}'),
198198
}
199199
}
200200
}
@@ -204,14 +204,15 @@ impl ExactSizeIterator for EscapeUnicode {
204204
#[inline]
205205
fn len(&self) -> usize {
206206
// The match is a single memory access with no branching
207-
self.hex_digit_idx + match self.state {
208-
EscapeUnicodeState::Done => 0,
209-
EscapeUnicodeState::RightBrace => 1,
210-
EscapeUnicodeState::Value => 2,
211-
EscapeUnicodeState::LeftBrace => 3,
212-
EscapeUnicodeState::Type => 4,
213-
EscapeUnicodeState::Backslash => 5,
214-
}
207+
self.hex_digit_idx
208+
+ match self.state {
209+
EscapeUnicodeState::Done => 0,
210+
EscapeUnicodeState::RightBrace => 1,
211+
EscapeUnicodeState::Value => 2,
212+
EscapeUnicodeState::LeftBrace => 3,
213+
EscapeUnicodeState::Type => 4,
214+
EscapeUnicodeState::Backslash => 5,
215+
}
215216
}
216217
}
217218

@@ -238,7 +239,7 @@ impl fmt::Display for EscapeUnicode {
238239
#[derive(Clone, Debug)]
239240
#[stable(feature = "rust1", since = "1.0.0")]
240241
pub struct EscapeDefault {
241-
state: EscapeDefaultState
242+
state: EscapeDefaultState,
242243
}
243244

244245
#[derive(Clone, Debug)]
@@ -284,24 +285,20 @@ impl Iterator for EscapeDefault {
284285
EscapeDefaultState::Backslash(c) if n == 0 => {
285286
self.state = EscapeDefaultState::Char(c);
286287
Some('\\')
287-
},
288+
}
288289
EscapeDefaultState::Backslash(c) if n == 1 => {
289290
self.state = EscapeDefaultState::Done;
290291
Some(c)
291-
},
292+
}
292293
EscapeDefaultState::Backslash(_) => {
293294
self.state = EscapeDefaultState::Done;
294295
None
295-
},
296+
}
296297
EscapeDefaultState::Char(c) => {
297298
self.state = EscapeDefaultState::Done;
298299

299-
if n == 0 {
300-
Some(c)
301-
} else {
302-
None
303-
}
304-
},
300+
if n == 0 { Some(c) } else { None }
301+
}
305302
EscapeDefaultState::Done => None,
306303
EscapeDefaultState::Unicode(ref mut i) => i.nth(n),
307304
}
@@ -355,12 +352,16 @@ pub struct EscapeDebug(EscapeDefault);
355352
#[stable(feature = "char_escape_debug", since = "1.20.0")]
356353
impl Iterator for EscapeDebug {
357354
type Item = char;
358-
fn next(&mut self) -> Option<char> { self.0.next() }
359-
fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() }
355+
fn next(&mut self) -> Option<char> {
356+
self.0.next()
357+
}
358+
fn size_hint(&self) -> (usize, Option<usize>) {
359+
self.0.size_hint()
360+
}
360361
}
361362

362363
#[stable(feature = "char_escape_debug", since = "1.20.0")]
363-
impl ExactSizeIterator for EscapeDebug { }
364+
impl ExactSizeIterator for EscapeDebug {}
364365

365366
#[stable(feature = "fused", since = "1.26.0")]
366367
impl FusedIterator for EscapeDebug {}
@@ -440,7 +441,7 @@ impl CaseMappingIter {
440441
fn new(chars: [char; 3]) -> CaseMappingIter {
441442
if chars[2] == '\0' {
442443
if chars[1] == '\0' {
443-
CaseMappingIter::One(chars[0]) // Including if chars[0] == '\0'
444+
CaseMappingIter::One(chars[0]) // Including if chars[0] == '\0'
444445
} else {
445446
CaseMappingIter::Two(chars[0], chars[1])
446447
}
@@ -493,9 +494,7 @@ impl fmt::Display for CaseMappingIter {
493494
f.write_char(b)?;
494495
f.write_char(c)
495496
}
496-
CaseMappingIter::One(c) => {
497-
f.write_char(c)
498-
}
497+
CaseMappingIter::One(c) => f.write_char(c),
499498
CaseMappingIter::Zero => Ok(()),
500499
}
501500
}

0 commit comments

Comments
 (0)