Skip to content

Commit 20bc598

Browse files
chris-ha458BurntSushi
authored andcommitted
lint: fix a selection of Clippy lints
PR #1129
1 parent 71233b5 commit 20bc598

File tree

13 files changed

+32
-49
lines changed

13 files changed

+32
-49
lines changed

regex-automata/src/nfa/thompson/compiler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ impl Compiler {
16651665
capture_index: u32,
16661666
name: Option<&str>,
16671667
) -> Result<StateID, BuildError> {
1668-
let name = name.map(|n| Arc::from(n));
1668+
let name = name.map(Arc::from);
16691669
self.builder.borrow_mut().add_capture_start(
16701670
StateID::ZERO,
16711671
capture_index,

regex-automata/src/nfa/thompson/nfa.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,13 +1471,13 @@ impl fmt::Debug for Inner {
14711471
}
14721472
let pattern_len = self.start_pattern.len();
14731473
if pattern_len > 1 {
1474-
writeln!(f, "")?;
1474+
writeln!(f)?;
14751475
for pid in 0..pattern_len {
14761476
let sid = self.start_pattern[pid];
14771477
writeln!(f, "START({:06?}): {:?}", pid, sid.as_usize())?;
14781478
}
14791479
}
1480-
writeln!(f, "")?;
1480+
writeln!(f)?;
14811481
writeln!(
14821482
f,
14831483
"transition equivalence classes: {:?}",
@@ -1819,7 +1819,7 @@ impl SparseTransitions {
18191819
&self,
18201820
unit: alphabet::Unit,
18211821
) -> Option<StateID> {
1822-
unit.as_u8().map_or(None, |byte| self.matches_byte(byte))
1822+
unit.as_u8().and_then(|byte| self.matches_byte(byte))
18231823
}
18241824

18251825
/// This follows the matching transition for a particular byte.
@@ -1909,7 +1909,7 @@ impl DenseTransitions {
19091909
&self,
19101910
unit: alphabet::Unit,
19111911
) -> Option<StateID> {
1912-
unit.as_u8().map_or(None, |byte| self.matches_byte(byte))
1912+
unit.as_u8().and_then(|byte| self.matches_byte(byte))
19131913
}
19141914

19151915
/// This follows the matching transition for a particular byte.

regex-automata/src/nfa/thompson/pikevm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ impl PikeVM {
12901290
// the only thing in 'curr'. So we might as well just skip
12911291
// ahead until we find something that we know might advance us
12921292
// forward.
1293-
if let Some(ref pre) = pre {
1293+
if let Some(pre) = pre {
12941294
let span = Span::from(at..input.end());
12951295
match pre.find(input.haystack(), span) {
12961296
None => break,
@@ -1344,7 +1344,7 @@ impl PikeVM {
13441344
// search. If we re-computed it at every position, we would be
13451345
// simulating an unanchored search when we were tasked to perform
13461346
// an anchored search.
1347-
if (!hm.is_some() || allmatches)
1347+
if (hm.is_none() || allmatches)
13481348
&& (!anchored || at == input.start())
13491349
{
13501350
// Since we are adding to the 'curr' active states and since

regex-automata/src/nfa/thompson/range_trie.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl RangeTrie {
235235
/// Clear this range trie such that it is empty. Clearing a range trie
236236
/// and reusing it can beneficial because this may reuse allocations.
237237
pub fn clear(&mut self) {
238-
self.free.extend(self.states.drain(..));
238+
self.free.append(&mut self.states);
239239
self.add_empty(); // final
240240
self.add_empty(); // root
241241
}
@@ -296,7 +296,7 @@ impl RangeTrie {
296296
assert!(!ranges.is_empty());
297297
assert!(ranges.len() <= 4);
298298

299-
let mut stack = mem::replace(&mut self.insert_stack, vec![]);
299+
let mut stack = core::mem::replace(&mut self.insert_stack, vec![]);
300300
stack.clear();
301301

302302
stack.push(NextInsert::new(ROOT, ranges));
@@ -866,7 +866,7 @@ impl Split {
866866

867867
impl fmt::Debug for RangeTrie {
868868
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
869-
writeln!(f, "")?;
869+
writeln!(f)?;
870870
for (i, state) in self.states.iter().enumerate() {
871871
let status = if i == FINAL.as_usize() { '*' } else { ' ' };
872872
writeln!(f, "{}{:06}: {:?}", status, i, state)?;

regex-automata/src/util/determinize/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub(crate) fn next(
131131
if !state.look_need().is_empty() {
132132
// Add look-ahead assertions that are now true based on the current
133133
// input unit.
134-
let mut look_have = state.look_have().clone();
134+
let mut look_have = state.look_have();
135135
match unit.as_u8() {
136136
Some(b'\r') => {
137137
if !rev || !state.is_half_crlf() {

regex-automata/src/util/determinize/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(crate) struct State(Arc<[u8]>);
115115
/// without having to convert it into a State first.
116116
impl core::borrow::Borrow<[u8]> for State {
117117
fn borrow(&self) -> &[u8] {
118-
&*self.0
118+
&self.0
119119
}
120120
}
121121

@@ -177,7 +177,7 @@ impl State {
177177
}
178178

179179
fn repr(&self) -> Repr<'_> {
180-
Repr(&*self.0)
180+
Repr(&self.0)
181181
}
182182
}
183183

@@ -461,7 +461,7 @@ impl<'a> Repr<'a> {
461461
/// If this state is not a match state, then this always returns 0.
462462
fn match_len(&self) -> usize {
463463
if !self.is_match() {
464-
return 0;
464+
0
465465
} else if !self.has_pattern_ids() {
466466
1
467467
} else {

regex-automata/src/util/interpolate.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,7 @@ fn find_cap_ref_braced(rep: &[u8], mut i: usize) -> Option<CaptureRef<'_>> {
321321
/// Returns true if and only if the given byte is allowed in a capture name
322322
/// written in non-brace form.
323323
fn is_valid_cap_letter(b: u8) -> bool {
324-
match b {
325-
b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'_' => true,
326-
_ => false,
327-
}
324+
matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'_')
328325
}
329326

330327
#[cfg(test)]

regex-automata/src/util/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ mod inner {
678678
#[inline]
679679
pub(super) fn value(&self) -> &T {
680680
match self.value {
681-
Ok(ref v) => &**v,
681+
Ok(ref v) => v,
682682
// SAFETY: This is safe because the only way a PoolGuard gets
683683
// created for self.value=Err is when the current thread
684684
// corresponds to the owning thread, of which there can only
@@ -703,7 +703,7 @@ mod inner {
703703
#[inline]
704704
pub(super) fn value_mut(&mut self) -> &mut T {
705705
match self.value {
706-
Ok(ref mut v) => &mut **v,
706+
Ok(ref mut v) => v,
707707
// SAFETY: This is safe because the only way a PoolGuard gets
708708
// created for self.value=None is when the current thread
709709
// corresponds to the owning thread, of which there can only

regex-automata/src/util/prefilter/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,17 @@ pub(crate) trait PrefilterI:
501501
impl<P: PrefilterI + ?Sized> PrefilterI for Arc<P> {
502502
#[cfg_attr(feature = "perf-inline", inline(always))]
503503
fn find(&self, haystack: &[u8], span: Span) -> Option<Span> {
504-
(&**self).find(haystack, span)
504+
(**self).find(haystack, span)
505505
}
506506

507507
#[cfg_attr(feature = "perf-inline", inline(always))]
508508
fn prefix(&self, haystack: &[u8], span: Span) -> Option<Span> {
509-
(&**self).prefix(haystack, span)
509+
(**self).prefix(haystack, span)
510510
}
511511

512512
#[cfg_attr(feature = "perf-inline", inline(always))]
513513
fn memory_usage(&self) -> usize {
514-
(&**self).memory_usage()
514+
(**self).memory_usage()
515515
}
516516

517517
#[cfg_attr(feature = "perf-inline", inline(always))]

regex-automata/src/util/search.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,13 +1694,14 @@ impl Anchored {
16941694
/// # Ok::<(), Box<dyn std::error::Error>>(())
16951695
/// ```
16961696
#[non_exhaustive]
1697-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1697+
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
16981698
pub enum MatchKind {
16991699
/// Report all possible matches.
17001700
All,
17011701
/// Report only the leftmost matches. When multiple leftmost matches exist,
17021702
/// report the match corresponding to the part of the regex that appears
17031703
/// first in the syntax.
1704+
#[default]
17041705
LeftmostFirst,
17051706
// There is prior art in RE2 that shows that we should be able to add
17061707
// LeftmostLongest too. The tricky part of it is supporting ungreedy
@@ -1726,12 +1727,6 @@ impl MatchKind {
17261727
}
17271728
}
17281729

1729-
impl Default for MatchKind {
1730-
fn default() -> MatchKind {
1731-
MatchKind::LeftmostFirst
1732-
}
1733-
}
1734-
17351730
/// An error indicating that a search stopped before reporting whether a
17361731
/// match exists or not.
17371732
///

0 commit comments

Comments
 (0)