From 4161bad54f690e77f53ca1f0f4426161e60fa4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Barv=C3=AD=C5=99?= Date: Fri, 31 Mar 2023 17:13:31 +0200 Subject: [PATCH] FIX lint clippy::len_without_is_empty (#451) --- src/eval/array.rs | 5 +++++ src/eval/str.rs | 5 +++++ src/syntax/node.rs | 5 +++++ src/syntax/parser.rs | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/eval/array.rs b/src/eval/array.rs index 3006c91f4..8dcbd5a9b 100644 --- a/src/eval/array.rs +++ b/src/eval/array.rs @@ -41,6 +41,11 @@ impl Array { Self(vec) } + /// Return `true` if the length is 0. + pub fn is_empty(&self) -> bool { + self.0.len() == 0 + } + /// The length of the array. pub fn len(&self) -> i64 { self.0.len() as i64 diff --git a/src/eval/str.rs b/src/eval/str.rs index d867e19c2..22b5498b4 100644 --- a/src/eval/str.rs +++ b/src/eval/str.rs @@ -34,6 +34,11 @@ impl Str { Self(EcoString::new()) } + /// Return `true` if the length is 0. + pub fn is_empty(&self) -> bool { + self.0.len() == 0 + } + /// The length of the string in bytes. pub fn len(&self) -> i64 { self.0.len() as i64 diff --git a/src/syntax/node.rs b/src/syntax/node.rs index afbebe97f..3c9bc049b 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -53,6 +53,11 @@ impl SyntaxNode { } } + /// Return `true` if the length is 0. + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + /// The byte length of the node in the source text. pub fn len(&self) -> usize { match &self.0 { diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 46150ff2b..e95da4af7 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -1324,7 +1324,7 @@ impl<'s> Parser<'s> { while self .nodes .last() - .map_or(false, |child| child.kind() == SyntaxKind::Error && child.len() == 0) + .map_or(false, |child| child.kind() == SyntaxKind::Error && child.is_empty()) { self.nodes.pop(); }