Skip to content

Commit 7b4bd5c

Browse files
marmelademaBurntSushi
authored andcommitted
regex: fix clippy lints up to rust 1.41.1
Some lints have been intentionally ignored, especially: * any lints that would change public APIs (like &self -> self) * any lints that would introduce new public APIs (like Default over new) Closes #780
1 parent 295a060 commit 7b4bd5c

14 files changed

+72
-85
lines changed

src/backtrack.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,7 @@ impl<'a, 'm, 'r, 's, I: Input> Bounded<'a, 'm, 'r, 's, I> {
9393
let mut cache = cache.borrow_mut();
9494
let cache = &mut cache.backtrack;
9595
let start = input.at(start);
96-
let mut b = Bounded {
97-
prog: prog,
98-
input: input,
99-
matches: matches,
100-
slots: slots,
101-
m: cache,
102-
};
96+
let mut b = Bounded { prog, input, matches, slots, m: cache };
10397
b.exec_(start, end)
10498
}
10599

@@ -220,14 +214,14 @@ impl<'a, 'm, 'r, 's, I: Input> Bounded<'a, 'm, 'r, 's, I> {
220214
// job is popped and the old capture index is restored.
221215
self.m.jobs.push(Job::SaveRestore {
222216
slot: inst.slot,
223-
old_pos: old_pos,
217+
old_pos,
224218
});
225219
self.slots[inst.slot] = Some(at.pos());
226220
}
227221
ip = inst.goto;
228222
}
229223
Split(ref inst) => {
230-
self.m.jobs.push(Job::Inst { ip: inst.goto2, at: at });
224+
self.m.jobs.push(Job::Inst { ip: inst.goto2, at });
231225
ip = inst.goto1;
232226
}
233227
EmptyLook(ref inst) => {

src/compile.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ impl Compiler {
149149
self.compiled.start = dotstar_patch.entry;
150150
}
151151
self.compiled.captures = vec![None];
152-
let patch = self.c_capture(0, expr)?.unwrap_or(self.next_inst());
152+
let patch =
153+
self.c_capture(0, expr)?.unwrap_or_else(|| self.next_inst());
153154
if self.compiled.needs_dotstar() {
154155
self.fill(dotstar_patch.hole, patch.entry);
155156
} else {
@@ -185,15 +186,15 @@ impl Compiler {
185186
self.fill_to_next(prev_hole);
186187
let split = self.push_split_hole();
187188
let Patch { hole, entry } =
188-
self.c_capture(0, expr)?.unwrap_or(self.next_inst());
189+
self.c_capture(0, expr)?.unwrap_or_else(|| self.next_inst());
189190
self.fill_to_next(hole);
190191
self.compiled.matches.push(self.insts.len());
191192
self.push_compiled(Inst::Match(i));
192193
prev_hole = self.fill_split(split, Some(entry), None);
193194
}
194195
let i = exprs.len() - 1;
195196
let Patch { hole, entry } =
196-
self.c_capture(0, &exprs[i])?.unwrap_or(self.next_inst());
197+
self.c_capture(0, &exprs[i])?.unwrap_or_else(|| self.next_inst());
197198
self.fill(prev_hole, entry);
198199
self.fill_to_next(hole);
199200
self.compiled.matches.push(self.insts.len());
@@ -410,11 +411,11 @@ impl Compiler {
410411
} else {
411412
let entry = self.insts.len();
412413
let hole = self.push_hole(InstHole::Save { slot: first_slot });
413-
let patch = self.c(expr)?.unwrap_or(self.next_inst());
414+
let patch = self.c(expr)?.unwrap_or_else(|| self.next_inst());
414415
self.fill(hole, patch.entry);
415416
self.fill_to_next(patch.hole);
416417
let hole = self.push_hole(InstHole::Save { slot: first_slot + 1 });
417-
Ok(Some(Patch { hole: hole, entry: entry }))
418+
Ok(Some(Patch { hole, entry }))
418419
}
419420
}
420421

@@ -448,7 +449,7 @@ impl Compiler {
448449
self.c_class(&[hir::ClassUnicodeRange::new(c, c)])
449450
}
450451
} else {
451-
let hole = self.push_hole(InstHole::Char { c: c });
452+
let hole = self.push_hole(InstHole::Char { c });
452453
Ok(Some(Patch { hole, entry: self.insts.len() - 1 }))
453454
}
454455
}
@@ -458,7 +459,7 @@ impl Compiler {
458459

459460
assert!(!ranges.is_empty());
460461
if self.compiled.uses_bytes() {
461-
Ok(Some(CompileClass { c: self, ranges: ranges }.compile()?))
462+
Ok(Some(CompileClass { c: self, ranges }.compile()?))
462463
} else {
463464
let ranges: Vec<(char, char)> =
464465
ranges.iter().map(|r| (r.start(), r.end())).collect();
@@ -467,9 +468,9 @@ impl Compiler {
467468
} else {
468469
self.extra_inst_bytes +=
469470
ranges.len() * (size_of::<char>() * 2);
470-
self.push_hole(InstHole::Ranges { ranges: ranges })
471+
self.push_hole(InstHole::Ranges { ranges })
471472
};
472-
Ok(Some(Patch { hole: hole, entry: self.insts.len() - 1 }))
473+
Ok(Some(Patch { hole, entry: self.insts.len() - 1 }))
473474
}
474475
}
475476

