From 61f3a438d3a729a6be941bca1ff4c6a97a33f221 Mon Sep 17 00:00:00 2001 From: "Jeremy A. Kolb" Date: Mon, 15 Oct 2018 17:44:23 -0400 Subject: Cargo Format Run `cargo fmt` and ignore generated files --- crates/ra_syntax/src/algo/visit.rs | 63 ++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 26 deletions(-) (limited to 'crates/ra_syntax/src/algo/visit.rs') diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs index 1ae988a87..c021f464c 100644 --- a/crates/ra_syntax/src/algo/visit.rs +++ b/crates/ra_syntax/src/algo/visit.rs @@ -1,23 +1,31 @@ -use std::marker::PhantomData; -use crate::{SyntaxNodeRef, AstNode}; +use crate::{AstNode, SyntaxNodeRef}; +use std::marker::PhantomData; -pub fn visitor<'a, T>() -> impl Visitor<'a, Output=T> { +pub fn visitor<'a, T>() -> impl Visitor<'a, Output = T> { EmptyVisitor { ph: PhantomData } } -pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output=T, Ctx=C> { - EmptyVisitorCtx { ph: PhantomData, ctx } +pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C> { + EmptyVisitorCtx { + ph: PhantomData, + ctx, + } } pub trait Visitor<'a>: Sized { type Output; fn accept(self, node: SyntaxNodeRef<'a>) -> Option; fn visit(self, f: F) -> Vis - where N: AstNode<'a>, - F: FnOnce(N) -> Self::Output, + where + N: AstNode<'a>, + F: FnOnce(N) -> Self::Output, { - Vis { inner: self, f, ph: PhantomData } + Vis { + inner: self, + f, + ph: PhantomData, + } } } @@ -26,16 +34,21 @@ pub trait VisitorCtx<'a>: Sized { type Ctx; fn accept(self, node: SyntaxNodeRef<'a>) -> Result; fn visit(self, f: F) -> VisCtx - where N: AstNode<'a>, - F: FnOnce(N, Self::Ctx) -> Self::Output, + where + N: AstNode<'a>, + F: FnOnce(N, Self::Ctx) -> Self::Output, { - VisCtx { inner: self, f, ph: PhantomData } + VisCtx { + inner: self, + f, + ph: PhantomData, + } } } #[derive(Debug)] struct EmptyVisitor { - ph: PhantomData T> + ph: PhantomData T>, } impl<'a, T> Visitor<'a> for EmptyVisitor { @@ -69,10 +82,10 @@ pub struct Vis { } impl<'a, V, N, F> Visitor<'a> for Vis - where - V: Visitor<'a>, - N: AstNode<'a>, - F: FnOnce(N) -> >::Output, +where + V: Visitor<'a>, + N: AstNode<'a>, + F: FnOnce(N) -> >::Output, { type Output = >::Output; @@ -90,21 +103,19 @@ pub struct VisCtx { } impl<'a, V, N, F> VisitorCtx<'a> for VisCtx - where - V: VisitorCtx<'a>, - N: AstNode<'a>, - F: FnOnce(N, >::Ctx) -> >::Output, +where + V: VisitorCtx<'a>, + N: AstNode<'a>, + F: FnOnce(N, >::Ctx) -> >::Output, { type Output = >::Output; type Ctx = >::Ctx; fn accept(self, node: SyntaxNodeRef<'a>) -> Result { let VisCtx { inner, f, .. } = self; - inner.accept(node).or_else(|ctx| - match N::cast(node) { - None => Err(ctx), - Some(node) => Ok(f(node, ctx)) - } - ) + inner.accept(node).or_else(|ctx| match N::cast(node) { + None => Err(ctx), + Some(node) => Ok(f(node, ctx)), + }) } } -- cgit v1.2.3