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/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, 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 { 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> { diff --git a/src/syntax_text.rs b/src/syntax_text.rs index 3ab3f6c..41b6a3f 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); @@ -59,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; @@ -97,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 {}, @@ -285,10 +285,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]) {