From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 8 Feb 2019 14:49:43 +0300 Subject: reformat the world --- crates/ra_syntax/src/algo/visit.rs | 17 ++----- crates/ra_syntax/src/ast.rs | 37 ++++----------- crates/ra_syntax/src/grammar/expressions.rs | 15 ++---- crates/ra_syntax/src/grammar/expressions/atom.rs | 9 +--- crates/ra_syntax/src/grammar/items.rs | 6 +-- crates/ra_syntax/src/grammar/params.rs | 6 +-- crates/ra_syntax/src/grammar/patterns.rs | 4 +- crates/ra_syntax/src/lexer/ptr.rs | 5 +- crates/ra_syntax/src/lib.rs | 9 +--- crates/ra_syntax/src/parser_api.rs | 5 +- crates/ra_syntax/src/parser_impl.rs | 22 ++------- crates/ra_syntax/src/parser_impl/event.rs | 41 ++++------------ crates/ra_syntax/src/parser_impl/input.rs | 6 +-- crates/ra_syntax/src/ptr.rs | 19 ++------ crates/ra_syntax/src/reparsing.rs | 10 +--- crates/ra_syntax/src/string_lexing/parser.rs | 9 +--- crates/ra_syntax/src/string_lexing/string.rs | 7 +-- crates/ra_syntax/src/validation/block.rs | 6 +-- crates/ra_syntax/src/validation/byte.rs | 30 ++---------- crates/ra_syntax/src/validation/byte_string.rs | 20 ++------ crates/ra_syntax/src/validation/char.rs | 20 ++------ crates/ra_syntax/src/validation/string.rs | 20 ++------ crates/ra_syntax/src/yellow/builder.rs | 5 +- crates/ra_syntax/src/yellow/syntax_error.rs | 12 ++--- crates/ra_syntax/src/yellow/syntax_text.rs | 10 +--- crates/ra_syntax/tests/test.rs | 59 +++++++++--------------- 26 files changed, 95 insertions(+), 314 deletions(-) (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs index 38f21594c..81a99228f 100644 --- a/crates/ra_syntax/src/algo/visit.rs +++ b/crates/ra_syntax/src/algo/visit.rs @@ -7,10 +7,7 @@ pub fn visitor<'a, T>() -> impl Visitor<'a, Output = T> { } pub fn visitor_ctx<'a, T, C>(ctx: C) -> impl VisitorCtx<'a, Output = T, Ctx = C> { - EmptyVisitorCtx { - ph: PhantomData, - ctx, - } + EmptyVisitorCtx { ph: PhantomData, ctx } } pub trait Visitor<'a>: Sized { @@ -21,11 +18,7 @@ pub trait Visitor<'a>: Sized { N: AstNode + 'a, F: FnOnce(&'a N) -> Self::Output, { - Vis { - inner: self, - f, - ph: PhantomData, - } + Vis { inner: self, f, ph: PhantomData } } } @@ -38,11 +31,7 @@ pub trait VisitorCtx<'a>: Sized { N: AstNode + 'a, F: FnOnce(&'a N, Self::Ctx) -> Self::Output, { - VisCtx { - inner: self, - f, - ph: PhantomData, - } + VisCtx { inner: self, f, ph: PhantomData } } } diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index d6237532b..cf5cfecc2 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -127,16 +127,12 @@ pub trait DocCommentsOwner: AstNode { let line = comment.text().as_str(); // Determine if the prefix or prefix + 1 char is stripped - let pos = if line - .chars() - .nth(prefix_len) - .map(|c| c.is_whitespace()) - .unwrap_or(false) - { - prefix_len + 1 - } else { - prefix_len - }; + let pos = + if line.chars().nth(prefix_len).map(|c| c.is_whitespace()).unwrap_or(false) { + prefix_len + 1 + } else { + prefix_len + }; line[pos..].to_owned() }) @@ -357,10 +353,7 @@ pub enum PathSegmentKind<'a> { impl PathSegment { pub fn parent_path(&self) -> &Path { - self.syntax() - .parent() - .and_then(Path::cast) - .expect("segments are always nested in paths") + self.syntax().parent().and_then(Path::cast).expect("segments are always nested in paths") } pub fn kind(&self) -> Option { @@ -428,10 +421,7 @@ pub struct AstChildren<'a, N> { impl<'a, N> AstChildren<'a, N> { fn new(parent: &'a SyntaxNode) -> Self { - AstChildren { - inner: parent.children(), - ph: PhantomData, - } + AstChildren { inner: parent.children(), ph: PhantomData } } } @@ -658,11 +648,7 @@ impl SelfParam { let borrowed = self.syntax().children().any(|n| n.kind() == AMP); if borrowed { // check for a `mut` coming after the & -- `mut &self` != `&mut self` - if self - .syntax() - .children() - .skip_while(|n| n.kind() != AMP) - .any(|n| n.kind() == MUT_KW) + if self.syntax().children().skip_while(|n| n.kind() != AMP).any(|n| n.kind() == MUT_KW) { SelfParamFlavor::MutRef } else { @@ -769,8 +755,5 @@ fn test_doc_comment_preserves_indents() { "#, ); let module = file.syntax().descendants().find_map(Module::cast).unwrap(); - assert_eq!( - "doc1\n```\nfn foo() {\n // ...\n}\n```", - module.doc_comment_text().unwrap() - ); + assert_eq!("doc1\n```\nfn foo() {\n // ...\n}\n```", module.doc_comment_text().unwrap()); } diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs index 6b88c5685..28fcb1f7d 100644 --- a/crates/ra_syntax/src/grammar/expressions.rs +++ b/crates/ra_syntax/src/grammar/expressions.rs @@ -7,26 +7,17 @@ use super::*; const EXPR_FIRST: TokenSet = LHS_FIRST; pub(super) fn expr(p: &mut Parser) -> BlockLike { - let r = Restrictions { - forbid_structs: false, - prefer_stmt: false, - }; + let r = Restrictions { forbid_structs: false, prefer_stmt: false }; expr_bp(p, r, 1) } pub(super) fn expr_stmt(p: &mut Parser) -> BlockLike { - let r = Restrictions { - forbid_structs: false, - prefer_stmt: true, - }; + let r = Restrictions { forbid_structs: false, prefer_stmt: true }; expr_bp(p, r, 1) } fn expr_no_struct(p: &mut Parser) { - let r = Restrictions { - forbid_structs: true, - prefer_stmt: false, - }; + let r = Restrictions { forbid_structs: true, prefer_stmt: false }; expr_bp(p, r, 1); } diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index 600774afd..27ba87657 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs @@ -141,14 +141,7 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { } } p.expect(R_PAREN); - m.complete( - p, - if saw_expr && !saw_comma { - PAREN_EXPR - } else { - TUPLE_EXPR - }, - ) + m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR }) } // test array_expr diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs index 84c18a293..a61f260cf 100644 --- a/crates/ra_syntax/src/grammar/items.rs +++ b/crates/ra_syntax/src/grammar/items.rs @@ -155,11 +155,7 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem { IMPL_BLOCK } _ => { - return if has_mods { - MaybeItem::Modifiers - } else { - MaybeItem::None - }; + return if has_mods { MaybeItem::Modifiers } else { MaybeItem::None }; } }; diff --git a/crates/ra_syntax/src/grammar/params.rs b/crates/ra_syntax/src/grammar/params.rs index 13158429a..185386569 100644 --- a/crates/ra_syntax/src/grammar/params.rs +++ b/crates/ra_syntax/src/grammar/params.rs @@ -36,11 +36,7 @@ impl Flavor { } fn list_(p: &mut Parser, flavor: Flavor) { - let (bra, ket) = if flavor.type_required() { - (L_PAREN, R_PAREN) - } else { - (PIPE, PIPE) - }; + let (bra, ket) = if flavor.type_required() { (L_PAREN, R_PAREN) } else { (PIPE, PIPE) }; assert!(p.at(bra)); let m = p.start(); p.bump(); diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 1ac5efdf6..f3f400ae0 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -2,9 +2,7 @@ use super::*; pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST .union(paths::PATH_FIRST) - .union(token_set![ - REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE - ]); + .union(token_set![REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE]); pub(super) fn pattern(p: &mut Parser) { pattern_r(p, PAT_RECOVERY_SET) diff --git a/crates/ra_syntax/src/lexer/ptr.rs b/crates/ra_syntax/src/lexer/ptr.rs index 0a473c991..c341c4176 100644 --- a/crates/ra_syntax/src/lexer/ptr.rs +++ b/crates/ra_syntax/src/lexer/ptr.rs @@ -11,10 +11,7 @@ pub(crate) struct Ptr<'s> { impl<'s> Ptr<'s> { /// Creates a new `Ptr` from a string. pub fn new(text: &'s str) -> Ptr<'s> { - Ptr { - text, - len: 0.into(), - } + Ptr { text, len: 0.into() } } /// Gets the length of the remaining string. diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 104f32851..088b2f5d7 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs @@ -11,11 +11,7 @@ //! [rfc#2256]: //! [RFC.md]: -#![forbid( - missing_debug_implementations, - unconditional_recursion, - future_incompatible -)] +#![forbid(missing_debug_implementations, unconditional_recursion, future_incompatible)] #![deny(bad_style, missing_docs)] #![allow(missing_docs)] //#![warn(unreachable_pub)] // rust-lang/rust#47816 @@ -70,8 +66,7 @@ impl SourceFile { } pub fn reparse(&self, edit: &AtomTextEdit) -> TreeArc { - self.incremental_reparse(edit) - .unwrap_or_else(|| self.full_reparse(edit)) + self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) } pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option> { diff --git a/crates/ra_syntax/src/parser_api.rs b/crates/ra_syntax/src/parser_api.rs index 3148371c5..504df753e 100644 --- a/crates/ra_syntax/src/parser_api.rs +++ b/crates/ra_syntax/src/parser_api.rs @@ -136,10 +136,7 @@ pub(crate) struct Marker { impl Marker { fn new(pos: u32) -> Marker { - Marker { - pos, - bomb: DropBomb::new("Marker must be either completed or abandoned"), - } + Marker { pos, bomb: DropBomb::new("Marker must be either completed or abandoned") } } /// Finishes the syntax tree node and assigns `kind` to it, diff --git a/crates/ra_syntax/src/parser_impl.rs b/crates/ra_syntax/src/parser_impl.rs index 01a51cd8d..f255dc23b 100644 --- a/crates/ra_syntax/src/parser_impl.rs +++ b/crates/ra_syntax/src/parser_impl.rs @@ -54,9 +54,7 @@ pub(crate) fn parse_with( parser(&mut parser_api); parser_api.0.into_events() }; - EventProcessor::new(sink, text, tokens, &mut events) - .process() - .finish() + EventProcessor::new(sink, text, tokens, &mut events).process().finish() } /// Implementation details of `Parser`, extracted @@ -160,17 +158,13 @@ impl<'t> ParserImpl<'t> { /// Append one Error event to the back of events. pub(super) fn error(&mut self, msg: String) { - self.push_event(Event::Error { - msg: ParseError(msg), - }) + self.push_event(Event::Error { msg: ParseError(msg) }) } /// Complete an event with appending a `Finish` event. pub(super) fn complete(&mut self, pos: u32, kind: SyntaxKind) { match self.events[pos as usize] { - Event::Start { - kind: ref mut slot, .. - } => { + Event::Start { kind: ref mut slot, .. } => { *slot = kind; } _ => unreachable!(), @@ -183,10 +177,7 @@ impl<'t> ParserImpl<'t> { let idx = pos as usize; if idx == self.events.len() - 1 { match self.events.pop() { - Some(Event::Start { - kind: TOMBSTONE, - forward_parent: None, - }) => (), + Some(Event::Start { kind: TOMBSTONE, forward_parent: None }) => (), _ => unreachable!(), } } @@ -196,10 +187,7 @@ impl<'t> ParserImpl<'t> { pub(super) fn precede(&mut self, pos: u32) -> u32 { let new_pos = self.start(); match self.events[pos as usize] { - Event::Start { - ref mut forward_parent, - .. - } => { + Event::Start { ref mut forward_parent, .. } => { *forward_parent = Some(new_pos - pos); } _ => unreachable!(), diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index 33e10ef85..677876ab5 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs @@ -86,10 +86,7 @@ pub(crate) enum Event { impl Event { pub(crate) fn tombstone() -> Self { - Event::Start { - kind: TOMBSTONE, - forward_parent: None, - } + Event::Start { kind: TOMBSTONE, forward_parent: None } } } @@ -109,14 +106,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { tokens: &'a [Token], events: &'a mut [Event], ) -> EventProcessor<'a, S> { - EventProcessor { - sink, - text_pos: 0.into(), - text, - token_pos: 0, - tokens, - events, - } + EventProcessor { sink, text_pos: 0.into(), text, token_pos: 0, tokens, events } } /// Generate the syntax tree with the control of events. @@ -125,14 +115,9 @@ impl<'a, S: Sink> EventProcessor<'a, S> { for i in 0..self.events.len() { match mem::replace(&mut self.events[i], Event::tombstone()) { - Event::Start { - kind: TOMBSTONE, .. - } => (), + Event::Start { kind: TOMBSTONE, .. } => (), - Event::Start { - kind, - forward_parent, - } => { + Event::Start { kind, forward_parent } => { // For events[A, B, C], B is A's forward_parent, C is B's forward_parent, // in the normal control flow, the parent-child relation: `A -> B -> C`, // while with the magic forward_parent, it writes: `C <- B <- A`. @@ -145,10 +130,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { idx += fwd as usize; // append `A`'s forward_parent `B` fp = match mem::replace(&mut self.events[idx], Event::tombstone()) { - Event::Start { - kind, - forward_parent, - } => { + Event::Start { kind, forward_parent } => { forward_parents.push(kind); forward_parent } @@ -174,10 +156,9 @@ impl<'a, S: Sink> EventProcessor<'a, S> { .sum::(); self.leaf(kind, len, n_raw_tokens); } - Event::Error { msg } => self.sink.error(SyntaxError::new( - SyntaxErrorKind::ParseError(msg), - self.text_pos, - )), + Event::Error { msg } => self + .sink + .error(SyntaxError::new(SyntaxErrorKind::ParseError(msg), self.text_pos)), } } self.sink @@ -189,10 +170,8 @@ impl<'a, S: Sink> EventProcessor<'a, S> { self.sink.start_branch(kind); return; } - let n_trivias = self.tokens[self.token_pos..] - .iter() - .take_while(|it| it.kind.is_trivia()) - .count(); + let n_trivias = + self.tokens[self.token_pos..].iter().take_while(|it| it.kind.is_trivia()).count(); let leading_trivias = &self.tokens[self.token_pos..self.token_pos + n_trivias]; let mut trivia_end = self.text_pos + leading_trivias.iter().map(|it| it.len).sum::(); diff --git a/crates/ra_syntax/src/parser_impl/input.rs b/crates/ra_syntax/src/parser_impl/input.rs index 7fde5b3ab..616a26fdc 100644 --- a/crates/ra_syntax/src/parser_impl/input.rs +++ b/crates/ra_syntax/src/parser_impl/input.rs @@ -36,11 +36,7 @@ impl<'t> ParserInput<'t> { len += token.len; } - ParserInput { - text, - start_offsets, - tokens, - } + ParserInput { text, start_offsets, tokens } } /// Get the syntax kind of token at given input position. diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index 13ee1305f..aae590cb6 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs @@ -15,16 +15,12 @@ pub struct SyntaxNodePtr { impl SyntaxNodePtr { pub fn new(node: &SyntaxNode) -> SyntaxNodePtr { - SyntaxNodePtr { - range: node.range(), - kind: node.kind(), - } + SyntaxNodePtr { range: node.range(), kind: node.kind() } } pub fn to_node(self, source_file: &SourceFile) -> &SyntaxNode { generate(Some(source_file.syntax()), |&node| { - node.children() - .find(|it| self.range.is_subrange(&it.range())) + node.children().find(|it| self.range.is_subrange(&it.range())) }) .find(|it| it.range() == self.range && it.kind() == self.kind) .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) @@ -55,10 +51,7 @@ impl Clone for AstPtr { impl AstPtr { pub fn new(node: &N) -> AstPtr { - AstPtr { - raw: SyntaxNodePtr::new(node.syntax()), - _ty: PhantomData, - } + AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } } pub fn to_node(self, source_file: &SourceFile) -> &N { @@ -76,11 +69,7 @@ fn test_local_syntax_ptr() { use crate::{ast, AstNode}; let file = SourceFile::parse("struct Foo { f: u32, }"); - let field = file - .syntax() - .descendants() - .find_map(ast::NamedFieldDef::cast) - .unwrap(); + let field = file.syntax().descendants().find_map(ast::NamedFieldDef::cast).unwrap(); let ptr = SyntaxNodePtr::new(field.syntax()); let field_syntax = ptr.to_node(&file); assert_eq!(field.syntax(), &*field_syntax); diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 2f1de6b02..c5c609ad5 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs @@ -75,10 +75,7 @@ fn is_contextual_kw(text: &str) -> bool { type ParseFn = fn(&mut Parser); fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, ParseFn)> { let node = algo::find_covering_node(node, range); - return node - .ancestors() - .filter_map(|node| reparser(node).map(|r| (node, r))) - .next(); + return node.ancestors().filter_map(|node| reparser(node).map(|r| (node, r))).next(); fn reparser(node: &SyntaxNode) -> Option { let res = match node.kind() { @@ -169,10 +166,7 @@ mod tests { let fully_reparsed = SourceFile::parse(&after); let incrementally_reparsed = { let f = SourceFile::parse(&before); - let edit = AtomTextEdit { - delete: range, - insert: replace_with.to_string(), - }; + let edit = AtomTextEdit { delete: range, insert: replace_with.to_string() }; let (node, green, new_errors) = reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); let green_root = node.replace_with(green); diff --git a/crates/ra_syntax/src/string_lexing/parser.rs b/crates/ra_syntax/src/string_lexing/parser.rs index e835382fc..7469eb903 100644 --- a/crates/ra_syntax/src/string_lexing/parser.rs +++ b/crates/ra_syntax/src/string_lexing/parser.rs @@ -24,9 +24,7 @@ impl<'a> Parser<'a> { } pub fn advance(&mut self) -> char { - let next = self - .peek() - .expect("cannot advance if end of input is reached"); + let next = self.peek().expect("cannot advance if end of input is reached"); self.pos += next.len_utf8(); next } @@ -133,10 +131,7 @@ impl<'a> Parser<'a> { Some(self.parse_escape(start)) } else { let end = self.get_pos(); - Some(StringComponent::new( - TextRange::from_to(start, end), - CodePoint, - )) + Some(StringComponent::new(TextRange::from_to(start, end), CodePoint)) } } diff --git a/crates/ra_syntax/src/string_lexing/string.rs b/crates/ra_syntax/src/string_lexing/string.rs index 064f08544..a4742a0d1 100644 --- a/crates/ra_syntax/src/string_lexing/string.rs +++ b/crates/ra_syntax/src/string_lexing/string.rs @@ -120,12 +120,7 @@ mod tests { fn closed_char_component(src: &str) -> StringComponent { let (has_closing_quote, components) = parse(src); assert!(has_closing_quote, "char should have closing quote"); - assert!( - components.len() == 1, - "Literal: {}\nComponents: {:#?}", - src, - components - ); + assert!(components.len() == 1, "Literal: {}\nComponents: {:#?}", src, components); components[0].clone() } diff --git a/crates/ra_syntax/src/validation/block.rs b/crates/ra_syntax/src/validation/block.rs index 9e1949124..4e77c15b6 100644 --- a/crates/ra_syntax/src/validation/block.rs +++ b/crates/ra_syntax/src/validation/block.rs @@ -17,8 +17,6 @@ pub(crate) fn validate_block_node(node: &ast::Block, errors: &mut Vec {} } } - errors.extend( - node.attrs() - .map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range())), - ) + errors + .extend(node.attrs().map(|attr| SyntaxError::new(InvalidBlockAttr, attr.syntax().range()))) } diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs index 9bddabc80..d51fabcf9 100644 --- a/crates/ra_syntax/src/validation/byte.rs +++ b/crates/ra_syntax/src/validation/byte.rs @@ -28,10 +28,7 @@ pub(super) fn validate_byte_node(node: &ast::Byte, errors: &mut Vec } if let Some(range) = components.suffix { - errors.push(SyntaxError::new( - InvalidSuffix, - range + literal_range.start(), - )); + errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); } if len == 0 { @@ -55,10 +52,7 @@ pub(super) fn validate_byte_component( AsciiCodeEscape => validate_byte_code_escape(text, range, errors), UnicodeEscape => errors.push(SyntaxError::new(UnicodeEscapeForbidden, range)), CodePoint => { - let c = text - .chars() - .next() - .expect("Code points should be one character long"); + let c = text.chars().next().expect("Code points should be one character long"); // These bytes must always be escaped if c == '\t' || c == '\r' || c == '\n' { @@ -93,10 +87,7 @@ fn validate_byte_code_escape(text: &str, range: TextRange, errors: &mut Vec } if let Some(range) = components.suffix { - errors.push(SyntaxError::new( - InvalidSuffix, - range + literal_range.start(), - )); + errors.push(SyntaxError::new(InvalidSuffix, range + literal_range.start())); } if len == 0 { @@ -184,12 +181,7 @@ mod test { fn assert_valid_char(literal: &str) { let file = build_file(literal); - assert!( - file.errors().len() == 0, - "Errors for literal '{}': {:?}", - literal, - file.errors() - ); + assert!(file.errors().len() == 0, "Errors for literal '{}': {:?}", literal, file.errors()); } fn assert_invalid_char(literal: &str) { @@ -258,13 +250,7 @@ mod test { #[test] fn test_valid_unicode_escape() { - let valid = [ - r"\u{FF}", - r"\u{0}", - r"\u{F}", - r"\u{10FFFF}", - r"\u{1_0__FF___FF_____}", - ]; + let valid = [r"\u{FF}", r"\u{0}", r"\u{F}", r"\u{10FFFF}", r"\u{1_0__FF___FF_____}"]; for c in &valid { assert_valid_char(c); } diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs index 365fe8d2d..4fd7fffdf 100644 --- a/crates/ra_syntax/src/validation/string.rs +++ b/crates/ra_syntax/src/validation/string.rs @@ -29,10 +29,7 @@ pub(crate) fn validate_string_node(node: &ast::String, errors: &mut Vec GreenBuilder { - GreenBuilder { - errors: Vec::new(), - inner: GreenNodeBuilder::new(), - } + GreenBuilder { errors: Vec::new(), inner: GreenNodeBuilder::new() } } } diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs index c52c44cc3..412cf82cc 100644 --- a/crates/ra_syntax/src/yellow/syntax_error.rs +++ b/crates/ra_syntax/src/yellow/syntax_error.rs @@ -28,10 +28,7 @@ impl Into for TextRange { impl SyntaxError { pub fn new>(kind: SyntaxErrorKind, loc: L) -> SyntaxError { - SyntaxError { - kind, - location: loc.into(), - } + SyntaxError { kind, location: loc.into() } } pub fn kind(&self) -> SyntaxErrorKind { @@ -119,10 +116,9 @@ impl fmt::Display for SyntaxErrorKind { InvalidByteEscape => write!(f, "Invalid escape sequence"), TooShortByteCodeEscape => write!(f, "Escape sequence should have two digits"), MalformedByteCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"), - UnicodeEscapeForbidden => write!( - f, - "Unicode escapes are not allowed in byte literals or byte strings" - ), + UnicodeEscapeForbidden => { + write!(f, "Unicode escapes are not allowed in byte literals or byte strings") + } TooShortAsciiCodeEscape => write!(f, "Escape sequence should have two digits"), AsciiCodeEscapeOutOfRange => { write!(f, "Escape sequence should be between \\x00 and \\x7F") diff --git a/crates/ra_syntax/src/yellow/syntax_text.rs b/crates/ra_syntax/src/yellow/syntax_text.rs index 378cd1b2e..84e5b231a 100644 --- a/crates/ra_syntax/src/yellow/syntax_text.rs +++ b/crates/ra_syntax/src/yellow/syntax_text.rs @@ -10,10 +10,7 @@ pub struct SyntaxText<'a> { impl<'a> SyntaxText<'a> { pub(crate) fn new(node: &'a SyntaxNode) -> SyntaxText<'a> { - SyntaxText { - node, - range: node.range(), - } + SyntaxText { node, range: node.range() } } pub fn chunks(&self) -> impl Iterator { @@ -58,10 +55,7 @@ impl<'a> SyntaxText<'a> { let range = range.restrict(self.range).unwrap_or_else(|| { panic!("invalid slice, range: {:?}, slice: {:?}", self.range, range) }); - SyntaxText { - node: self.node, - range, - } + SyntaxText { node: self.node, range } } pub fn char_at(&self, offset: impl Into) -> Option { diff --git a/crates/ra_syntax/tests/test.rs b/crates/ra_syntax/tests/test.rs index 3243b27ae..168d0623d 100644 --- a/crates/ra_syntax/tests/test.rs +++ b/crates/ra_syntax/tests/test.rs @@ -23,36 +23,28 @@ fn lexer_tests() { #[test] fn parser_tests() { - dir_tests( - &test_data_dir(), - &["parser/inline/ok", "parser/ok"], - |text, path| { - let file = SourceFile::parse(text); - let errors = file.errors(); - assert_eq!( - &*errors, - &[] as &[ra_syntax::SyntaxError], - "There should be no errors in the file {:?}", - path.display() - ); - dump_tree(file.syntax()) - }, - ); - dir_tests( - &test_data_dir(), - &["parser/err", "parser/inline/err"], - |text, path| { - let file = SourceFile::parse(text); - let errors = file.errors(); - assert_ne!( - &*errors, - &[] as &[ra_syntax::SyntaxError], - "There should be errors in the file {:?}", - path.display() - ); - dump_tree(file.syntax()) - }, - ); + dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], |text, path| { + let file = SourceFile::parse(text); + let errors = file.errors(); + assert_eq!( + &*errors, + &[] as &[ra_syntax::SyntaxError], + "There should be no errors in the file {:?}", + path.display() + ); + dump_tree(file.syntax()) + }); + dir_tests(&test_data_dir(), &["parser/err", "parser/inline/err"], |text, path| { + let file = SourceFile::parse(text); + let errors = file.errors(); + assert_ne!( + &*errors, + &[] as &[ra_syntax::SyntaxError], + "There should be errors in the file {:?}", + path.display() + ); + dump_tree(file.syntax()) + }); } #[test] @@ -87,12 +79,7 @@ fn self_hosting_parsing() { let text = read_text(entry.path()); let node = SourceFile::parse(&text); let errors = node.errors(); - assert_eq!( - &*errors, - &[], - "There should be no errors in the file {:?}", - entry - ); + assert_eq!(&*errors, &[], "There should be no errors in the file {:?}", entry); } assert!( count > 30, -- cgit v1.2.3