@@ -508,8 +509,8 @@ impl Compiler {
508509
}
509510

510511
fn c_empty_look(&mut self, look: EmptyLook) -> ResultOrEmpty {
511-
let hole = self.push_hole(InstHole::EmptyLook { look: look });
512-
Ok(Some(Patch { hole: hole, entry: self.insts.len() - 1 }))
512+
let hole = self.push_hole(InstHole::EmptyLook { look });
513+
Ok(Some(Patch { hole, entry: self.insts.len() - 1 }))
513514
}
514515

515516
fn c_concat<'a, I>(&mut self, exprs: I) -> ResultOrEmpty
@@ -533,7 +534,7 @@ impl Compiler {
533534
hole = p.hole;
534535
}
535536
}
536-
Ok(Some(Patch { hole: hole, entry: entry }))
537+
Ok(Some(Patch { hole, entry }))
537538
}
538539

539540
fn c_alternate(&mut self, exprs: &[Hir]) -> ResultOrEmpty {
@@ -676,7 +677,7 @@ impl Compiler {
676677
// None).
677678
let patch_concat = self
678679
.c_concat(iter::repeat(expr).take(min))?
679-
.unwrap_or(self.next_inst());
680+
.unwrap_or_else(|| self.next_inst());
680681
if let Some(patch_rep) = self.c_repeat_zero_or_more(expr, greedy)? {
681682
self.fill(patch_concat.hole, patch_rep.entry);
682683
Ok(Some(Patch { hole: patch_rep.hole, entry: patch_concat.entry }))
@@ -700,7 +701,7 @@ impl Compiler {
700701
}
701702
// Same reasoning as in c_repeat_range_min_or_more (we know that min <
702703
// max at this point).
703-
let patch_concat = patch_concat.unwrap_or(self.next_inst());
704+
let patch_concat = patch_concat.unwrap_or_else(|| self.next_inst());
704705
let initial_entry = patch_concat.entry;
705706
// It is much simpler to compile, e.g., `a{2,5}` as:
706707
//
@@ -879,14 +880,14 @@ impl MaybeInst {
879880
}
880881
MaybeInst::Split1(goto1) => {
881882
MaybeInst::Compiled(Inst::Split(InstSplit {
882-
goto1: goto1,
883+
goto1,
883884
goto2: goto,
884885
}))
885886
}
886887
MaybeInst::Split2(goto2) => {
887888
MaybeInst::Compiled(Inst::Split(InstSplit {
888889
goto1: goto,
889-
goto2: goto2,
890+
goto2,
890891
}))
891892
}
892893
_ => unreachable!(
@@ -900,9 +901,7 @@ impl MaybeInst {
900901

901902
fn fill_split(&mut self, goto1: InstPtr, goto2: InstPtr) {
902903
let filled = match *self {
903-
MaybeInst::Split => {
904-
Inst::Split(InstSplit { goto1: goto1, goto2: goto2 })
905-
}
904+
MaybeInst::Split => Inst::Split(InstSplit { goto1, goto2 }),
906905
_ => unreachable!(
907906
"must be called on Split instruction, \
908907
instead it was called on: {:?}",
@@ -960,19 +959,17 @@ enum InstHole {
960959
impl InstHole {
961960
fn fill(&self, goto: InstPtr) -> Inst {
962961
match *self {
963-
InstHole::Save { slot } => {
964-
Inst::Save(InstSave { goto: goto, slot: slot })
965-
}
962+
InstHole::Save { slot } => Inst::Save(InstSave { goto, slot }),
966963
InstHole::EmptyLook { look } => {
967-
Inst::EmptyLook(InstEmptyLook { goto: goto, look: look })
964+
Inst::EmptyLook(InstEmptyLook { goto, look })
968965
}
969-
InstHole::Char { c } => Inst::Char(InstChar { goto: goto, c: c }),
966+
InstHole::Char { c } => Inst::Char(InstChar { goto, c }),
970967
InstHole::Ranges { ref ranges } => Inst::Ranges(InstRanges {
971-
goto: goto,
968+
goto,
972969
ranges: ranges.clone().into_boxed_slice(),
973970
}),
974971
InstHole::Bytes { start, end } => {
975-
Inst::Bytes(InstBytes { goto: goto, start: start, end: end })
972+
Inst::Bytes(InstBytes { goto, start, end })
976973
}
977974
}
978975
}
@@ -1042,7 +1039,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
10421039
let mut last_hole = Hole::None;
10431040
for byte_range in seq {
10441041
let key = SuffixCacheKey {
1045-
from_inst: from_inst,
1042+
from_inst,
10461043
start: byte_range.start,
10471044
end: byte_range.end,
10481045
};
@@ -1132,7 +1129,7 @@ impl SuffixCache {
11321129
}
11331130
}
11341131
*pos = self.dense.len();
1135-
self.dense.push(SuffixCacheEntry { key: key, pc: pc });
1132+
self.dense.push(SuffixCacheEntry { key, pc });
11361133
None
11371134
}
11381135

@@ -1143,8 +1140,8 @@ impl SuffixCache {
11431140
fn hash(&self, suffix: &SuffixCacheKey) -> usize {
11441141
// Basic FNV-1a hash as described:
11451142
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
1146-
const FNV_PRIME: u64 = 1099511628211;
1147-
let mut h = 14695981039346656037;
1143+
const FNV_PRIME: u64 = 1_099_511_628_211;
1144+
let mut h = 14_695_981_039_346_656_037;
11481145
h = (h ^ (suffix.from_inst as u64)).wrapping_mul(FNV_PRIME);
11491146
h = (h ^ (suffix.start as u64)).wrapping_mul(FNV_PRIME);
11501147
h = (h ^ (suffix.end as u64)).wrapping_mul(FNV_PRIME);

src/dfa.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,10 @@ impl<'a> Fsm<'a> {
454454
let mut cache = cache.borrow_mut();
455455
let cache = &mut cache.dfa;
456456
let mut dfa = Fsm {
457-
prog: prog,
457+
prog,
458458
start: 0, // filled in below
459-
at: at,
460-
quit_after_match: quit_after_match,
459+
at,
460+
quit_after_match,
461461
last_match_si: STATE_UNKNOWN,
462462
last_cache_flush: at,
463463
cache: &mut cache.inner,
@@ -484,10 +484,10 @@ impl<'a> Fsm<'a> {
484484
let mut cache = cache.borrow_mut();
485485
let cache = &mut cache.dfa_reverse;
486486
let mut dfa = Fsm {
487-
prog: prog,
487+
prog,
488488
start: 0, // filled in below
489-
at: at,
490-
quit_after_match: quit_after_match,
489+
at,
490+
quit_after_match,
491491
last_match_si: STATE_UNKNOWN,
492492
last_cache_flush: at,
493493
cache: &mut cache.inner,
@@ -515,9 +515,9 @@ impl<'a> Fsm<'a> {
515515
let mut cache = cache.borrow_mut();
516516
let cache = &mut cache.dfa;
517517
let mut dfa = Fsm {
518-
prog: prog,
518+
prog,
519519
start: 0, // filled in below
520-
at: at,
520+
at,
521521
quit_after_match: false,
522522
last_match_si: STATE_UNKNOWN,
523523
last_cache_flush: at,
@@ -1606,11 +1606,7 @@ struct StateMap {
16061606

16071607
impl StateMap {
16081608
fn new(num_byte_classes: usize) -> StateMap {
1609-
StateMap {
1610-
map: HashMap::new(),
1611-
states: vec![],
1612-
num_byte_classes: num_byte_classes,
1613-
}
1609+
StateMap { map: HashMap::new(), states: vec![], num_byte_classes }
16141610
}
16151611

16161612
fn len(&self) -> usize {
@@ -1646,7 +1642,7 @@ impl Transitions {
16461642
/// The number of byte classes corresponds to the stride. Every state will
16471643
/// have `num_byte_classes` slots for transitions.
16481644
fn new(num_byte_classes: usize) -> Transitions {
1649-
Transitions { table: vec![], num_byte_classes: num_byte_classes }
1645+
Transitions { table: vec![], num_byte_classes }
16501646
}
16511647

16521648
/// Returns the total number of states currently in this table.
@@ -1696,27 +1692,27 @@ impl Transitions {
16961692

16971693
impl StateFlags {
16981694
fn is_match(&self) -> bool {
1699-
self.0 & 0b0000000_1 > 0
1695+
self.0 & 0b0000_0001 > 0
17001696
}
17011697

17021698
fn set_match(&mut self) {
1703-
self.0 |= 0b0000000_1;
1699+
self.0 |= 0b0000_0001;
17041700
}
17051701

17061702
fn is_word(&self) -> bool {
1707-
self.0 & 0b000000_1_0 > 0
1703+
self.0 & 0b0000_0010 > 0
17081704
}
17091705

17101706
fn set_word(&mut self) {
1711-
self.0 |= 0b000000_1_0;
1707+
self.0 |= 0b0000_0010;
17121708
}
17131709

17141710
fn has_empty(&self) -> bool {
1715-
self.0 & 0b00000_1_00 > 0
1711+
self.0 & 0b0000_0100 > 0
17161712
}
17171713

17181714
fn set_empty(&mut self) {
1719-
self.0 |= 0b00000_1_00;
1715+
self.0 |= 0b0000_0100;
17201716
}
17211717
}
17221718

src/exec.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ impl ExecBuilder {
288288
exprs.push(expr);
289289
}
290290
Ok(Parsed {
291-
exprs: exprs,
291+
exprs,
292292
prefixes: prefixes.unwrap_or_else(Literals::empty),
293293
suffixes: suffixes.unwrap_or_else(Literals::empty),
294-
bytes: bytes,
294+
bytes,
295295
})
296296
}
297297

@@ -311,7 +311,7 @@ impl ExecBuilder {
311311
match_type: MatchType::Nothing,
312312
});
313313
let pool = ExecReadOnly::new_pool(&ro);
314-
return Ok(Exec { ro: ro, pool });
314+
return Ok(Exec { ro, pool });
315315
}
316316
let parsed = self.parse()?;
317317
let mut nfa = Compiler::new()
@@ -340,12 +340,12 @@ impl ExecBuilder {
340340

341341
let mut ro = ExecReadOnly {
342342
res: self.options.pats,
343-
nfa: nfa,
344-
dfa: dfa,
345-
dfa_reverse: dfa_reverse,
343+
nfa,
344+
dfa,
345+
dfa_reverse,
346346
suffixes: LiteralSearcher::suffixes(parsed.suffixes),
347347
#[cfg(feature = "perf-literal")]
348-
ac: ac,
348+
ac,
349349
match_type: MatchType::Nothing,
350350
};
351351
ro.match_type = ro.choose_match_type(self.match_type);

src/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl From<usize> for Ref<'static> {
127127
/// If no such valid reference could be found, None is returned.
128128
fn find_cap_ref(replacement: &[u8]) -> Option<CaptureRef<'_>> {
129129
let mut i = 0;
130-
let rep: &[u8] = replacement.as_ref();
130+
let rep: &[u8] = replacement;
131131
if rep.len() <= 1 || rep[0] != b'$' {
132132
return None;
133133
}
@@ -136,7 +136,7 @@ fn find_cap_ref(replacement: &[u8]) -> Option<CaptureRef<'_>> {
136136
return find_cap_ref_braced(rep, i + 1);
137137
}
138138
let mut cap_end = i;
139-
while rep.get(cap_end).map_or(false, is_valid_cap_letter) {
139+
while rep.get(cap_end).copied().map_or(false, is_valid_cap_letter) {
140140
cap_end += 1;
141141
}
142142
if cap_end == i {
@@ -183,8 +183,8 @@ fn find_cap_ref_braced(rep: &[u8], mut i: usize) -> Option<CaptureRef<'_>> {
183183
}
184184

185185
/// Returns true if and only if the given byte is allowed in a capture name.
186-
fn is_valid_cap_letter(b: &u8) -> bool {
187-
match *b {
186+
fn is_valid_cap_letter(b: u8) -> bool {
187+
match b {
188188
b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'_' => true,
189189
_ => false,
190190
}

0 commit comments

Comments
 (0)