From c52169f535f89c0300ec06e13ddcaa7e0f459a0b Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Mon, 1 Jun 2026 21:17:23 +0200 Subject: clippy --- src/parse/mod.rs | 23 ++++++++++------------- src/parse/regex/byte_range.rs | 10 +++++----- src/parse/regex/dfa.rs | 3 ++- src/parse/regex/enfa.rs | 1 + src/parse/span.rs | 16 +++++++--------- 5 files changed, 25 insertions(+), 28 deletions(-) (limited to 'src/parse') diff --git a/src/parse/mod.rs b/src/parse/mod.rs index e7a2d1d..b3855a8 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -1382,11 +1382,11 @@ impl HighlightKind { /// all highlight kind variants *except* None pub fn variants() -> impl Iterator { let a = Keyword::VARIANTS - .into_iter() + .iter() .cloned() .map(HighlightKind::Keyword); let b = OtherHighlights::VARIANTS - .into_iter() + .iter() .cloned() .map(HighlightKind::Other); a.chain(b) @@ -1405,7 +1405,7 @@ impl HighlightKind { match ident { b"keywords" => { return Keyword::VARIANTS - .into_iter() + .iter() .cloned() .map(HighlightKind::Keyword) .collect(); @@ -1421,15 +1421,14 @@ impl HighlightKind { } Self::variants() - .into_iter() .filter(|x| x.identifier() == ident) .collect() } pub fn all_identifiers() -> Vec { - let kw = Keyword::VARIANTS.into_iter().map(Keyword::identifier); + let kw = Keyword::VARIANTS.iter().map(Keyword::identifier); let ot = OtherHighlights::VARIANTS - .into_iter() + .iter() .map(OtherHighlights::identifier); let groups = [&b"keywords"[..], b"braces", b"all", b"everything"]; kw.chain(ot) @@ -1650,13 +1649,11 @@ impl<'a> Cursor<'a> { self.buf = &self.buf[bytes.len() + 1..]; self.spaces(); Ok(()) + } else if self.is_completion() && self.buf.len() == bytes.len() { + self.buf = &self.buf[bytes.len()..]; + Ok(()) } else { - if self.is_completion() && self.buf.len() == bytes.len() { - self.buf = &self.buf[bytes.len()..]; - Ok(()) - } else { - Err(ParseError::ExpectedKeyword(kw)) - } + Err(ParseError::ExpectedKeyword(kw)) } } else { self.buf = &self.buf[bytes.len()..]; @@ -1931,7 +1928,7 @@ impl Parse for Case { let mut branches = Vec::new(); loop { b.spaces(); - if let Ok(_) = b.consume_keyword(Keyword::CloseBrace) { + if b.consume_keyword(Keyword::CloseBrace).is_ok() { break; } branches.push(CaseBranch::parse(b)?); diff --git a/src/parse/regex/byte_range.rs b/src/parse/regex/byte_range.rs index 1ca6d8f..86b2c2b 100644 --- a/src/parse/regex/byte_range.rs +++ b/src/parse/regex/byte_range.rs @@ -49,11 +49,11 @@ impl ByteRange { let mut out = Vec::new(); for (mut loc, delta) in edges { - if let Some(last) = last { - if last <= loc { - out.push(ByteRange::new_range(last, loc)); - loc = loc + 1; - } + if let Some(last) = last + && last <= loc + { + out.push(ByteRange::new_range(last, loc)); + loc += 1; } depth += delta; diff --git a/src/parse/regex/dfa.rs b/src/parse/regex/dfa.rs index aba6238..7e5be7b 100644 --- a/src/parse/regex/dfa.rs +++ b/src/parse/regex/dfa.rs @@ -14,6 +14,7 @@ pub struct State { accept: bool, } +#[allow(clippy::upper_case_acronyms)] pub struct DFA { start: StateId, states: Vec, @@ -94,7 +95,7 @@ impl From for DFA { .collect(); for ms in multi_states.iter() { - let i: usize = multi_to_dfa[&ms]; + let i: usize = multi_to_dfa[ms]; states[i].accept = ms.accept(); for t in ms.possible_transitions() { let k = multi_to_dfa[&ms.transition(t)]; diff --git a/src/parse/regex/enfa.rs b/src/parse/regex/enfa.rs index 71998c9..3809595 100644 --- a/src/parse/regex/enfa.rs +++ b/src/parse/regex/enfa.rs @@ -8,6 +8,7 @@ use super::byte_range::ByteRange; /// NFA with epsilon transitions #[derive(Clone)] +#[allow(clippy::upper_case_acronyms)] pub struct ENFA { pub states: Vec, } diff --git a/src/parse/span.rs b/src/parse/span.rs index 340a078..671c10d 100644 --- a/src/parse/span.rs +++ b/src/parse/span.rs @@ -22,6 +22,12 @@ impl FileId { } } +impl Default for FileId { + fn default() -> Self { + Self::new() + } +} + #[derive(Copy, Clone)] pub struct SpanFrom { pub file: FileId, @@ -52,15 +58,7 @@ pub struct Span { /// manual implementation of PartialOrd to ensure shorter Spans are first impl PartialOrd for Span { fn partial_cmp(&self, other: &Self) -> Option { - match self.file.partial_cmp(&other.file) { - Some(core::cmp::Ordering::Equal) => {} - ord => return ord, - } - match self.start.partial_cmp(&other.start) { - Some(core::cmp::Ordering::Equal) => {} - ord => return ord, - } - other.end.partial_cmp(&self.end) + Some(self.cmp(other)) } } -- cgit v1.2.3