diff --git a/src/api.rs b/src/api.rs index 69e2f07..3a83daf 100644 --- a/src/api.rs +++ b/src/api.rs @@ -133,7 +133,7 @@ impl SyntaxNode { self.raw.parent().map(Self::from) } - pub fn ancestors(&self) -> impl Iterator> { + pub fn ancestors(&self) -> impl Iterator> + use { self.raw.ancestors().map(SyntaxNode::from) } @@ -219,7 +219,7 @@ impl SyntaxNode { self.raw.last_token().map(SyntaxToken::from) } - pub fn siblings(&self, direction: Direction) -> impl Iterator> { + pub fn siblings(&self, direction: Direction) -> impl Iterator> + use { self.raw.siblings(direction).map(SyntaxNode::from) } @@ -230,11 +230,11 @@ impl SyntaxNode { self.raw.siblings_with_tokens(direction).map(SyntaxElement::from) } - pub fn descendants(&self) -> impl Iterator> { + pub fn descendants(&self) -> impl Iterator> + use { self.raw.descendants().map(SyntaxNode::from) } - pub fn descendants_with_tokens(&self) -> impl Iterator> { + pub fn descendants_with_tokens(&self) -> impl Iterator> + use { self.raw.descendants_with_tokens().map(NodeOrToken::from) } @@ -337,12 +337,12 @@ impl SyntaxToken { /// Iterator over all the ancestors of this token excluding itself. #[deprecated = "use `SyntaxToken::parent_ancestors` instead"] - pub fn ancestors(&self) -> impl Iterator> { + pub fn ancestors(&self) -> impl Iterator> + use { self.parent_ancestors() } /// Iterator over all the ancestors of this token excluding itself. - pub fn parent_ancestors(&self) -> impl Iterator> { + pub fn parent_ancestors(&self) -> impl Iterator> + use { self.raw.ancestors().map(SyntaxNode::from) } @@ -356,7 +356,7 @@ impl SyntaxToken { pub fn siblings_with_tokens( &self, direction: Direction, - ) -> impl Iterator> { + ) -> impl Iterator> + use { self.raw.siblings_with_tokens(direction).map(SyntaxElement::from) } @@ -403,7 +403,7 @@ impl SyntaxElement { } } - pub fn ancestors(&self) -> impl Iterator> { + pub fn ancestors(&self) -> impl Iterator> + use { let first = match self { NodeOrToken::Node(it) => Some(it.clone()), NodeOrToken::Token(it) => it.parent(), diff --git a/src/cursor.rs b/src/cursor.rs index 7d63948..0ea88ac 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -668,7 +668,7 @@ impl SyntaxNode { } #[inline] - pub fn ancestors(&self) -> impl Iterator { + pub fn ancestors(&self) -> impl Iterator + use<> { iter::successors(Some(self.clone()), SyntaxNode::parent) } @@ -831,7 +831,7 @@ impl SyntaxNode { } #[inline] - pub fn siblings(&self, direction: Direction) -> impl Iterator { + pub fn siblings(&self, direction: Direction) -> impl Iterator + use<> { iter::successors(Some(self.clone()), move |node| match direction { Direction::Next => node.next_sibling(), Direction::Prev => node.prev_sibling(), @@ -842,7 +842,7 @@ impl SyntaxNode { pub fn siblings_with_tokens( &self, direction: Direction, - ) -> impl Iterator { + ) -> impl Iterator + use<> { let me: SyntaxElement = self.clone().into(); iter::successors(Some(me), move |el| match direction { Direction::Next => el.next_sibling_or_token(), @@ -851,7 +851,7 @@ impl SyntaxNode { } #[inline] - pub fn descendants(&self) -> impl Iterator { + pub fn descendants(&self) -> impl Iterator + use<> { self.preorder().filter_map(|event| match event { WalkEvent::Enter(node) => Some(node), WalkEvent::Leave(_) => None, @@ -859,7 +859,7 @@ impl SyntaxNode { } #[inline] - pub fn descendants_with_tokens(&self) -> impl Iterator { + pub fn descendants_with_tokens(&self) -> impl Iterator + use<> { self.preorder_with_tokens().filter_map(|event| match event { WalkEvent::Enter(it) => Some(it), WalkEvent::Leave(_) => None, @@ -1054,7 +1054,7 @@ impl SyntaxToken { } #[inline] - pub fn ancestors(&self) -> impl Iterator { + pub fn ancestors(&self) -> impl Iterator + use<> { std::iter::successors(self.parent(), SyntaxNode::parent) } @@ -1077,7 +1077,7 @@ impl SyntaxToken { pub fn siblings_with_tokens( &self, direction: Direction, - ) -> impl Iterator { + ) -> impl Iterator + use<> { let me: SyntaxElement = self.clone().into(); iter::successors(Some(me), move |el| match direction { Direction::Next => el.next_sibling_or_token(), @@ -1156,7 +1156,7 @@ impl SyntaxElement { } #[inline] - pub fn ancestors(&self) -> impl Iterator { + pub fn ancestors(&self) -> impl Iterator + use<> { let first = match self { NodeOrToken::Node(it) => Some(it.clone()), NodeOrToken::Token(it) => it.parent(), diff --git a/src/syntax_text.rs b/src/syntax_text.rs index 981df56..7e91ba2 100644 --- a/src/syntax_text.rs +++ b/src/syntax_text.rs @@ -105,7 +105,7 @@ impl SyntaxText { } } - fn tokens_with_ranges(&self) -> impl Iterator { + fn tokens_with_ranges(&self) -> impl Iterator + use<> { let text_range = self.range; self.node.descendants_with_tokens().filter_map(|element| element.into_token()).filter_map( move |token| {