1
Fork 0
mirror of https://github.com/RGBCube/cstree synced 2025-08-02 12:07:47 +00:00

treewide: specify lifetimes correctly (#77)

don't overrestrict lifetimes, prefer `use<...>` to prevent `impl Trait` from capturing too much
This commit is contained in:
RGBCube 2025-07-29 16:54:24 +00:00 committed by GitHub
parent a8ebf29808
commit d006fcbcfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 4 deletions

View file

@ -292,7 +292,7 @@ impl<'a, S: Syntax, D> SyntaxElementRef<'a, S, D> {
/// Returns an iterator along the chain of parents of this node. /// Returns an iterator along the chain of parents of this node.
#[inline] #[inline]
pub fn ancestors(&self) -> impl Iterator<Item = &'a SyntaxNode<S, D>> { pub fn ancestors(&self) -> impl Iterator<Item = &'a SyntaxNode<S, D>> + use<'a, S, D> {
match self { match self {
NodeOrToken::Node(it) => it.ancestors(), NodeOrToken::Node(it) => it.ancestors(),
NodeOrToken::Token(it) => it.parent().ancestors(), NodeOrToken::Token(it) => it.parent().ancestors(),

View file

@ -713,7 +713,7 @@ impl<'a, S: Syntax, D> ResolvedElementRef<'a, S, D> {
/// Returns an iterator along the chain of parents of this node. /// Returns an iterator along the chain of parents of this node.
#[inline] #[inline]
pub fn ancestors(&self) -> impl Iterator<Item = &'a ResolvedNode<S, D>> { pub fn ancestors(&self) -> impl Iterator<Item = &'a ResolvedNode<S, D>> + use<'a, S, D> {
match self { match self {
NodeOrToken::Node(it) => it.ancestors(), NodeOrToken::Node(it) => it.ancestors(),
NodeOrToken::Token(it) => it.parent().ancestors(), NodeOrToken::Token(it) => it.parent().ancestors(),

View file

@ -150,7 +150,7 @@ impl<'n, 'i, I: Resolver<TokenKey> + ?Sized, S: Syntax, D> SyntaxText<'n, 'i, I,
/// See also [`fold_chunks`](SyntaxText::fold_chunks) for folds that always succeed. /// See also [`fold_chunks`](SyntaxText::fold_chunks) for folds that always succeed.
pub fn try_fold_chunks<T, F, E>(&self, init: T, mut f: F) -> Result<T, E> pub fn try_fold_chunks<T, F, E>(&self, init: T, mut f: F) -> Result<T, E>
where where
F: FnMut(T, &str) -> Result<T, E>, F: FnMut(T, &'i str) -> Result<T, E>,
{ {
self.tokens_with_ranges().try_fold(init, move |acc, (token, range)| { self.tokens_with_ranges().try_fold(init, move |acc, (token, range)| {
f(acc, &token.resolve_text(self.resolver)[range]) f(acc, &token.resolve_text(self.resolver)[range])
@ -195,7 +195,7 @@ impl<'n, 'i, I: Resolver<TokenKey> + ?Sized, S: Syntax, D> SyntaxText<'n, 'i, I,
self.fold_chunks((), |(), chunk| f(chunk)) self.fold_chunks((), |(), chunk| f(chunk))
} }
fn tokens_with_ranges(&self) -> impl Iterator<Item = (&SyntaxToken<S, D>, TextRange)> { fn tokens_with_ranges(&self) -> impl Iterator<Item = (&'n SyntaxToken<S, D>, TextRange)> + use<'i, 'n, I, S, D> {
let text_range = self.range; let text_range = self.range;
self.node self.node
.descendants_with_tokens() .descendants_with_tokens()