Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eeb6be4

Browse files
committedMay 15, 2021
Fix clippy lints up to rust 1.41.1 in regex-syntax crate
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)
1 parent 6cdb904 commit eeb6be4

File tree

13 files changed

+108
-139
lines changed

13 files changed

+108
-139
lines changed
 

‎regex-syntax/src/ast/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl PartialOrd for Position {
385385
impl Span {
386386
/// Create a new span with the given positions.
387387
pub fn new(start: Position, end: Position) -> Span {
388-
Span { start: start, end: end }
388+
Span { start, end }
389389
}
390390

391391
/// Create a new span using the given position as the start and end.
@@ -427,7 +427,7 @@ impl Position {
427427
///
428428
/// `column` is the approximate column number, starting at `1`.
429429
pub fn new(offset: usize, line: usize, column: usize) -> Position {
430-
Position { offset: offset, line: line, column: column }
430+
Position { offset, line, column }
431431
}
432432
}
433433

‎regex-syntax/src/ast/parse.rs

Lines changed: 54 additions & 77 deletions
Large diffs are not rendered by default.

‎regex-syntax/src/ast/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Printer {
5757
/// here are a `fmt::Formatter` (which is available in `fmt::Display`
5858
/// implementations) or a `&mut String`.
5959
pub fn print<W: fmt::Write>(&mut self, ast: &Ast, wtr: W) -> fmt::Result {
60-
visitor::visit(ast, Writer { printer: self, wtr: wtr })
60+
visitor::visit(ast, Writer { printer: self, wtr })
6161
}
6262
}
6363

‎regex-syntax/src/ast/visitor.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a> HeapVisitor<'a> {
388388
Some(ClassFrame::Union { head: item, tail: &[] })
389389
}
390390
ast::ClassSet::BinaryOp(ref op) => {
391-
Some(ClassFrame::Binary { op: op })
391+
Some(ClassFrame::Binary { op })
392392
}
393393
}
394394
}
@@ -402,11 +402,9 @@ impl<'a> HeapVisitor<'a> {
402402
})
403403
}
404404
}
405-
ClassInduct::BinaryOp(op) => Some(ClassFrame::BinaryLHS {
406-
op: op,
407-
lhs: &op.lhs,
408-
rhs: &op.rhs,
409-
}),
405+
ClassInduct::BinaryOp(op) => {
406+
Some(ClassFrame::BinaryLHS { op, lhs: &op.lhs, rhs: &op.rhs })
407+
}
410408
_ => None,
411409
}
412410
}
@@ -427,7 +425,7 @@ impl<'a> HeapVisitor<'a> {
427425
}
428426
ClassFrame::Binary { .. } => None,
429427
ClassFrame::BinaryLHS { op, rhs, .. } => {
430-
Some(ClassFrame::BinaryRHS { op: op, rhs: rhs })
428+
Some(ClassFrame::BinaryRHS { op, rhs })
431429
}
432430
ClassFrame::BinaryRHS { .. } => None,
433431
}

