mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-07 13:15:21 +00:00
apply clippy suggestions
This commit is contained in:
parent
5e9d9853e7
commit
e00297d1c7
4 changed files with 26 additions and 26 deletions
|
@ -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 {
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue