Skip to content

apply clippy suggestions #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading