Skip to content

Commit

Permalink
apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Jan 21, 2025
1 parent 5e9d985 commit e00297d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions ast/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 20 additions & 20 deletions literal/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl UnicodeEscape<'_> {
}
}

impl<'a> Escape for UnicodeEscape<'a> {
impl Escape for UnicodeEscape<'_> {
fn source_len(&self) -> usize {
self.source.len()
}
Expand All @@ -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,
Expand Down Expand Up @@ -391,7 +373,7 @@ impl AsciiEscape<'_> {
}
}

impl<'a> Escape for AsciiEscape<'a> {
impl Escape for AsciiEscape<'_> {
fn source_len(&self) -> usize {
self.source.len()
}
Expand Down Expand Up @@ -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"));
}
}
4 changes: 2 additions & 2 deletions literal/src/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ fn trim_slice<T>(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()
Expand Down
4 changes: 2 additions & 2 deletions parser/src/soft_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e00297d

Please sign in to comment.