Skip to content

Commit cc26afc

Browse files
authored
Fix a number of Clippy warnings (#170)
1 parent 217ae12 commit cc26afc

File tree

5 files changed

+38
-46
lines changed

5 files changed

+38
-46
lines changed

logos-derive/src/generator/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a> Generator<'a> {
107107

108108
if !self.gotos.contains_key(&key) {
109109
let meta = &self.meta[id];
110-
let enters_loop = meta.loop_entry_from.len() > 0;
110+
let enters_loop = !meta.loop_entry_from.is_empty();
111111

112112

113113
let bump = if enters_loop || !ctx.can_backtrack() {

logos-derive/src/graph/range.rs

+20-18
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ impl Iterator for Range {
4343
type Item = u8;
4444

4545
fn next(&mut self) -> Option<u8> {
46-
if self.start < self.end {
47-
let res = self.start;
48-
self.start += 1;
49-
50-
Some(res)
51-
} else if self.start == self.end {
52-
let res = self.start;
53-
54-
// Necessary so that range 0xFF-0xFF doesn't loop forever
55-
self.start = 0xFF;
56-
self.end = 0x00;
57-
58-
Some(res)
59-
} else {
60-
None
46+
match self.start.cmp(&self.end) {
47+
std::cmp::Ordering::Less => {
48+
let res = self.start;
49+
self.start += 1;
50+
51+
Some(res)
52+
}
53+
std::cmp::Ordering::Equal => {
54+
let res = self.start;
55+
56+
// Necessary so that range 0xFF-0xFF doesn't loop forever
57+
self.start = 0xFF;
58+
self.end = 0x00;
59+
60+
Some(res)
61+
}
62+
std::cmp::Ordering::Greater => None,
6163
}
6264
}
6365
}
@@ -109,15 +111,15 @@ mod tests {
109111
#[test]
110112
fn range_iter_one() {
111113
let byte = Range::from(b'!');
112-
let collected = byte.into_iter().take(1000).collect::<Vec<_>>();
114+
let collected = byte.take(1000).collect::<Vec<_>>();
113115

114116
assert_eq!(b"!", &collected[..]);
115117
}
116118

117119
#[test]
118120
fn range_iter_few() {
119121
let byte = Range { start: b'a', end: b'd' };
120-
let collected = byte.into_iter().take(1000).collect::<Vec<_>>();
122+
let collected = byte.take(1000).collect::<Vec<_>>();
121123

122124
assert_eq!(b"abcd", &collected[..]);
123125
}
@@ -126,7 +128,7 @@ mod tests {
126128
fn range_iter_bunds() {
127129
let byte = Range::from(0xFA..=0xFF);
128130

129-
let collected = byte.into_iter().take(1000).collect::<Vec<_>>();
131+
let collected = byte.take(1000).collect::<Vec<_>>();
130132

131133
assert_eq!(b"\xFA\xFB\xFC\xFD\xFE\xFF", &collected[..]);
132134
}

logos-derive/src/mir.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl TryFrom<Hir> for Mir {
100100
},
101101
HirKind::Repetition(repetition) => {
102102
if !repetition.greedy {
103-
Err("#[regex]: non-greedy parsing is currently unsupported.")?;
103+
return Err("#[regex]: non-greedy parsing is currently unsupported.".into());
104104
}
105105

106106
let kind = repetition.kind;
@@ -120,18 +120,18 @@ impl TryFrom<Hir> for Mir {
120120
]))
121121
},
122122
RepetitionKind::Range(..) => {
123-
Err("#[regex]: {n,m} repetition range is currently unsupported.")?
123+
Err("#[regex]: {n,m} repetition range is currently unsupported.".into())
124124
},
125125
}
126126
},
127127
HirKind::Group(group) => {
128128
Mir::try_from(*group.hir)
129129
},
130130
HirKind::WordBoundary(_) => {
131-
Err("#[regex]: word boundaries are currently unsupported.")?
131+
Err("#[regex]: word boundaries are currently unsupported.".into())
132132
},
133133
HirKind::Anchor(_) => {
134-
Err("#[regex]: anchors in #[regex] are currently unsupported.")?
134+
Err("#[regex]: anchors in #[regex] are currently unsupported.".into())
135135
},
136136
}
137137
}

logos-derive/src/parser/type_params.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,8 @@ pub fn replace_lifetime(ty: &mut Type) {
121121
})
122122
.flat_map(|ab| ab.args.iter_mut())
123123
.for_each(|arg| {
124-
match arg {
125-
GenericArgument::Lifetime(lt) => {
126-
*lt = Lifetime::new("'s", lt.span());
127-
},
128-
_ => (),
124+
if let GenericArgument::Lifetime(lt) = arg {
125+
*lt = Lifetime::new("'s", lt.span());
129126
}
130127
});
131128
},

logos/src/source.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ pub trait Source {
2828
/// ```rust
2929
/// use logos::Source;
3030
///
31-
/// fn main() {
32-
/// let foo = "foo";
31+
/// let foo = "foo";
3332
///
34-
/// assert_eq!(foo.read(0), Some(b"foo")); // Option<&[u8; 3]>
35-
/// assert_eq!(foo.read(0), Some(b"fo")); // Option<&[u8; 2]>
36-
/// assert_eq!(foo.read(2), Some(b'o')); // Option<u8>
37-
/// assert_eq!(foo.read::<&[u8; 4]>(0), None); // Out of bounds
38-
/// assert_eq!(foo.read::<&[u8; 2]>(2), None); // Out of bounds
39-
/// }
33+
/// assert_eq!(foo.read(0), Some(b"foo")); // Option<&[u8; 3]>
34+
/// assert_eq!(foo.read(0), Some(b"fo")); // Option<&[u8; 2]>
35+
/// assert_eq!(foo.read(2), Some(b'o')); // Option<u8>
36+
/// assert_eq!(foo.read::<&[u8; 4]>(0), None); // Out of bounds
37+
/// assert_eq!(foo.read::<&[u8; 2]>(2), None); // Out of bounds
4038
/// ```
4139
fn read<'a, Chunk>(&'a self, offset: usize) -> Option<Chunk>
4240
where
@@ -53,11 +51,8 @@ pub trait Source {
5351
/// ```rust
5452
/// use logos::Source;
5553
///
56-
/// fn main() {
57-
/// let foo = "It was the year when they finally immanentized the Eschaton.";
58-
///
59-
/// assert_eq!(<str as Source>::slice(&foo, 51..59), Some("Eschaton"));
60-
/// }
54+
/// let foo = "It was the year when they finally immanentized the Eschaton.";
55+
/// assert_eq!(<str as Source>::slice(&foo, 51..59), Some("Eschaton"));
6156
/// ```
6257
fn slice(&self, range: Range<usize>) -> Option<&Self::Slice>;
6358

@@ -69,12 +64,10 @@ pub trait Source {
6964
/// ```rust
7065
/// use logos::Source;
7166
///
72-
/// fn main() {
73-
/// let foo = "It was the year when they finally immanentized the Eschaton.";
67+
/// let foo = "It was the year when they finally immanentized the Eschaton.";
7468
///
75-
/// unsafe {
76-
/// assert_eq!(<str as Source>::slice_unchecked(&foo, 51..59), "Eschaton");
77-
/// }
69+
/// unsafe {
70+
/// assert_eq!(<str as Source>::slice_unchecked(&foo, 51..59), "Eschaton");
7871
/// }
7972
/// ```
8073
unsafe fn slice_unchecked(&self, range: Range<usize>) -> &Self::Slice;

0 commit comments

Comments
 (0)