Skip to content

Commit 05eb81a

Browse files
committed
Auto merge of #29295 - little-dude:rustfmt_librustc_unicode, r=nrc
I didn't see anything particularly weird here. The last commit has the only changes I'm not 100% sure about. I ignored tables.rs since it's genrated, but I updated the python script that generates it. ?r @nrc
2 parents 04475b9 + 1bb7205 commit 05eb81a

File tree

3 files changed

+105
-54
lines changed

3 files changed

+105
-54
lines changed

src/etc/unicode.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,19 @@ def escape_char(c):
313313

314314
def emit_bsearch_range_table(f):
315315
f.write("""
316-
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
316+
fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool {
317317
use core::cmp::Ordering::{Equal, Less, Greater};
318318
use core::slice::SliceExt;
319-
r.binary_search_by(|&(lo,hi)| {
320-
if lo <= c && c <= hi { Equal }
321-
else if hi < c { Less }
322-
else { Greater }
323-
}).is_ok()
319+
r.binary_search_by(|&(lo, hi)| {
320+
if lo <= c && c <= hi {
321+
Equal
322+
} else if hi < c {
323+
Less
324+
} else {
325+
Greater
326+
}
327+
})
328+
.is_ok()
324329
}\n
325330
""")
326331

src/librustc_unicode/char.rs

+52-28
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ pub struct ToLowercase(CaseMappingIter);
4949
#[stable(feature = "rust1", since = "1.0.0")]
5050
impl Iterator for ToLowercase {
5151
type Item = char;
52-
fn next(&mut self) -> Option<char> { self.0.next() }
52+
fn next(&mut self) -> Option<char> {
53+
self.0.next()
54+
}
5355
}
5456

5557
/// An iterator over the uppercase mapping of a given character, returned from
@@ -61,15 +63,17 @@ pub struct ToUppercase(CaseMappingIter);
6163
#[stable(feature = "rust1", since = "1.0.0")]
6264
impl Iterator for ToUppercase {
6365
type Item = char;
64-
fn next(&mut self) -> Option<char> { self.0.next() }
66+
fn next(&mut self) -> Option<char> {
67+
self.0.next()
68+
}
6569
}
6670

6771

6872
enum CaseMappingIter {
6973
Three(char, char, char),
7074
Two(char, char),
7175
One(char),
72-
Zero
76+
Zero,
7377
}
7478

