Skip to content

Commit 264ef3f

Browse files
committed
Revert some unwarranted clippy-changes
1 parent 94f8213 commit 264ef3f

24 files changed

+55
-129
lines changed

examples/shootout-regex-dna-replace.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ macro_rules! regex {
99
}}
1010
}
1111

12-
#[cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))]
13-
#[allow(regex_macro)]
1412
fn main() {
1513
let mut seq = String::with_capacity(50 * (1 << 20));
1614
io::stdin().read_to_string(&mut seq).unwrap();

examples/shootout-regex-dna-single.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use std::io::{self, Read};
1111

1212
macro_rules! regex { ($re:expr) => { ::regex::Regex::new($re).unwrap() } }
1313

14-
#[cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))]
15-
#[allow(trivial_regex)]
1614
fn main() {
1715
let mut seq = String::with_capacity(50 * (1 << 20));
1816
io::stdin().read_to_string(&mut seq).unwrap();

examples/shootout-regex-dna.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ use std::thread;
1313

1414
macro_rules! regex { ($re:expr) => { ::regex::Regex::new($re).unwrap() } }
1515

16-
#[cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))]
17-
#[allow(trivial_regex)]
1816
fn main() {
1917
let mut seq = String::with_capacity(51 * (1 << 20));
2018
io::stdin().read_to_string(&mut seq).unwrap();

src/compile.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ impl Compiler {
569569
greedy: bool,
570570
min: u32,
571571
) -> Result {
572-
let min = min as usize;
572+
let min = u32_to_usize(min);
573573
let patch_concat = try!(self.c_concat(iter::repeat(expr).take(min)));
574574
let patch_rep = try!(self.c_repeat_zero_or_more(expr, greedy));
575575
self.fill(patch_concat.hole, patch_rep.entry);
@@ -583,7 +583,7 @@ impl Compiler {
583583
min: u32,
584584
max: u32,
585585
) -> Result {
586-
let (min, max) = (min as usize, max as usize);
586+
let (min, max) = (u32_to_usize(min), u32_to_usize(max));
587587
let patch_concat = try!(self.c_concat(iter::repeat(expr).take(min)));
588588
let initial_entry = patch_concat.entry;
589589
if min == max {
@@ -713,12 +713,6 @@ impl Compiler {
713713
}
714714
}
715715

716-
impl Default for Compiler {
717-
fn default() -> Self {
718-
Self::new()
719-
}
720-
}
721-
722716
#[derive(Debug)]
723717
enum Hole {
724718
None,
@@ -1055,6 +1049,16 @@ impl ByteClassSet {
10551049
}
10561050
}
10571051

1052+
fn u32_to_usize(n: u32) -> usize {
1053+
// In case usize is less than 32 bits, we need to guard against overflow.
1054+
// On most platforms this compiles to nothing.
1055+
// TODO Use `std::convert::TryFrom` once it's stable.
1056+
if (n as u64) > (::std::usize::MAX as u64) {
1057+
panic!("BUG: {} is too big to be pointer sized", n)
1058+
}
1059+
n as usize
1060+
}
1061+
10581062
#[cfg(test)]
10591063
mod tests {
10601064
use super::ByteClassSet;

src/dfa.rs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ struct State{
271271
data: Box<[u8]>,
272272
}
273273

274-
/// `InstPt`r is a 32 bit pointer into a sequence of opcodes (i.e., it indexes
274+
/// `InstPtr` is a 32 bit pointer into a sequence of opcodes (i.e., it indexes
275275
/// an NFA state).
276276
///
277277
/// Throughout this library, this is usually set to `usize`, but we force a
@@ -484,7 +484,7 @@ impl<'a> Fsm<'a> {
484484
Some(STATE_DEAD) => return Result::NoMatch(at),
485485
Some(si) => si,
486486
};
487-
debug_assert_ne!(dfa.start, STATE_UNKNOWN);
487+
debug_assert!(dfa.start != STATE_UNKNOWN);
488488
dfa.exec_at(&mut cache.qcur, &mut cache.qnext, text)
489489
}
490490

@@ -517,7 +517,7 @@ impl<'a> Fsm<'a> {
517517
Some(STATE_DEAD) => return Result::NoMatch(at),
518518
Some(si) => si,
519519
};
520-
debug_assert_ne!(dfa.start, STATE_UNKNOWN);
520+
debug_assert!(dfa.start != STATE_UNKNOWN);
521521
dfa.exec_at_reverse(&mut cache.qcur, &mut cache.qnext, text)
522522
}
523523

@@ -529,7 +529,7 @@ impl<'a> Fsm<'a> {
529529
text: &[u8],
530530
at: usize,
531531
) -> Result<usize> {
532-
debug_assert_eq!(matches.len(), prog.matches.len());
532+
debug_assert!(matches.len() == prog.matches.len());
533533
let mut cache = cache.borrow_mut();
534534
let mut cache = &mut cache.dfa;
535535
let mut dfa = Fsm {
@@ -551,14 +551,14 @@ impl<'a> Fsm<'a> {
551551
Some(STATE_DEAD) => return Result::NoMatch(at),
552552
Some(si) => si,
553553
};
554-
debug_assert_ne!(dfa.start, STATE_UNKNOWN);
554+
debug_assert!(dfa.start != STATE_UNKNOWN);
555555
let result = dfa.exec_at(&mut cache.qcur, &mut cache.qnext, text);
556556
if result.is_match() {
557557
if matches.len() == 1 {
558558
matches[0] = true;
559559
} else {
560-
debug_assert_ne!(dfa.last_match_si, STATE_UNKNOWN);
561-
debug_assert_ne!(dfa.last_match_si, STATE_DEAD);
560+
debug_assert!(dfa.last_match_si != STATE_UNKNOWN);
561+
debug_assert!(dfa.last_match_si != STATE_DEAD);
562562
for ip in dfa.state(dfa.last_match_si).inst_ptrs() {
563563
if let Inst::Match(slot) = dfa.prog[ip] {
564564
matches[slot] = true;
@@ -730,7 +730,7 @@ impl<'a> Fsm<'a> {
730730
Some(STATE_DEAD) => return result.set_non_match(at),
731731
Some(si) => si,
732732
};
733-
debug_assert_ne!(next_si, STATE_UNKNOWN);
733+
debug_assert!(next_si != STATE_UNKNOWN);
734734
if next_si & STATE_MATCH > 0 {
735735
next_si &= !STATE_MATCH;
736736
result = Result::Match(at - 1);
@@ -754,7 +754,7 @@ impl<'a> Fsm<'a> {
754754
Some(STATE_DEAD) => return result.set_non_match(text.len()),
755755
Some(si) => si & !STATE_START,
756756
};
757-
debug_assert_ne!(prev_si, STATE_UNKNOWN);
757+
debug_assert!(prev_si != STATE_UNKNOWN);
758758
if prev_si & STATE_MATCH > 0 {
759759
prev_si &= !STATE_MATCH;
760760
self.last_match_si = prev_si;
@@ -835,7 +835,7 @@ impl<'a> Fsm<'a> {
835835
Some(STATE_DEAD) => return result.set_non_match(at),
836836
Some(si) => si,
837837
};
838-
debug_assert_ne!(next_si, STATE_UNKNOWN);
838+
debug_assert!(next_si != STATE_UNKNOWN);
839839
if next_si & STATE_MATCH > 0 {
840840
next_si &= !STATE_MATCH;
841841
result = Result::Match(at + 1);
@@ -856,7 +856,7 @@ impl<'a> Fsm<'a> {
856856
Some(STATE_DEAD) => return result.set_non_match(0),
857857
Some(si) => si,
858858
};
859-
debug_assert_ne!(prev_si, STATE_UNKNOWN);
859+
debug_assert!(prev_si != STATE_UNKNOWN);
860860
if prev_si & STATE_MATCH > 0 {
861861
prev_si &= !STATE_MATCH;
862862
self.last_match_si = prev_si;
@@ -1001,17 +1001,18 @@ impl<'a> Fsm<'a> {
10011001
}
10021002
}
10031003

1004-
let cache = if b.is_eof() && self.prog.matches.len() > 1 {
1005-
// If we're processing the last byte of the input and we're
1006-
// matching a regex set, then make the next state contain the
1007-
// previous states transitions. We do this so that the main
1008-
// matching loop can extract all of the match instructions.
1009-
mem::swap(qcur, qnext);
1010-
// And don't cache this state because it's totally bunk.
1011-
false
1012-
} else {
1013-
true
1014-
};
1004+
let cache =
1005+
if b.is_eof() && self.prog.matches.len() > 1 {
1006+
// If we're processing the last byte of the input and we're
1007+
// matching a regex set, then make the next state contain the
1008+
// previous states transitions. We do this so that the main
1009+
// matching loop can extract all of the match instructions.
1010+
mem::swap(qcur, qnext);
1011+
// And don't cache this state because it's totally bunk.
1012+
false
1013+
} else {
1014+
true
1015+
};
10151016

10161017
// We've now built up the set of NFA states that ought to comprise the
10171018
// next DFA state, so try to find it in the cache, and if it doesn't
@@ -1037,7 +1038,7 @@ impl<'a> Fsm<'a> {
10371038
if next <= STATE_MAX && self.state(next).flags().is_match() {
10381039
next |= STATE_MATCH;
10391040
}
1040-
debug_assert_ne!(next, STATE_UNKNOWN);
1041+
debug_assert!(next != STATE_UNKNOWN);
10411042
// And now store our state in the current state's next list.
10421043
if cache {
10431044
let cls = self.byte_class(b);
@@ -1173,10 +1174,11 @@ impl<'a> Fsm<'a> {
11731174
}
11741175
// If the cache has gotten too big, wipe it.
11751176
if self.approximate_size() > self.prog.dfa_size_limit
1176-
&& !self.clear_cache_and_save(current_state) {
1177-
// Ooops. DFA is giving up.
1178-
return None;
1179-
}
1177+
&& !self.clear_cache_and_save(current_state)
1178+
{
1179+
// Ooops. DFA is giving up.
1180+
return None;
1181+
}
11801182
// Allocate room for our state and add it.
11811183
self.add_state(key)
11821184
}
@@ -1377,7 +1379,7 @@ impl<'a> Fsm<'a> {
13771379
// matches are delayed by one byte, start states can never be match
13781380
// states.
13791381
let flagi = {
1380-
((empty_flags.start as u8) |
1382+
(((empty_flags.start as u8) << 0) |
13811383
((empty_flags.end as u8) << 1) |
13821384
((empty_flags.start_line as u8) << 2) |
13831385
((empty_flags.end_line as u8) << 3) |
@@ -1502,8 +1504,10 @@ impl<'a> Fsm<'a> {
15021504
self.cache.states.push(state.clone());
15031505
self.cache.compiled.insert(state, si);
15041506
// Transition table and set of states and map should all be in sync.
1505-
debug_assert_eq!(self.cache.states.len(), self.cache.trans.num_states());
1506-
debug_assert_eq!(self.cache.states.len(), self.cache.compiled.len());
1507+
debug_assert!(self.cache.states.len()
1508+
== self.cache.trans.num_states());
1509+
debug_assert!(self.cache.states.len()
1510+
== self.cache.compiled.len());
15071511
Some(si)
15081512
}
15091513

src/exec.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,14 @@ impl ExecBuilder {
226226
let expr = try!(parser.parse(pat));
227227
bytes = bytes || expr.has_bytes();
228228

229-
if (is_set || !expr.is_anchored_start())
230-
&& expr.has_anchored_start() {
231-
// Regex sets with anchors do not go well with literal
232-
// optimizations.
229+
if !expr.is_anchored_start() && expr.has_anchored_start() {
233230
// Partial anchors unfortunately make it hard to use prefixes,
234231
// so disable them.
235232
prefixes = None;
233+
} else if is_set && expr.is_anchored_start() {
234+
// Regex sets with anchors do not go well with literal
235+
// optimizations.
236+
prefixes = None;
236237
}
237238
prefixes = prefixes.and_then(|mut prefixes| {
238239
if !prefixes.union_prefixes(&expr) {

src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl InputAt {
5858
self.len
5959
}
6060

61-
/// Returns wether the UTF-8 width of the character at this position
61+
/// Returns whether the UTF-8 width of the character at this position
6262
/// is zero.
6363
pub fn is_empty(&self) -> bool {
6464
self.len == 0

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,6 @@ another matching engine with fixed memory requirements.
488488
*/
489489

490490
#![deny(missing_docs)]
491-
#![allow(inline_always)]
492-
#![cfg_attr(not(feature = "cargo-clippy"), allow(unknown_lints))]
493491
#![cfg_attr(test, deny(warnings))]
494492
#![cfg_attr(feature = "pattern", feature(pattern))]
495493
#![cfg_attr(feature = "simd-accel", feature(cfg_target_feature))]

src/pikevm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ impl<'r, I: Input> Fsm<'r, I> {
234234
///
235235
/// at and at_next are the current and next positions in the input. at or
236236
/// at_next may be EOF.
237-
#[allow(too_many_arguments)]
238237
fn step(
239238
&mut self,
240239
nlist: &mut Threads,

src/prog.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ impl Program {
158158
}
159159
}
160160

161-
impl Default for Program {
162-
fn default() -> Self {
163-
Self::new()
164-
}
165-
}
166-
167161
impl Deref for Program {
168162
type Target = [Inst];
169163

src/re_bytes.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,6 @@ pub struct Captures<'t> {
785785
named_groups: Arc<HashMap<String, usize>>,
786786
}
787787

788-
#[allow(len_without_is_empty)]
789788
impl<'t> Captures<'t> {
790789
/// Returns the match associated with the capture group at index `i`. If
791790
/// `i` does not correspond to a capture group, or if the capture group
@@ -987,7 +986,7 @@ pub trait Replacer {
987986
/// be beneficial to avoid finding sub-captures.
988987
///
989988
/// In general, this is called once for every call to `replacen`.
990-
fn no_expansion(&mut self) -> Option<Cow<[u8]>> {
989+
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, [u8]>> {
991990
None
992991
}
993992
}

src/re_trait.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub type Slot = Option<usize>;
2020
#[doc(hidden)]
2121
pub struct Locations(Vec<Slot>);
2222

23-
#[allow(len_without_is_empty)]
2423
impl Locations {
2524
/// Returns the start and end positions of the Nth capture group. Returns
2625
/// `None` if `i` is not a valid capture group or if the capture group did
@@ -165,7 +164,7 @@ pub trait RegularExpression: Sized {
165164
/// matches with captures.
166165
fn captures_iter(
167166
self,
168-
text: & Self::Text,
167+
text: &Self::Text,
169168
) -> CaptureMatches<Self> {
170169
CaptureMatches(self.find_iter(text))
171170
}

src/re_unicode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,6 @@ pub struct Captures<'t> {
936936
named_groups: NamedGroups,
937937
}
938938

939-
#[allow(len_without_is_empty)]
940939
impl<'t> Captures<'t> {
941940
/// Returns the match associated with the capture group at index `i`. If
942941
/// `i` does not correspond to a capture group, or if the capture group
@@ -1199,7 +1198,7 @@ pub trait Replacer {
11991198
/// be beneficial to avoid finding sub-captures.
12001199
///
12011200
/// In general, this is called once for every call to `replacen`.
1202-
fn no_expansion(&mut self) -> Option<Cow<str>> {
1201+
fn no_expansion<'r>(&'r mut self) -> Option<Cow<'r, str>> {
12031202
None
12041203
}
12051204
}

0 commit comments

Comments
 (0)