‎regex-syntax/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'p> Spans<'p> {
182182
if line_count <= 1 { 0 } else { line_count.to_string().len() };
183183
let mut spans = Spans {
184184
pattern: &fmter.pattern,
185-
line_number_width: line_number_width,
185+
line_number_width,
186186
by_line: vec![vec![]; line_count],
187187
multi_line: vec![],
188188
};
@@ -288,7 +288,7 @@ fn repeat_char(c: char, count: usize) -> String {
288288
mod tests {
289289
use crate::ast::parse::Parser;
290290

291-
fn assert_panic_message(pattern: &str, expected_msg: &str) -> () {
291+
fn assert_panic_message(pattern: &str, expected_msg: &str) {
292292
let result = Parser::new().parse(pattern);
293293
match result {
294294
Ok(_) => {

‎regex-syntax/src/hir/interval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ impl<I: Interval> IntervalSet<I> {
114114
// we're done.
115115
let drain_end = self.ranges.len();
116116

117-
let mut ita = (0..drain_end).into_iter();
118-
let mut itb = (0..other.ranges.len()).into_iter();
117+
let mut ita = 0..drain_end;
118+
let mut itb = 0..other.ranges.len();
119119
let mut a = ita.next().unwrap();
120120
let mut b = itb.next().unwrap();
121121
loop {
@@ -394,7 +394,7 @@ pub trait Interval:
394394
return (None, None);
395395
}
396396
if self.is_intersection_empty(other) {
397-
return (Some(self.clone()), None);
397+
return (Some(*self), None);
398398
}
399399
let add_lower = other.lower() > self.lower();
400400
let add_upper = other.upper() < self.upper();
@@ -425,11 +425,11 @@ pub trait Interval:
425425
other: &Self,
426426
) -> (Option<Self>, Option<Self>) {
427427
let union = match self.union(other) {
428-
None => return (Some(self.clone()), Some(other.clone())),
428+
None => return (Some(*self), Some(*other)),
429429
Some(union) => union,
430430
};
431431
let intersection = match self.intersect(other) {
432-
None => return (Some(self.clone()), Some(other.clone())),
432+
None => return (Some(*self), Some(*other)),
433433
Some(intersection) => intersection,
434434
};
435435
union.difference(&intersection)

‎regex-syntax/src/hir/literal/mod.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl Literals {
225225
if self.lits.is_empty() {
226226
return self.to_empty();
227227
}
228-
let mut old: Vec<Literal> = self.lits.iter().cloned().collect();
228+
let mut old = self.lits.to_vec();
229229
let mut new = self.to_empty();
230230
'OUTER: while let Some(mut candidate) = old.pop() {
231231
if candidate.is_empty() {
@@ -256,15 +256,13 @@ impl Literals {
256256
old.push(lit3);
257257
lit2.clear();
258258
}
259-
} else {
260-
if let Some(i) = position(&lit2, &candidate) {
261-
lit2.cut();
262-
let mut new_candidate = candidate.clone();
263-
new_candidate.truncate(i);
264-
new_candidate.cut();
265-
old.push(new_candidate);
266-
candidate.clear();
267-
}
259+
} else if let Some(i) = position(&lit2, &candidate) {
260+
lit2.cut();
261+
let mut new_candidate = candidate.clone();
262+
new_candidate.truncate(i);
263+
new_candidate.cut();
264+
old.push(new_candidate);
265+
candidate.clear();
268266
}
269267
// Oops, the candidate is already represented in the set.
270268
if candidate.is_empty() {
@@ -793,7 +791,7 @@ fn repeat_range_literals<F: FnMut(&Hir, &mut Literals)>(
793791
f(
794792
&Hir::repetition(hir::Repetition {
795793
kind: hir::RepetitionKind::ZeroOrMore,
796-
greedy: greedy,
794+
greedy,
797795
hir: Box::new(e.clone()),
798796
}),
799797
lits,
@@ -932,12 +930,10 @@ fn escape_unicode(bytes: &[u8]) -> String {
932930
if c.is_whitespace() {
933931
let escaped = if c as u32 <= 0x7F {
934932
escape_byte(c as u8)
933+
} else if c as u32 <= 0xFFFF {
934+
format!(r"\u{{{:04x}}}", c as u32)
935935
} else {
936-
if c as u32 <= 0xFFFF {
937-
format!(r"\u{{{:04x}}}", c as u32)
938-
} else {
939-
format!(r"\U{{{:08x}}}", c as u32)
940-
}
936+
format!(r"\U{{{:08x}}}", c as u32)
941937
};
942938
space_escaped.push_str(&escaped);
943939
} else {

‎regex-syntax/src/hir/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl Hir {
243243
info.set_match_empty(true);
244244
info.set_literal(false);
245245
info.set_alternation_literal(false);
246-
Hir { kind: HirKind::Empty, info: info }
246+
Hir { kind: HirKind::Empty, info }
247247
}
248248

249249
/// Creates a literal HIR expression.
@@ -268,7 +268,7 @@ impl Hir {
268268
info.set_match_empty(false);
269269
info.set_literal(true);
270270
info.set_alternation_literal(true);
271-
Hir { kind: HirKind::Literal(lit), info: info }
271+
Hir { kind: HirKind::Literal(lit), info }
272272
}
273273

274274
/// Creates a class HIR expression.
@@ -285,7 +285,7 @@ impl Hir {
285285
info.set_match_empty(false);
286286
info.set_literal(false);
287287
info.set_alternation_literal(false);
288-
Hir { kind: HirKind::Class(class), info: info }
288+
Hir { kind: HirKind::Class(class), info }
289289
}
290290

291291
/// Creates an anchor assertion HIR expression.
@@ -318,7 +318,7 @@ impl Hir {
318318
if let Anchor::EndLine = anchor {
319319
info.set_line_anchored_end(true);
320320
}
321-
Hir { kind: HirKind::Anchor(anchor), info: info }
321+
Hir { kind: HirKind::Anchor(anchor), info }
322322
}
323323

324324
/// Creates a word boundary assertion HIR expression.
@@ -341,7 +341,7 @@ impl Hir {
341341
if let WordBoundary::AsciiNegate = word_boundary {
342342
info.set_always_utf8(false);
343343
}
344-
Hir { kind: HirKind::WordBoundary(word_boundary), info: info }
344+
Hir { kind: HirKind::WordBoundary(word_boundary), info }
345345
}
346346

347347
/// Creates a repetition HIR expression.
@@ -368,7 +368,7 @@ impl Hir {
368368
info.set_match_empty(rep.is_match_empty() || rep.hir.is_match_empty());
369369
info.set_literal(false);
370370
info.set_alternation_literal(false);
371-
Hir { kind: HirKind::Repetition(rep), info: info }
371+
Hir { kind: HirKind::Repetition(rep), info }
372372
}
373373

374374
/// Creates a group HIR expression.
@@ -385,7 +385,7 @@ impl Hir {
385385
info.set_match_empty(group.hir.is_match_empty());
386386
info.set_literal(false);
387387
info.set_alternation_literal(false);
388-
Hir { kind: HirKind::Group(group), info: info }
388+
Hir { kind: HirKind::Group(group), info }
389389
}
390390

391391
/// Returns the concatenation of the given expressions.
@@ -476,7 +476,7 @@ impl Hir {
476476
})
477477
.any(|e| e.is_line_anchored_end()),
478478
);
479-
Hir { kind: HirKind::Concat(exprs), info: info }
479+
Hir { kind: HirKind::Concat(exprs), info }
480480
}
481481
}
482482
}
@@ -538,7 +538,7 @@ impl Hir {
538538
let x = info.is_alternation_literal() && e.is_literal();
539539
info.set_alternation_literal(x);
540540
}
541-
Hir { kind: HirKind::Alternation(exprs), info: info }
541+
Hir { kind: HirKind::Alternation(exprs), info }
542542
}
543543
}
544544
}

‎regex-syntax/src/hir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Printer {
6565
/// here are a `fmt::Formatter` (which is available in `fmt::Display`
6666
/// implementations) or a `&mut String`.
6767
pub fn print<W: fmt::Write>(&mut self, hir: &Hir, wtr: W) -> fmt::Result {
68-
visitor::visit(hir, Writer { printer: self, wtr: wtr })
68+
visitor::visit(hir, Writer { printer: self, wtr })
6969
}
7070
}
7171

‎regex-syntax/src/hir/translate.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ struct TranslatorI<'t, 'p> {
595595
impl<'t, 'p> TranslatorI<'t, 'p> {
596596
/// Build a new internal translator.
597597
fn new(trans: &'t Translator, pattern: &'p str) -> TranslatorI<'t, 'p> {
598-
TranslatorI { trans: trans, pattern: pattern }
598+
TranslatorI { trans, pattern }
599599
}
600600

601601
/// Return a reference to the underlying translator.
@@ -615,7 +615,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
615615

616616
/// Create a new error with the given span and error type.
617617
fn error(&self, span: Span, kind: ErrorKind) -> Error {
618-
Error { kind: kind, pattern: self.pattern.to_string(), span: span }
618+
Error { kind, pattern: self.pattern.to_string(), span }
619619
}
620620

621621
/// Return a copy of the active flags.
@@ -785,7 +785,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
785785
}
786786
ast::GroupKind::NonCapturing(_) => hir::GroupKind::NonCapturing,
787787
};
788-
Hir::group(hir::Group { kind: kind, hir: Box::new(expr) })
788+
Hir::group(hir::Group { kind, hir: Box::new(expr) })
789789
}
790790

791791
fn hir_repetition(&self, rep: &ast::Repetition, expr: Hir) -> Hir {
@@ -808,11 +808,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
808808
};
809809
let greedy =
810810
if self.flags().swap_greed() { !rep.greedy } else { rep.greedy };
811-
Hir::repetition(hir::Repetition {
812-
kind: kind,
813-
greedy: greedy,
814-
hir: Box::new(expr),
815-
})
811+
Hir::repetition(hir::Repetition { kind, greedy, hir: Box::new(expr) })
816812
}
817813

818814
fn hir_unicode_class(
@@ -905,7 +901,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
905901
result: unicode::Result<hir::ClassUnicode>,
906902
) -> Result<hir::ClassUnicode> {
907903
result.map_err(|err| {
908-
let sp = span.clone();
904+
let sp = *span;
909905
match err {
910906
unicode::Error::PropertyNotFound => {
911907
self.error(sp, ErrorKind::UnicodePropertyNotFound)
@@ -1218,31 +1214,31 @@ mod tests {
12181214
fn hir_quest(greedy: bool, expr: Hir) -> Hir {
12191215
Hir::repetition(hir::Repetition {
12201216
kind: hir::RepetitionKind::ZeroOrOne,
1221-
greedy: greedy,
1217+
greedy,
12221218
hir: Box::new(expr),
12231219
})
12241220
}
12251221

12261222
fn hir_star(greedy: bool, expr: Hir) -> Hir {
12271223
Hir::repetition(hir::Repetition {
12281224
kind: hir::RepetitionKind::ZeroOrMore,
1229-
greedy: greedy,
1225+
greedy,
12301226
hir: Box::new(expr),
12311227
})
12321228
}
12331229

12341230
fn hir_plus(greedy: bool, expr: Hir) -> Hir {
12351231
Hir::repetition(hir::Repetition {
12361232
kind: hir::RepetitionKind::OneOrMore,
1237-
greedy: greedy,
1233+
greedy,
12381234
hir: Box::new(expr),
12391235
})
12401236
}
12411237

12421238
fn hir_range(greedy: bool, range: hir::RepetitionRange, expr: Hir) -> Hir {
12431239
Hir::repetition(hir::Repetition {
12441240
kind: hir::RepetitionKind::Range(range),
1245-
greedy: greedy,
1241+
greedy,
12461242
hir: Box::new(expr),
12471243
})
12481244
}

‎regex-syntax/src/unicode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn simple_fold(
9999

100100
Ok(CASE_FOLDING_SIMPLE
101101
.binary_search_by_key(&c, |&(c1, _)| c1)
102-
.map(|i| CASE_FOLDING_SIMPLE[i].1.iter().map(|&c| c))
102+
.map(|i| CASE_FOLDING_SIMPLE[i].1.iter().copied())
103103
.map_err(|i| {
104104
if i >= CASE_FOLDING_SIMPLE.len() {
105105
None
@@ -580,7 +580,7 @@ fn ages(canonical_age: &str) -> Result<impl Iterator<Item = Range>> {
580580
fn imp(canonical_age: &str) -> Result<impl Iterator<Item = Range>> {
581581
use crate::unicode_tables::age;
582582

583-
const AGES: &'static [(&'static str, Range)] = &[
583+
const AGES: &[(&str, Range)] = &[
584584
("V1_1", age::V1_1),
585585
("V2_0", age::V2_0),
586586
("V2_1", age::V2_1),
@@ -610,7 +610,7 @@ fn ages(canonical_age: &str) -> Result<impl Iterator<Item = Range>> {
610610
let pos = AGES.iter().position(|&(age, _)| canonical_age == age);
611611
match pos {
612612
None => Err(Error::PropertyValueNotFound),
613-
Some(i) => Ok(AGES[..i + 1].iter().map(|&(_, classes)| classes)),
613+
Some(i) => Ok(AGES[..=i].iter().map(|&(_, classes)| classes)),
614614
}
615615
}
616616

‎regex-syntax/src/unicode_tables/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::redundant_static_lifetimes)]
2+
13
#[cfg(feature = "unicode-age")]
24
pub mod age;
35

‎regex-syntax/src/utf8.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a> IntoIterator for &'a Utf8Sequence {
198198
type Item = &'a Utf8Range;
199199

200200
fn into_iter(self) -> Self::IntoIter {
201-
self.as_slice().into_iter()
201+
self.as_slice().iter()
202202
}
203203
}
204204

@@ -448,7 +448,7 @@ fn max_scalar_value(nbytes: usize) -> u32 {
448448
1 => 0x007F,
449449
2 => 0x07FF,
450450
3 => 0xFFFF,
451-
4 => 0x10FFFF,
451+
4 => 0x0010_FFFF,
452452
_ => unreachable!("invalid UTF-8 byte sequence size"),
453453
}
454454
}
@@ -492,7 +492,7 @@ mod tests {
492492
fn single_codepoint_one_sequence() {
493493
// Tests that every range of scalar values that contains a single
494494
// scalar value is recognized by one sequence of byte ranges.
495-
for i in 0x0..(0x10FFFF + 1) {
495+
for i in 0x0..=0x0010_FFFF {
496496
let c = match char::from_u32(i) {
497497
None => continue,
498498
Some(c) => c,

0 commit comments

Comments
 (0)
Please sign in to comment.