7579
impl CaseMappingIter {
@@ -165,7 +169,9 @@ impl char {
165169
/// ```
166170
#[stable(feature = "rust1", since = "1.0.0")]
167171
#[inline]
168-
pub fn is_digit(self, radix: u32) -> bool { C::is_digit(self, radix) }
172+
pub fn is_digit(self, radix: u32) -> bool {
173+
C::is_digit(self, radix)
174+
}
169175

170176
/// Converts a `char` to a digit in the given radix.
171177
///
@@ -229,7 +235,9 @@ impl char {
229235
/// ```
230236
#[stable(feature = "rust1", since = "1.0.0")]
231237
#[inline]
232-
pub fn to_digit(self, radix: u32) -> Option<u32> { C::to_digit(self, radix) }
238+
pub fn to_digit(self, radix: u32) -> Option<u32> {
239+
C::to_digit(self, radix)
240+
}
233241

234242
/// Returns an iterator that yields the hexadecimal Unicode escape of a
235243
/// character, as `char`s.
@@ -262,7 +270,9 @@ impl char {
262270
/// ```
263271
#[stable(feature = "rust1", since = "1.0.0")]
264272
#[inline]
265-
pub fn escape_unicode(self) -> EscapeUnicode { C::escape_unicode(self) }
273+
pub fn escape_unicode(self) -> EscapeUnicode {
274+
C::escape_unicode(self)
275+
}
266276

267277
/// Returns an iterator that yields the literal escape code of a `char`.
268278
///
@@ -309,7 +319,9 @@ impl char {
309319
/// ```
310320
#[stable(feature = "rust1", since = "1.0.0")]
311321
#[inline]
312-
pub fn escape_default(self) -> EscapeDefault { C::escape_default(self) }
322+
pub fn escape_default(self) -> EscapeDefault {
323+
C::escape_default(self)
324+
}
313325

314326
/// Returns the number of bytes this `char` would need if encoded in UTF-8.
315327
///
@@ -358,7 +370,9 @@ impl char {
358370
/// ```
359371
#[stable(feature = "rust1", since = "1.0.0")]
360372
#[inline]
361-
pub fn len_utf8(self) -> usize { C::len_utf8(self) }
373+
pub fn len_utf8(self) -> usize {
374+
C::len_utf8(self)
375+
}
362376

363377
/// Returns the number of 16-bit code units this `char` would need if
364378
/// encoded in UTF-16.
@@ -378,7 +392,9 @@ impl char {
378392
/// ```
379393
#[stable(feature = "rust1", since = "1.0.0")]
380394
#[inline]
381-
pub fn len_utf16(self) -> usize { C::len_utf16(self) }
395+
pub fn len_utf16(self) -> usize {
396+
C::len_utf16(self)
397+
}
382398

383399
/// Encodes this character as UTF-8 into the provided byte buffer, and then
384400
/// returns the number of bytes written.
@@ -482,9 +498,9 @@ impl char {
482498
#[inline]
483499
pub fn is_alphabetic(self) -> bool {
484500
match self {
485-
'a' ... 'z' | 'A' ... 'Z' => true,
501+
'a'...'z' | 'A'...'Z' => true,
486502
c if c > '\x7f' => derived_property::Alphabetic(c),
487-
_ => false
503+
_ => false,
488504
}
489505
}
490506

@@ -498,7 +514,9 @@ impl char {
498514
reason = "mainly needed for compiler internals",
499515
issue = "0")]
500516
#[inline]
501-
pub fn is_xid_start(self) -> bool { derived_property::XID_Start(self) }
517+
pub fn is_xid_start(self) -> bool {
518+
derived_property::XID_Start(self)
519+
}
502520

503521
/// Returns true if this `char` satisfies the 'XID_Continue' Unicode property, and false
504522
/// otherwise.
@@ -510,7 +528,9 @@ impl char {
510528
reason = "mainly needed for compiler internals",
511529
issue = "0")]
512530
#[inline]
513-
pub fn is_xid_continue(self) -> bool { derived_property::XID_Continue(self) }
531+
pub fn is_xid_continue(self) -> bool {
532+
derived_property::XID_Continue(self)
533+
}
514534

515535
/// Returns true if this `char` is lowercase, and false otherwise.
516536
///
@@ -542,9 +562,9 @@ impl char {
542562
#[inline]
543563
pub fn is_lowercase(self) -> bool {
544564
match self {
545-
'a' ... 'z' => true,
565+
'a'...'z' => true,
546566
c if c > '\x7f' => derived_property::Lowercase(c),
547-
_ => false
567+
_ => false,
548568
}
549569
}
550570

@@ -578,9 +598,9 @@ impl char {
578598
#[inline]
579599
pub fn is_uppercase(self) -> bool {
580600
match self {
581-
'A' ... 'Z' => true,
601+
'A'...'Z' => true,
582602
c if c > '\x7f' => derived_property::Uppercase(c),
583-
_ => false
603+
_ => false,
584604
}
585605
}
586606

@@ -608,9 +628,9 @@ impl char {
608628
#[inline]
609629
pub fn is_whitespace(self) -> bool {
610630
match self {
611-
' ' | '\x09' ... '\x0d' => true,
631+
' ' | '\x09'...'\x0d' => true,
612632
c if c > '\x7f' => property::White_Space(c),
613-
_ => false
633+
_ => false,
614634
}
615635
}
616636

@@ -673,7 +693,9 @@ impl char {
673693
/// ```
674694
#[stable(feature = "rust1", since = "1.0.0")]
675695
#[inline]
676-
pub fn is_control(self) -> bool { general_category::Cc(self) }
696+
pub fn is_control(self) -> bool {
697+
general_category::Cc(self)
698+
}
677699

678700
/// Returns true if this `char` is numeric, and false otherwise.
679701
///
@@ -713,9 +735,9 @@ impl char {
713735
#[inline]
714736
pub fn is_numeric(self) -> bool {
715737
match self {
716-
'0' ... '9' => true,
738+
'0'...'9' => true,
717739
c if c > '\x7f' => general_category::N(c),
718-
_ => false
740+
_ => false,
719741
}
720742
}
721743

@@ -823,7 +845,9 @@ impl char {
823845
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
824846
#[unstable(feature = "decode_utf16", reason = "recently exposed", issue = "27830")]
825847
#[derive(Clone)]
826-
pub struct DecodeUtf16<I> where I: Iterator<Item=u16> {
848+
pub struct DecodeUtf16<I>
849+
where I: Iterator<Item = u16>
850+
{
827851
iter: I,
828852
buf: Option<u16>,
829853
}
@@ -874,7 +898,7 @@ pub struct DecodeUtf16<I> where I: Iterator<Item=u16> {
874898
/// ```
875899
#[unstable(feature = "decode_utf16", reason = "recently exposed", issue = "27830")]
876900
#[inline]
877-
pub fn decode_utf16<I: IntoIterator<Item=u16>>(iterable: I) -> DecodeUtf16<I::IntoIter> {
901+
pub fn decode_utf16<I: IntoIterator<Item = u16>>(iterable: I) -> DecodeUtf16<I::IntoIter> {
878902
DecodeUtf16 {
879903
iter: iterable.into_iter(),
880904
buf: None,
@@ -890,8 +914,8 @@ impl<I: Iterator<Item=u16>> Iterator for DecodeUtf16<I> {
890914
Some(buf) => buf,
891915
None => match self.iter.next() {
892916
Some(u) => u,
893-
None => return None
894-
}
917+
None => return None,
918+
},
895919
};
896920

897921
if u < 0xD800 || 0xDFFF < u {
@@ -904,13 +928,13 @@ impl<I: Iterator<Item=u16>> Iterator for DecodeUtf16<I> {
904928
let u2 = match self.iter.next() {
905929
Some(u2) => u2,
906930
// eof
907-
None => return Some(Err(u))
931+
None => return Some(Err(u)),
908932
};
909933
if u2 < 0xDC00 || u2 > 0xDFFF {
910934
// not a trailing surrogate so we're not a valid
911935
// surrogate pair, so rewind to redecode u2 next time.
912936
self.buf = Some(u2);
913-
return Some(Err(u))
937+
return Some(Err(u));
914938
}
915939

916940
// all ok, so lets decode it.

0 commit comments

Comments
 (0)