Skip to content

Commit 23f7f59

Browse files
committed
style: start using rustfmt
1 parent 6bffb75 commit 23f7f59

28 files changed

+32931
-11708
lines changed

benches/bench.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ fn parse_medium2(b: &mut Bencher) {
5959
#[bench]
6060
fn parse_medium3(b: &mut Bencher) {
6161
b.iter(|| {
62-
let re = r"\p{age:3.2}\p{hira}\p{scx:hira}\p{alphabetic}\p{sc:Greek}\pL";
62+
let re =
63+
r"\p{age:3.2}\p{hira}\p{scx:hira}\p{alphabetic}\p{sc:Greek}\pL";
6364
Parser::new().parse(re).unwrap()
6465
});
6566
}

src/ast/mod.rs

+85-106
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::cmp::Ordering;
1616
use std::error;
1717
use std::fmt;
1818

19-
pub use ast::visitor::{Visitor, visit};
19+
pub use ast::visitor::{visit, Visitor};
2020

2121
pub mod parse;
2222
pub mod print;
@@ -202,11 +202,11 @@ impl error::Error for Error {
202202
EscapeUnexpectedEof => "unexpected eof (escape sequence)",
203203
EscapeUnrecognized => "unrecognized escape sequence",
204204
FlagDanglingNegation => "dangling flag negation operator",
205-
FlagDuplicate{..} => "duplicate flag",
206-
FlagRepeatedNegation{..} => "repeated negation",
205+
FlagDuplicate { .. } => "duplicate flag",
206+
FlagRepeatedNegation { .. } => "repeated negation",
207207
FlagUnexpectedEof => "unexpected eof (flag)",
208208
FlagUnrecognized => "unrecognized flag",
209-
GroupNameDuplicate{..} => "duplicate capture group name",
209+
GroupNameDuplicate { .. } => "duplicate capture group name",
210210
GroupNameEmpty => "empty capture group name",
211211
GroupNameInvalid => "invalid capture group name",
212212
GroupNameUnexpectedEof => "unclosed capture group name",
@@ -233,86 +233,67 @@ impl fmt::Display for ErrorKind {
233233
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
234234
use self::ErrorKind::*;
235235
match *self {
236-
CaptureLimitExceeded => {
237-
write!(f, "exceeded the maximum number of \
238-
capturing groups ({})", ::std::u32::MAX)
239-
}
236+
CaptureLimitExceeded => write!(
237+
f,
238+
"exceeded the maximum number of \
239+
capturing groups ({})",
240+
::std::u32::MAX
241+
),
240242
ClassEscapeInvalid => {
241243
write!(f, "invalid escape sequence found in character class")
242244
}
243-
ClassRangeInvalid => {
244-
write!(f, "invalid character class range, \
245-
the start must be <= the end")
246-
}
245+
ClassRangeInvalid => write!(
246+
f,
247+
"invalid character class range, \
248+
the start must be <= the end"
249+
),
247250
ClassRangeLiteral => {
248251
write!(f, "invalid range boundary, must be a literal")
249252
}
250-
ClassUnclosed => {
251-
write!(f, "unclosed character class")
252-
}
253-
DecimalEmpty => {
254-
write!(f, "decimal literal empty")
255-
}
256-
DecimalInvalid => {
257-
write!(f, "decimal literal invalid")
258-
}
259-
EscapeHexEmpty => {
260-
write!(f, "hexadecimal literal empty")
261-
}
253+
ClassUnclosed => write!(f, "unclosed character class"),
254+
DecimalEmpty => write!(f, "decimal literal empty"),
255+
DecimalInvalid => write!(f, "decimal literal invalid"),
256+
EscapeHexEmpty => write!(f, "hexadecimal literal empty"),
262257
EscapeHexInvalid => {
263258
write!(f, "hexadecimal literal is not a Unicode scalar value")
264259
}
265-
EscapeHexInvalidDigit => {
266-
write!(f, "invalid hexadecimal digit")
267-
}
268-
EscapeUnexpectedEof => {
269-
write!(f, "incomplete escape sequence, \
270-
reached end of pattern prematurely")
271-
}
272-
EscapeUnrecognized => {
273-
write!(f, "unrecognized escape sequence")
274-
}
260+
EscapeHexInvalidDigit => write!(f, "invalid hexadecimal digit"),
261+
EscapeUnexpectedEof => write!(
262+
f,
263+
"incomplete escape sequence, \
264+
reached end of pattern prematurely"
265+
),
266+
EscapeUnrecognized => write!(f, "unrecognized escape sequence"),
275267
FlagDanglingNegation => {
276268
write!(f, "dangling flag negation operator")
277269
}
278-
FlagDuplicate{..} => {
279-
write!(f, "duplicate flag")
280-
}
281-
FlagRepeatedNegation{..} => {
270+
FlagDuplicate { .. } => write!(f, "duplicate flag"),
271+
FlagRepeatedNegation { .. } => {
282272
write!(f, "flag negation operator repeated")
283273
}
284274
FlagUnexpectedEof => {
285275
write!(f, "expected flag but got end of regex")
286276
}
287-
FlagUnrecognized => {
288-
write!(f, "unrecognized flag")
289-
}
290-
GroupNameDuplicate{..} => {
277+
FlagUnrecognized => write!(f, "unrecognized flag"),
278+
GroupNameDuplicate { .. } => {
291279
write!(f, "duplicate capture group name")
292280
}
293-
GroupNameEmpty => {
294-
write!(f, "empty capture group name")
295-
}
296-
GroupNameInvalid => {
297-
write!(f, "invalid capture group character")
298-
}
299-
GroupNameUnexpectedEof => {
300-
write!(f, "unclosed capture group name")
301-
}
302-
GroupUnclosed => {
303-
write!(f, "unclosed group")
304-
}
305-
GroupUnopened => {
306-
write!(f, "unopened group")
307-
}
308-
NestLimitExceeded(limit) => {
309-
write!(f, "exceed the maximum number of \
310-
nested parentheses/brackets ({})", limit)
311-
}
312-
RepetitionCountInvalid => {
313-
write!(f, "invalid repetition count range, \
314-
the start must be <= the end")
315-
}
281+
GroupNameEmpty => write!(f, "empty capture group name"),
282+
GroupNameInvalid => write!(f, "invalid capture group character"),
283+
GroupNameUnexpectedEof => write!(f, "unclosed capture group name"),
284+
GroupUnclosed => write!(f, "unclosed group"),
285+
GroupUnopened => write!(f, "unopened group"),
286+
NestLimitExceeded(limit) => write!(
287+
f,
288+
"exceed the maximum number of \
289+
nested parentheses/brackets ({})",
290+
limit
291+
),
292+
RepetitionCountInvalid => write!(
293+
f,
294+
"invalid repetition count range, \
295+
the start must be <= the end"
296+
),
316297
RepetitionCountDecimalEmpty => {
317298
write!(f, "repetition quantifier expects a valid decimal")
318299
}
@@ -325,10 +306,11 @@ impl fmt::Display for ErrorKind {
325306
UnsupportedBackreference => {
326307
write!(f, "backreferences are not supported")
327308
}
328-
UnsupportedLookAround => {
329-
write!(f, "look-around, including look-ahead and look-behind, \
330-
is not supported")
331-
}
309+
UnsupportedLookAround => write!(
310+
f,
311+
"look-around, including look-ahead and look-behind, \
312+
is not supported"
313+
),
332314
_ => unreachable!(),
333315
}
334316
}
@@ -384,7 +366,8 @@ impl fmt::Debug for Position {
384366
write!(
385367
f,
386368
"Position(o: {:?}, l: {:?}, c: {:?})",
387-
self.offset, self.line, self.column)
369+
self.offset, self.line, self.column
370+
)
388371
}
389372
}
390373

@@ -868,7 +851,8 @@ impl ClassUnicode {
868851
pub fn is_negated(&self) -> bool {
869852
match self.kind {
870853
ClassUnicodeKind::NamedValue {
871-
op: ClassUnicodeOpKind::NotEqual, ..
854+
op: ClassUnicodeOpKind::NotEqual,
855+
..
872856
} => !self.negated,
873857
_ => self.negated,
874858
}
@@ -910,7 +894,7 @@ impl ClassUnicodeOpKind {
910894
/// Whether the op is an equality op or not.
911895
pub fn is_equal(&self) -> bool {
912896
match *self {
913-
ClassUnicodeOpKind::Equal|ClassUnicodeOpKind::Colon => true,
897+
ClassUnicodeOpKind::Equal | ClassUnicodeOpKind::Colon => true,
914898
_ => false,
915899
}
916900
}
@@ -1428,26 +1412,24 @@ impl Drop for ClassSet {
14281412
use std::mem;
14291413

14301414
match *self {
1431-
ClassSet::Item(ref item) => {
1432-
match *item {
1433-
ClassSetItem::Empty(_)
1434-
| ClassSetItem::Literal(_)
1435-
| ClassSetItem::Range(_)
1436-
| ClassSetItem::Ascii(_)
1437-
| ClassSetItem::Unicode(_)
1438-
| ClassSetItem::Perl(_) => return,
1439-
ClassSetItem::Bracketed(ref x) => {
1440-
if x.kind.is_empty() {
1441-
return;
1442-
}
1415+
ClassSet::Item(ref item) => match *item {
1416+
ClassSetItem::Empty(_)
1417+
| ClassSetItem::Literal(_)
1418+
| ClassSetItem::Range(_)
1419+
| ClassSetItem::Ascii(_)
1420+
| ClassSetItem::Unicode(_)
1421+
| ClassSetItem::Perl(_) => return,
1422+
ClassSetItem::Bracketed(ref x) => {
1423+
if x.kind.is_empty() {
1424+
return;
14431425
}
1444-
ClassSetItem::Union(ref x) => {
1445-
if x.items.is_empty() {
1446-
return;
1447-
}
1426+
}
1427+
ClassSetItem::Union(ref x) => {
1428+
if x.items.is_empty() {
1429+
return;
14481430
}
14491431
}
1450-
}
1432+
},
14511433
ClassSet::BinaryOp(ref op) => {
14521434
if op.lhs.is_empty() && op.rhs.is_empty() {
14531435
return;
@@ -1460,23 +1442,20 @@ impl Drop for ClassSet {
14601442
let mut stack = vec![mem::replace(self, empty_set())];
14611443
while let Some(mut set) = stack.pop() {
14621444
match set {
1463-
ClassSet::Item(ref mut item) => {
1464-
match *item {
1465-
ClassSetItem::Empty(_)
1466-
| ClassSetItem::Literal(_)
1467-
| ClassSetItem::Range(_)
1468-
| ClassSetItem::Ascii(_)
1469-
| ClassSetItem::Unicode(_)
1470-
| ClassSetItem::Perl(_) => {}
1471-
ClassSetItem::Bracketed(ref mut x) => {
1472-
stack.push(mem::replace(&mut x.kind, empty_set()));
1473-
}
1474-
ClassSetItem::Union(ref mut x) => {
1475-
stack.extend(
1476-
x.items.drain(..).map(ClassSet::Item));
1477-
}
1445+
ClassSet::Item(ref mut item) => match *item {
1446+
ClassSetItem::Empty(_)
1447+
| ClassSetItem::Literal(_)
1448+
| ClassSetItem::Range(_)
1449+
| ClassSetItem::Ascii(_)
1450+
| ClassSetItem::Unicode(_)
1451+
| ClassSetItem::Perl(_) => {}
1452+
ClassSetItem::Bracketed(ref mut x) => {
1453+
stack.push(mem::replace(&mut x.kind, empty_set()));
14781454
}
1479-
}
1455+
ClassSetItem::Union(ref mut x) => {
1456+
stack.extend(x.items.drain(..).map(ClassSet::Item));
1457+
}
1458+
},
14801459
ClassSet::BinaryOp(ref mut op) => {
14811460
stack.push(mem::replace(&mut op.lhs, empty_set()));
14821461
stack.push(mem::replace(&mut op.rhs, empty_set()));
@@ -1515,7 +1494,7 @@ mod tests {
15151494
// We run our test on a thread with a small stack size so we can
15161495
// force the issue more easily.
15171496
thread::Builder::new()
1518-
.stack_size(1<<10)
1497+
.stack_size(1 << 10)
15191498
.spawn(run)
15201499
.unwrap()
15211500
.join()

0 commit comments

Comments
 (0)