From 4de3c97b2afea55834cd16368f950133459d8c73 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Sat, 27 Jan 2018 18:31:23 -0500 Subject: Enforce rustfmt format --- src/tree/file_builder.rs | 32 ++++++++++++++++++++------------ src/tree/mod.rs | 44 ++++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 32 deletions(-) (limited to 'src/tree') diff --git a/src/tree/file_builder.rs b/src/tree/file_builder.rs index 35702ddd7..939922cb2 100644 --- a/src/tree/file_builder.rs +++ b/src/tree/file_builder.rs @@ -1,5 +1,5 @@ -use {SyntaxKind, TextUnit, TextRange}; -use super::{NodeData, SyntaxErrorData, NodeIdx, File}; +use {SyntaxKind, TextRange, TextUnit}; +use super::{File, NodeData, NodeIdx, SyntaxErrorData}; pub trait Sink { fn leaf(&mut self, kind: SyntaxKind, len: TextUnit); @@ -8,7 +8,6 @@ pub trait Sink { fn error(&mut self) -> ErrorBuilder; } - pub struct FileBuilder { text: String, nodes: Vec, @@ -48,9 +47,9 @@ impl Sink for FileBuilder { } fn finish_internal(&mut self) { - let (id, _) = self.in_progress.pop().expect( - "trying to complete a node, but there are no in-progress nodes" - ); + let (id, _) = self.in_progress + .pop() + .expect("trying to complete a node, but there are no in-progress nodes"); if !self.in_progress.is_empty() { self.add_len(id); } @@ -76,11 +75,14 @@ impl FileBuilder { assert!( self.in_progress.is_empty(), "some nodes in FileBuilder are unfinished: {:?}", - self.in_progress.iter().map(|&(idx, _)| self.nodes[idx].kind) + self.in_progress + .iter() + .map(|&(idx, _)| self.nodes[idx].kind) .collect::>() ); assert_eq!( - self.pos, (self.text.len() as u32).into(), + self.pos, + (self.text.len() as u32).into(), "nodes in FileBuilder do not cover the whole file" ); File { @@ -100,7 +102,6 @@ impl FileBuilder { child.parent = Some(self.current_id()); let id = self.new_node(child); { - let (parent, sibling) = *self.in_progress.last().unwrap(); let slot = if let Some(idx) = sibling { &mut self.nodes[idx].next_sibling @@ -140,12 +141,15 @@ fn grow(left: &mut TextRange, right: TextRange) { pub struct ErrorBuilder<'f> { message: Option, - builder: &'f mut FileBuilder + builder: &'f mut FileBuilder, } impl<'f> ErrorBuilder<'f> { fn new(builder: &'f mut FileBuilder) -> Self { - ErrorBuilder { message: None, builder } + ErrorBuilder { + message: None, + builder, + } } pub fn message>(mut self, m: M) -> Self { @@ -156,6 +160,10 @@ impl<'f> ErrorBuilder<'f> { pub fn emit(self) { let message = self.message.expect("Error message not set"); let &(node, after_child) = self.builder.in_progress.last().unwrap(); - self.builder.errors.push(SyntaxErrorData { node, message, after_child }) + self.builder.errors.push(SyntaxErrorData { + node, + message, + after_child, + }) } } diff --git a/src/tree/mod.rs b/src/tree/mod.rs index 3315b926e..a330caf54 100644 --- a/src/tree/mod.rs +++ b/src/tree/mod.rs @@ -1,4 +1,4 @@ -use text::{TextUnit, TextRange}; +use text::{TextRange, TextUnit}; use syntax_kinds::syntax_info; use std::fmt; @@ -11,15 +11,10 @@ pub use self::file_builder::{FileBuilder, Sink}; pub struct SyntaxKind(pub(crate) u32); pub(crate) const EOF: SyntaxKind = SyntaxKind(!0); -pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { - name: "EOF" -}; +pub(crate) const EOF_INFO: SyntaxInfo = SyntaxInfo { name: "EOF" }; pub(crate) const TOMBSTONE: SyntaxKind = SyntaxKind(!0 - 1); -pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { - name: "TOMBSTONE" -}; - +pub(crate) const TOMBSTONE_INFO: SyntaxInfo = SyntaxInfo { name: "TOMBSTONE" }; impl SyntaxKind { fn info(self) -> &'static SyntaxInfo { @@ -38,7 +33,6 @@ impl fmt::Debug for SyntaxKind { } } - pub(crate) struct SyntaxInfo { pub name: &'static str, } @@ -58,7 +52,10 @@ pub struct File { impl File { pub fn root<'f>(&'f self) -> Node<'f> { assert!(!self.nodes.is_empty()); - Node { file: self, idx: NodeIdx(0) } + Node { + file: self, + idx: NodeIdx(0), + } } } @@ -86,14 +83,17 @@ impl<'f> Node<'f> { } pub fn children(&self) -> Children<'f> { - Children { next: self.as_node(self.data().first_child) } + Children { + next: self.as_node(self.data().first_child), + } } pub fn errors(&self) -> SyntaxErrors<'f> { let pos = self.file.errors.iter().position(|e| e.node == self.idx); - let next = pos - .map(|i| ErrorIdx(i as u32)) - .map(|idx| SyntaxError { file: self.file, idx }); + let next = pos.map(|i| ErrorIdx(i as u32)).map(|idx| SyntaxError { + file: self.file, + idx, + }); SyntaxErrors { next } } @@ -102,7 +102,10 @@ impl<'f> Node<'f> { } fn as_node(&self, idx: Option) -> Option> { - idx.map(|idx| Node { file: self.file, idx }) + idx.map(|idx| Node { + file: self.file, + idx, + }) } } @@ -118,8 +121,7 @@ impl<'f> cmp::PartialEq> for Node<'f> { } } -impl<'f> cmp::Eq for Node<'f> { -} +impl<'f> cmp::Eq for Node<'f> {} #[derive(Clone, Copy)] pub struct SyntaxError<'f> { @@ -134,7 +136,10 @@ impl<'f> SyntaxError<'f> { pub fn after_child(&self) -> Option> { let idx = self.data().after_child?; - Some(Node { file: self.file, idx }) + Some(Node { + file: self.file, + idx, + }) } fn data(&self) -> &'f SyntaxErrorData { @@ -148,7 +153,7 @@ impl<'f> SyntaxError<'f> { } let result = SyntaxError { file: self.file, - idx: ErrorIdx(next_idx) + idx: ErrorIdx(next_idx), }; if result.data().node != self.data().node { return None; @@ -185,7 +190,6 @@ impl<'f> Iterator for SyntaxErrors<'f> { } } - #[derive(Clone, Copy, PartialEq, Eq)] struct NodeIdx(u32); -- cgit v1.2.3