aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/algo
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/algo')
-rw-r--r--crates/ra_syntax/src/algo/visit.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs
index c021f464c..38f21594c 100644
--- a/crates/ra_syntax/src/algo/visit.rs
+++ b/crates/ra_syntax/src/algo/visit.rs
@@ -1,4 +1,4 @@
1use crate::{AstNode, SyntaxNodeRef}; 1use crate::{AstNode, SyntaxNode};
2 2
3use std::marker::PhantomData; 3use std::marker::PhantomData;
4 4
@@ -15,11 +15,11 @@ pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C>
15 15
16pub trait Visitor<'a>: Sized { 16pub trait Visitor<'a>: Sized {
17 type Output; 17 type Output;
18 fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output>; 18 fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output>;
19 fn visit<N, F>(self, f: F) -> Vis<Self, N, F> 19 fn visit<N, F>(self, f: F) -> Vis<Self, N, F>
20 where 20 where
21 N: AstNode<'a>, 21 N: AstNode + 'a,
22 F: FnOnce(N) -> Self::Output, 22 F: FnOnce(&'a N) -> Self::Output,
23 { 23 {
24 Vis { 24 Vis {
25 inner: self, 25 inner: self,
@@ -32,11 +32,11 @@ pub trait Visitor<'a>: Sized {
32pub trait VisitorCtx<'a>: Sized { 32pub trait VisitorCtx<'a>: Sized {
33 type Output; 33 type Output;
34 type Ctx; 34 type Ctx;
35 fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx>; 35 fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx>;
36 fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F> 36 fn visit<N, F>(self, f: F) -> VisCtx<Self, N, F>
37 where 37 where
38 N: AstNode<'a>, 38 N: AstNode + 'a,
39 F: FnOnce(N, Self::Ctx) -> Self::Output, 39 F: FnOnce(&'a N, Self::Ctx) -> Self::Output,
40 { 40 {
41 VisCtx { 41 VisCtx {
42 inner: self, 42 inner: self,
@@ -54,7 +54,7 @@ struct EmptyVisitor<T> {
54impl<'a, T> Visitor<'a> for EmptyVisitor<T> { 54impl<'a, T> Visitor<'a> for EmptyVisitor<T> {
55 type Output = T; 55 type Output = T;
56 56
57 fn accept(self, _node: SyntaxNodeRef<'a>) -> Option<T> { 57 fn accept(self, _node: &'a SyntaxNode) -> Option<T> {
58 None 58 None
59 } 59 }
60} 60}
@@ -69,7 +69,7 @@ impl<'a, T, C> VisitorCtx<'a> for EmptyVisitorCtx<T, C> {
69 type Output = T; 69 type Output = T;
70 type Ctx = C; 70 type Ctx = C;
71 71
72 fn accept(self, _node: SyntaxNodeRef<'a>) -> Result<T, C> { 72 fn accept(self, _node: &'a SyntaxNode) -> Result<T, C> {
73 Err(self.ctx) 73 Err(self.ctx)
74 } 74 }
75} 75}
@@ -84,12 +84,12 @@ pub struct Vis<V, N, F> {
84impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F> 84impl<'a, V, N, F> Visitor<'a> for Vis<V, N, F>
85where 85where
86 V: Visitor<'a>, 86 V: Visitor<'a>,
87 N: AstNode<'a>, 87 N: AstNode + 'a,
88 F: FnOnce(N) -> <V as Visitor<'a>>::Output, 88 F: FnOnce(&'a N) -> <V as Visitor<'a>>::Output,
89{ 89{
90 type Output = <V as Visitor<'a>>::Output; 90 type Output = <V as Visitor<'a>>::Output;
91 91
92 fn accept(self, node: SyntaxNodeRef<'a>) -> Option<Self::Output> { 92 fn accept(self, node: &'a SyntaxNode) -> Option<Self::Output> {
93 let Vis { inner, f, .. } = self; 93 let Vis { inner, f, .. } = self;
94 inner.accept(node).or_else(|| N::cast(node).map(f)) 94 inner.accept(node).or_else(|| N::cast(node).map(f))
95 } 95 }
@@ -105,13 +105,13 @@ pub struct VisCtx<V, N, F> {
105impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F> 105impl<'a, V, N, F> VisitorCtx<'a> for VisCtx<V, N, F>
106where 106where
107 V: VisitorCtx<'a>, 107 V: VisitorCtx<'a>,
108 N: AstNode<'a>, 108 N: AstNode + 'a,
109 F: FnOnce(N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output, 109 F: FnOnce(&'a N, <V as VisitorCtx<'a>>::Ctx) -> <V as VisitorCtx<'a>>::Output,
110{ 110{
111 type Output = <V as VisitorCtx<'a>>::Output; 111 type Output = <V as VisitorCtx<'a>>::Output;
112 type Ctx = <V as VisitorCtx<'a>>::Ctx; 112 type Ctx = <V as VisitorCtx<'a>>::Ctx;
113 113
114 fn accept(self, node: SyntaxNodeRef<'a>) -> Result<Self::Output, Self::Ctx> { 114 fn accept(self, node: &'a SyntaxNode) -> Result<Self::Output, Self::Ctx> {
115 let VisCtx { inner, f, .. } = self; 115 let VisCtx { inner, f, .. } = self;
116 inner.accept(node).or_else(|ctx| match N::cast(node) { 116 inner.accept(node).or_else(|ctx| match N::cast(node) {
117 None => Err(ctx), 117 None => Err(ctx),