From 6c0bcc6a910d4d351737fb47dd06a2378ccc08a2 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:18:14 -0400 Subject: [PATCH 1/7] Remove Iterator::fold impl for Children as it is no different than the default one. --- src/green/node.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/green/node.rs b/src/green/node.rs index 0487278..348ea77 100644 --- a/src/green/node.rs +++ b/src/green/node.rs @@ -114,18 +114,6 @@ impl<'a> Iterator for Children<'a> { { self.next_back() } - - #[inline] - fn fold(mut self, init: Acc, mut f: Fold) -> Acc - where - Fold: FnMut(Acc, Self::Item) -> Acc, - { - let mut accum = init; - while let Some(x) = self.next() { - accum = f(accum, x); - } - accum - } } impl<'a> DoubleEndedIterator for Children<'a> { From ba1df7558e052fca5d5b0b2c7a3f7af939f181d6 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:19:20 -0400 Subject: [PATCH 2/7] Remove redundant lifetime annotation --- src/cursor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cursor.rs b/src/cursor.rs index db6901b..b47d2b3 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -414,7 +414,7 @@ impl SyntaxNode { /// Traverse the subtree rooted at the current node (including the current /// node) in preorder, including tokens. #[inline] - pub fn preorder_with_tokens<'a>(&'a self) -> impl Iterator> { + pub fn preorder_with_tokens(&self) -> impl Iterator> { let start: SyntaxElement = self.clone().into(); iter::successors(Some(WalkEvent::Enter(start.clone())), move |pos| { let next = match pos { From 52284531c97c1ea7d00d03223c1e3fd1c0ff84c5 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:19:53 -0400 Subject: [PATCH 3/7] Remove identity calls to Into::into --- examples/math.rs | 2 +- src/syntax_text.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/math.rs b/examples/math.rs index c51d84d..bdc474a 100644 --- a/examples/math.rs +++ b/examples/math.rs @@ -111,7 +111,7 @@ impl> Parser { } fn print(indent: usize, element: SyntaxElement) { - let kind: SyntaxKind = element.kind().into(); + let kind: SyntaxKind = element.kind(); print!("{:indent$}", "", indent = indent); match element { NodeOrToken::Node(node) => { diff --git a/src/syntax_text.rs b/src/syntax_text.rs index 3ab3f6c..2196e27 100644 --- a/src/syntax_text.rs +++ b/src/syntax_text.rs @@ -43,7 +43,6 @@ impl SyntaxText { } pub fn char_at(&self, offset: TextSize) -> Option { - let offset = offset.into(); let mut start: TextSize = 0.into(); let res = self.try_for_each_chunk(|chunk| { let end = start + TextSize::of(chunk); From 19a2c1f06cb459542bb22c6c17250d635aed8a4f Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:21:21 -0400 Subject: [PATCH 4/7] Remove use of `unwrap_or` followed by a function call clippy::or_fun_call for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call --- src/syntax_text.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/syntax_text.rs b/src/syntax_text.rs index 2196e27..9292ed4 100644 --- a/src/syntax_text.rs +++ b/src/syntax_text.rs @@ -58,7 +58,7 @@ impl SyntaxText { pub fn slice(&self, range: R) -> SyntaxText { let start = range.start().unwrap_or_default(); - let end = range.end().unwrap_or(self.len()); + let end = range.end().unwrap_or_else(|| self.len()); assert!(start <= end); let len = end - start; let start = self.range.start() + start; From 1441e73ecb378f2cb3dad76656cc225b56735560 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:24:43 -0400 Subject: [PATCH 5/7] Remove unnecessary reference of comparison operator clippy::op_ref --- src/syntax_text.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/syntax_text.rs b/src/syntax_text.rs index 9292ed4..e0bf7fc 100644 --- a/src/syntax_text.rs +++ b/src/syntax_text.rs @@ -284,10 +284,12 @@ mod tests { fn do_check(t1: &[&str], t2: &[&str]) { let t1 = build_tree(t1).text(); let t2 = build_tree(t2).text(); - let expected = t1.to_string() == t2.to_string(); + let t1_s = t1.to_string(); + let t2_s = t2.to_string(); + let expected = t1_s == t2_s; let actual = t1 == t2; assert_eq!(expected, actual, "`{}` (SyntaxText) `{}` (SyntaxText)", t1, t2); - let actual = t1 == &*t2.to_string(); + let actual = t1 == t2_s.as_str(); assert_eq!(expected, actual, "`{}` (SyntaxText) `{}` (&str)", t1, t2); } fn check(t1: &[&str], t2: &[&str]) { From be56ab8de32c7c99be4619bdd2510989cae51e8e Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:30:44 -0400 Subject: [PATCH 6/7] Allow clippy::unit_arg --- src/syntax_text.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/syntax_text.rs b/src/syntax_text.rs index e0bf7fc..41b6a3f 100644 --- a/src/syntax_text.rs +++ b/src/syntax_text.rs @@ -96,6 +96,7 @@ impl SyntaxText { pub fn for_each_chunk(&self, mut f: F) { enum Void {} + #[allow(clippy::unit_arg)] match self.try_for_each_chunk(|chunk| Ok::<(), Void>(f(chunk))) { Ok(()) => (), Err(void) => match void {}, From 3f3aa591af81e1c98a6c7e4fdc874619a98b5271 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 26 Apr 2020 17:32:24 -0400 Subject: [PATCH 7/7] Use next instead of nth in s_expr example --- examples/s_expressions.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/s_expressions.rs b/examples/s_expressions.rs index 0adabe5..a2d1eaa 100644 --- a/examples/s_expressions.rs +++ b/examples/s_expressions.rs @@ -346,12 +346,13 @@ impl List { self.0.children().filter_map(Sexp::cast) } fn eval(&self) -> Option { - let op = match self.sexps().nth(0)?.kind() { + let mut sexps = self.sexps(); + let op = match sexps.next()?.kind() { SexpKind::Atom(atom) => atom.as_op()?, _ => return None, }; - let arg1 = self.sexps().nth(1)?.eval()?; - let arg2 = self.sexps().nth(2)?.eval()?; + let arg1 = sexps.next()?.eval()?; + let arg2 = sexps.next()?.eval()?; let res = match op { Op::Add => arg1 + arg2, Op::Sub => arg1 - arg2,