diff --git a/ast/src/builtin.rs b/ast/src/builtin.rs index 1a64efb8..47dcc7b1 100644 --- a/ast/src/builtin.rs +++ b/ast/src/builtin.rs @@ -128,10 +128,10 @@ pub enum Constant { impl Constant { pub fn is_true(self) -> bool { - self.bool().map_or(false, |b| b) + self.bool().is_some_and(|b| b) } pub fn is_false(self) -> bool { - self.bool().map_or(false, |b| !b) + self.bool().is_some_and(|b| !b) } pub fn complex(self) -> Option<(f64, f64)> { match self { diff --git a/literal/src/escape.rs b/literal/src/escape.rs index ee4fae58..ba8e3ecf 100644 --- a/literal/src/escape.rs +++ b/literal/src/escape.rs @@ -232,7 +232,7 @@ impl UnicodeEscape<'_> { } } -impl<'a> Escape for UnicodeEscape<'a> { +impl Escape for UnicodeEscape<'_> { fn source_len(&self) -> usize { self.source.len() } @@ -254,24 +254,6 @@ impl<'a> Escape for UnicodeEscape<'a> { } } -#[cfg(test)] -mod unicode_escape_tests { - use super::*; - - #[test] - fn changed() { - fn test(s: &str) -> bool { - UnicodeEscape::new_repr(s).changed() - } - assert!(!test("hello")); - assert!(!test("'hello'")); - assert!(!test("\"hello\"")); - - assert!(test("'\"hello")); - assert!(test("hello\n")); - } -} - pub struct AsciiEscape<'a> { source: &'a [u8], layout: EscapeLayout, @@ -391,7 +373,7 @@ impl AsciiEscape<'_> { } } -impl<'a> Escape for AsciiEscape<'a> { +impl Escape for AsciiEscape<'_> { fn source_len(&self) -> usize { self.source.len() } @@ -439,3 +421,21 @@ impl std::fmt::Display for BytesRepr<'_, '_> { self.write(formatter) } } + +#[cfg(test)] +mod unicode_escape_tests { + use super::*; + + #[test] + fn changed() { + fn test(s: &str) -> bool { + UnicodeEscape::new_repr(s).changed() + } + assert!(!test("hello")); + assert!(!test("'hello'")); + assert!(!test("\"hello\"")); + + assert!(test("'\"hello")); + assert!(test("hello\n")); + } +} diff --git a/literal/src/float.rs b/literal/src/float.rs index c8224fa5..0f10a6a1 100644 --- a/literal/src/float.rs +++ b/literal/src/float.rs @@ -42,10 +42,10 @@ fn trim_slice(v: &[T], mut trim: impl FnMut(&T) -> bool) -> &[T] { // it.take_while_ref(&mut trim).for_each(drop); // hmm.. `&mut slice::Iter<_>` is not `Clone` // it.by_ref().rev().take_while_ref(&mut trim).for_each(drop); - while it.clone().next().map_or(false, &mut trim) { + while it.clone().next().is_some_and(&mut trim) { it.next(); } - while it.clone().next_back().map_or(false, &mut trim) { + while it.clone().next_back().is_some_and(&mut trim) { it.next_back(); } it.as_slice() diff --git a/parser/src/soft_keywords.rs b/parser/src/soft_keywords.rs index 9abcd395..3f8c24c8 100644 --- a/parser/src/soft_keywords.rs +++ b/parser/src/soft_keywords.rs @@ -132,8 +132,8 @@ where } } - self.start_of_line = next.as_ref().map_or(false, |lex_result| { - lex_result.as_ref().map_or(false, |(tok, _)| { + self.start_of_line = next.as_ref().is_some_and(|lex_result| { + lex_result.as_ref().is_ok_and(|(tok, _)| { #[cfg(feature = "full-lexer")] if matches!(tok, Tok::NonLogicalNewline | Tok::Comment { .. }) { return self.start_of_line;