From 12e3b4c70b5ef23b2fdfc197296d483680e125f9 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Fri, 8 Feb 2019 14:49:43 +0300
Subject: reformat the world

---
 crates/ra_ide_api_light/src/diagnostics.rs      |  32 +----
 crates/ra_ide_api_light/src/extend_selection.rs |  57 ++------
 crates/ra_ide_api_light/src/folding_ranges.rs   |  47 ++-----
 crates/ra_ide_api_light/src/formatting.rs       |   5 +-
 crates/ra_ide_api_light/src/join_lines.rs       |  27 +---
 crates/ra_ide_api_light/src/lib.rs              |  14 +-
 crates/ra_ide_api_light/src/line_index.rs       | 165 ++++--------------------
 crates/ra_ide_api_light/src/line_index_utils.rs |  51 ++------
 crates/ra_ide_api_light/src/structure.rs        |  13 +-
 crates/ra_ide_api_light/src/typing.rs           |  17 +--
 10 files changed, 77 insertions(+), 351 deletions(-)

(limited to 'crates/ra_ide_api_light')

diff --git a/crates/ra_ide_api_light/src/diagnostics.rs b/crates/ra_ide_api_light/src/diagnostics.rs
index 2b695dfdf..7c383ca2a 100644
--- a/crates/ra_ide_api_light/src/diagnostics.rs
+++ b/crates/ra_ide_api_light/src/diagnostics.rs
@@ -72,14 +72,7 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
     single_use_tree: &ast::UseTree,
 ) -> Option<TextEdit> {
     let use_tree_list_node = single_use_tree.syntax().parent()?;
-    if single_use_tree
-        .path()?
-        .segment()?
-        .syntax()
-        .first_child()?
-        .kind()
-        == SyntaxKind::SELF_KW
-    {
+    if single_use_tree.path()?.segment()?.syntax().first_child()?.kind() == SyntaxKind::SELF_KW {
         let start = use_tree_list_node.prev_sibling()?.range().start();
         let end = use_tree_list_node.range().end();
         let range = TextRange::from_to(start, end);
@@ -145,9 +138,8 @@ mod tests {
         for node in file.syntax().descendants() {
             func(&mut diagnostics, node);
         }
-        let diagnostic = diagnostics
-            .pop()
-            .unwrap_or_else(|| panic!("no diagnostics for:\n{}\n", before));
+        let diagnostic =
+            diagnostics.pop().unwrap_or_else(|| panic!("no diagnostics for:\n{}\n", before));
         let fix = diagnostic.fix.unwrap();
         let actual = fix.edit.apply(&before);
         assert_eq_text!(after, &actual);
@@ -162,21 +154,9 @@ mod tests {
         ",
             check_unnecessary_braces_in_use_statement,
         );
-        check_apply(
-            "use {b};",
-            "use b;",
-            check_unnecessary_braces_in_use_statement,
-        );
-        check_apply(
-            "use a::{c};",
-            "use a::c;",
-            check_unnecessary_braces_in_use_statement,
-        );
-        check_apply(
-            "use a::{self};",
-            "use a;",
-            check_unnecessary_braces_in_use_statement,
-        );
+        check_apply("use {b};", "use b;", check_unnecessary_braces_in_use_statement);
+        check_apply("use a::{c};", "use a::c;", check_unnecessary_braces_in_use_statement);
+        check_apply("use a::{self};", "use a;", check_unnecessary_braces_in_use_statement);
         check_apply(
             "use a::{c, d::{e}};",
             "use a::{c, d::e};",
diff --git a/crates/ra_ide_api_light/src/extend_selection.rs b/crates/ra_ide_api_light/src/extend_selection.rs
index f396dfe3f..28d62f290 100644
--- a/crates/ra_ide_api_light/src/extend_selection.rs
+++ b/crates/ra_ide_api_light/src/extend_selection.rs
@@ -43,11 +43,7 @@ pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange
     let node = find_covering_node(root, range);
 
     // Using shallowest node with same range allows us to traverse siblings.
-    let node = node
-        .ancestors()
-        .take_while(|n| n.range() == node.range())
-        .last()
-        .unwrap();
+    let node = node.ancestors().take_while(|n| n.range() == node.range()).last().unwrap();
 
     if range == node.range() {
         if string_kinds.contains(&node.kind()) {
@@ -145,10 +141,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
     }
 
     if let Some(comma_node) = nearby_comma(node, Direction::Prev) {
-        return Some(TextRange::from_to(
-            comma_node.range().start(),
-            node.range().end(),
-        ));
+        return Some(TextRange::from_to(comma_node.range().start(), node.range().end()));
     }
 
     if let Some(comma_node) = nearby_comma(node, Direction::Next) {
@@ -160,10 +153,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
             .filter(|node| is_single_line_ws(node))
             .unwrap_or(comma_node);
 
-        return Some(TextRange::from_to(
-            node.range().start(),
-            final_node.range().end(),
-        ));
+        return Some(TextRange::from_to(node.range().start(), final_node.range().end()));
     }
 
     return None;
@@ -217,36 +207,15 @@ mod tests {
     #[test]
     fn test_extend_selection_list() {
         do_check(r#"fn foo(<|>x: i32) {}"#, &["x", "x: i32"]);
-        do_check(
-            r#"fn foo(<|>x: i32, y: i32) {}"#,
-            &["x", "x: i32", "x: i32, "],
-        );
-        do_check(
-            r#"fn foo(<|>x: i32,y: i32) {}"#,
-            &["x", "x: i32", "x: i32,"],
-        );
-        do_check(
-            r#"fn foo(x: i32, <|>y: i32) {}"#,
-            &["y", "y: i32", ", y: i32"],
-        );
-        do_check(
-            r#"fn foo(x: i32, <|>y: i32, ) {}"#,
-            &["y", "y: i32", ", y: i32"],
-        );
-        do_check(
-            r#"fn foo(x: i32,<|>y: i32) {}"#,
-            &["y", "y: i32", ",y: i32"],
-        );
+        do_check(r#"fn foo(<|>x: i32, y: i32) {}"#, &["x", "x: i32", "x: i32, "]);
+        do_check(r#"fn foo(<|>x: i32,y: i32) {}"#, &["x", "x: i32", "x: i32,"]);
+        do_check(r#"fn foo(x: i32, <|>y: i32) {}"#, &["y", "y: i32", ", y: i32"]);
+        do_check(r#"fn foo(x: i32, <|>y: i32, ) {}"#, &["y", "y: i32", ", y: i32"]);
+        do_check(r#"fn foo(x: i32,<|>y: i32) {}"#, &["y", "y: i32", ",y: i32"]);
 
-        do_check(
-            r#"const FOO: [usize; 2] = [ 22<|> , 33];"#,
-            &["22", "22 , "],
-        );
+        do_check(r#"const FOO: [usize; 2] = [ 22<|> , 33];"#, &["22", "22 , "]);
         do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|>];"#, &["33", ", 33"]);
-        do_check(
-            r#"const FOO: [usize; 2] = [ 22 , 33<|> ,];"#,
-            &["33", ", 33"],
-        );
+        do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|> ,];"#, &["33", ", 33"]);
 
         do_check(
             r#"
@@ -292,11 +261,7 @@ struct B {
     <|>
 }
             "#,
-            &[
-                "\n    \n",
-                "{\n    \n}",
-                "/// bla\n/// bla\nstruct B {\n    \n}",
-            ],
+            &["\n    \n", "{\n    \n}", "/// bla\n/// bla\nstruct B {\n    \n}"],
         )
     }
 
diff --git a/crates/ra_ide_api_light/src/folding_ranges.rs b/crates/ra_ide_api_light/src/folding_ranges.rs
index c73637323..357a7dee1 100644
--- a/crates/ra_ide_api_light/src/folding_ranges.rs
+++ b/crates/ra_ide_api_light/src/folding_ranges.rs
@@ -30,30 +30,21 @@ pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
         // Fold items that span multiple lines
         if let Some(kind) = fold_kind(node.kind()) {
             if node.text().contains('\n') {
-                res.push(Fold {
-                    range: node.range(),
-                    kind,
-                });
+                res.push(Fold { range: node.range(), kind });
             }
         }
 
         // Fold groups of comments
         if node.kind() == COMMENT && !visited_comments.contains(&node) {
             if let Some(range) = contiguous_range_for_comment(node, &mut visited_comments) {
-                res.push(Fold {
-                    range,
-                    kind: FoldKind::Comment,
-                })
+                res.push(Fold { range, kind: FoldKind::Comment })
             }
         }
 
         // Fold groups of imports
         if node.kind() == USE_ITEM && !visited_imports.contains(&node) {
             if let Some(range) = contiguous_range_for_group(node, &mut visited_imports) {
-                res.push(Fold {
-                    range,
-                    kind: FoldKind::Imports,
-                })
+                res.push(Fold { range, kind: FoldKind::Imports })
             }
         }
 
@@ -62,10 +53,7 @@ pub fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
             if let Some(range) =
                 contiguous_range_for_group_unless(node, has_visibility, &mut visited_mods)
             {
-                res.push(Fold {
-                    range,
-                    kind: FoldKind::Mods,
-                })
+                res.push(Fold { range, kind: FoldKind::Mods })
             }
         }
     }
@@ -84,9 +72,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
 }
 
 fn has_visibility(node: &SyntaxNode) -> bool {
-    ast::Module::cast(node)
-        .and_then(|m| m.visibility())
-        .is_some()
+    ast::Module::cast(node).and_then(|m| m.visibility()).is_some()
 }
 
 fn contiguous_range_for_group<'a>(
@@ -125,10 +111,7 @@ fn contiguous_range_for_group_unless<'a>(
     }
 
     if first != last {
-        Some(TextRange::from_to(
-            first.range().start(),
-            last.range().end(),
-        ))
+        Some(TextRange::from_to(first.range().start(), last.range().end()))
     } else {
         // The group consists of only one element, therefore it cannot be folded
         None
@@ -169,10 +152,7 @@ fn contiguous_range_for_comment<'a>(
     }
 
     if first != last {
-        Some(TextRange::from_to(
-            first.range().start(),
-            last.range().end(),
-        ))
+        Some(TextRange::from_to(first.range().start(), last.range().end()))
     } else {
         // The group consists of only one element, therefore it cannot be folded
         None
@@ -199,10 +179,8 @@ mod tests {
             fold_kinds.len(),
             "The amount of fold kinds is different than the expected amount"
         );
-        for ((fold, range), fold_kind) in folds
-            .into_iter()
-            .zip(ranges.into_iter())
-            .zip(fold_kinds.into_iter())
+        for ((fold, range), fold_kind) in
+            folds.into_iter().zip(ranges.into_iter()).zip(fold_kinds.into_iter())
         {
             assert_eq!(fold.range.start(), range.start());
             assert_eq!(fold.range.end(), range.end());
@@ -280,12 +258,7 @@ mod with_attribute_next;</fold>
 fn main() <fold>{
 }</fold>"#;
 
-        let folds = &[
-            FoldKind::Mods,
-            FoldKind::Mods,
-            FoldKind::Mods,
-            FoldKind::Block,
-        ];
+        let folds = &[FoldKind::Mods, FoldKind::Mods, FoldKind::Mods, FoldKind::Block];
         do_check(text, folds);
     }
 
diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_ide_api_light/src/formatting.rs
index 46ffa7d96..8bc03f974 100644
--- a/crates/ra_ide_api_light/src/formatting.rs
+++ b/crates/ra_ide_api_light/src/formatting.rs
@@ -32,10 +32,7 @@ fn prev_leaves(node: &SyntaxNode) -> impl Iterator<Item = &SyntaxNode> {
 }
 
 fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> {
-    generate(node.ancestors().find_map(SyntaxNode::prev_sibling), |it| {
-        it.last_child()
-    })
-    .last()
+    generate(node.ancestors().find_map(SyntaxNode::prev_sibling), |it| it.last_child()).last()
 }
 
 pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
diff --git a/crates/ra_ide_api_light/src/join_lines.rs b/crates/ra_ide_api_light/src/join_lines.rs
index ab7c5b4b5..03770c52e 100644
--- a/crates/ra_ide_api_light/src/join_lines.rs
+++ b/crates/ra_ide_api_light/src/join_lines.rs
@@ -50,11 +50,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
         }
     }
 
-    LocalEdit {
-        label: "join lines".to_string(),
-        edit: edit.finish(),
-        cursor_position: None,
-    }
+    LocalEdit { label: "join lines".to_string(), edit: edit.finish(), cursor_position: None }
 }
 
 fn remove_newline(
@@ -71,10 +67,7 @@ fn remove_newline(
         )];
         let spaces = suff.bytes().take_while(|&b| b == b' ').count();
 
-        edit.replace(
-            TextRange::offset_len(offset, ((spaces + 1) as u32).into()),
-            " ".to_string(),
-        );
+        edit.replace(TextRange::offset_len(offset, ((spaces + 1) as u32).into()), " ".to_string());
         return;
     }
 
@@ -109,11 +102,7 @@ fn remove_newline(
         edit.delete(TextRange::from_to(prev.range().start(), node.range().end()));
     } else if prev.kind() == COMMA && next.kind() == R_CURLY {
         // Removes: comma, newline (incl. surrounding whitespace)
-        let space = if let Some(left) = prev.prev_sibling() {
-            compute_ws(left, next)
-        } else {
-            " "
-        };
+        let space = if let Some(left) = prev.prev_sibling() { compute_ws(left, next) } else { " " };
         edit.replace(
             TextRange::from_to(prev.range().start(), node.range().end()),
             space.to_string(),
@@ -134,20 +123,14 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Opti
     let block = ast::Block::cast(node.parent()?)?;
     let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?;
     let expr = extract_trivial_expression(block)?;
-    edit.replace(
-        block_expr.syntax().range(),
-        expr.syntax().text().to_string(),
-    );
+    edit.replace(block_expr.syntax().range(), expr.syntax().text().to_string());
     Some(())
 }
 
 fn join_single_use_tree(edit: &mut TextEditBuilder, node: &SyntaxNode) -> Option<()> {
     let use_tree_list = ast::UseTreeList::cast(node.parent()?)?;
     let (tree,) = use_tree_list.use_trees().collect_tuple()?;
-    edit.replace(
-        use_tree_list.syntax().range(),
-        tree.syntax().text().to_string(),
-    );
+    edit.replace(use_tree_list.syntax().range(), tree.syntax().text().to_string());
     Some(())
 }
 
diff --git a/crates/ra_ide_api_light/src/lib.rs b/crates/ra_ide_api_light/src/lib.rs
index 17044270c..f3078f51e 100644
--- a/crates/ra_ide_api_light/src/lib.rs
+++ b/crates/ra_ide_api_light/src/lib.rs
@@ -63,9 +63,8 @@ pub struct Diagnostic {
 }
 
 pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> {
-    const BRACES: &[SyntaxKind] = &[
-        L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE,
-    ];
+    const BRACES: &[SyntaxKind] =
+        &[L_CURLY, R_CURLY, L_BRACK, R_BRACK, L_PAREN, R_PAREN, L_ANGLE, R_ANGLE];
     let (brace_node, brace_idx) = find_leaf_at_offset(file.syntax(), offset)
         .filter_map(|node| {
             let idx = BRACES.iter().position(|&brace| brace == node.kind())?;
@@ -74,9 +73,7 @@ pub fn matching_brace(file: &SourceFile, offset: TextUnit) -> Option<TextUnit> {
         .next()?;
     let parent = brace_node.parent()?;
     let matching_kind = BRACES[brace_idx ^ 1];
-    let matching_node = parent
-        .children()
-        .find(|node| node.kind() == matching_kind)?;
+    let matching_node = parent.children().find(|node| node.kind() == matching_kind)?;
     Some(matching_node.range().start())
 }
 
@@ -122,10 +119,7 @@ pub fn highlight(root: &SyntaxNode) -> Vec<HighlightedRange> {
                 continue;
             }
         };
-        res.push(HighlightedRange {
-            range: node.range(),
-            tag,
-        })
+        res.push(HighlightedRange { range: node.range(), tag })
     }
     res
 }
diff --git a/crates/ra_ide_api_light/src/line_index.rs b/crates/ra_ide_api_light/src/line_index.rs
index 131737743..bf004c33a 100644
--- a/crates/ra_ide_api_light/src/line_index.rs
+++ b/crates/ra_ide_api_light/src/line_index.rs
@@ -54,10 +54,7 @@ impl LineIndex {
 
             let char_len = TextUnit::of_char(c);
             if char_len.to_usize() > 1 {
-                utf16_chars.push(Utf16Char {
-                    start: curr_col,
-                    end: curr_col + char_len,
-                });
+                utf16_chars.push(Utf16Char { start: curr_col, end: curr_col + char_len });
             }
 
             curr_col += char_len;
@@ -68,10 +65,7 @@ impl LineIndex {
             utf16_lines.insert(line, utf16_chars);
         }
 
-        LineIndex {
-            newlines,
-            utf16_lines,
-        }
+        LineIndex { newlines, utf16_lines }
     }
 
     pub fn line_col(&self, offset: TextUnit) -> LineCol {
@@ -79,10 +73,7 @@ impl LineIndex {
         let line_start_offset = self.newlines[line];
         let col = offset - line_start_offset;
 
-        LineCol {
-            line: line as u32,
-            col_utf16: self.utf8_to_utf16_col(line as u32, col) as u32,
-        }
+        LineCol { line: line as u32, col_utf16: self.utf8_to_utf16_col(line as u32, col) as u32 }
     }
 
     pub fn offset(&self, line_col: LineCol) -> TextUnit {
@@ -131,10 +122,7 @@ impl LineIndex {
 #[cfg(test)]
 /// Simple reference implementation to use in proptests
 pub fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
-    let mut res = LineCol {
-        line: 0,
-        col_utf16: 0,
-    };
+    let mut res = LineCol { line: 0, col_utf16: 0 };
     for (i, c) in text.char_indices() {
         if i + c.len_utf8() > offset.to_usize() {
             // if it's an invalid offset, inside a multibyte char
@@ -161,120 +149,31 @@ mod test_line_index {
     fn test_line_index() {
         let text = "hello\nworld";
         let index = LineIndex::new(text);
-        assert_eq!(
-            index.line_col(0.into()),
-            LineCol {
-                line: 0,
-                col_utf16: 0
-            }
-        );
-        assert_eq!(
-            index.line_col(1.into()),
-            LineCol {
-                line: 0,
-                col_utf16: 1
-            }
-        );
-        assert_eq!(
-            index.line_col(5.into()),
-            LineCol {
-                line: 0,
-                col_utf16: 5
-            }
-        );
-        assert_eq!(
-            index.line_col(6.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 0
-            }
-        );
-        assert_eq!(
-            index.line_col(7.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 1
-            }
-        );
-        assert_eq!(
-            index.line_col(8.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 2
-            }
-        );
-        assert_eq!(
-            index.line_col(10.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 4
-            }
-        );
-        assert_eq!(
-            index.line_col(11.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 5
-            }
-        );
-        assert_eq!(
-            index.line_col(12.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 6
-            }
-        );
+        assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 });
+        assert_eq!(index.line_col(1.into()), LineCol { line: 0, col_utf16: 1 });
+        assert_eq!(index.line_col(5.into()), LineCol { line: 0, col_utf16: 5 });
+        assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 0 });
+        assert_eq!(index.line_col(7.into()), LineCol { line: 1, col_utf16: 1 });
+        assert_eq!(index.line_col(8.into()), LineCol { line: 1, col_utf16: 2 });
+        assert_eq!(index.line_col(10.into()), LineCol { line: 1, col_utf16: 4 });
+        assert_eq!(index.line_col(11.into()), LineCol { line: 1, col_utf16: 5 });
+        assert_eq!(index.line_col(12.into()), LineCol { line: 1, col_utf16: 6 });
 
         let text = "\nhello\nworld";
         let index = LineIndex::new(text);
-        assert_eq!(
-            index.line_col(0.into()),
-            LineCol {
-                line: 0,
-                col_utf16: 0
-            }
-        );
-        assert_eq!(
-            index.line_col(1.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 0
-            }
-        );
-        assert_eq!(
-            index.line_col(2.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 1
-            }
-        );
-        assert_eq!(
-            index.line_col(6.into()),
-            LineCol {
-                line: 1,
-                col_utf16: 5
-            }
-        );
-        assert_eq!(
-            index.line_col(7.into()),
-            LineCol {
-                line: 2,
-                col_utf16: 0
-            }
-        );
+        assert_eq!(index.line_col(0.into()), LineCol { line: 0, col_utf16: 0 });
+        assert_eq!(index.line_col(1.into()), LineCol { line: 1, col_utf16: 0 });
+        assert_eq!(index.line_col(2.into()), LineCol { line: 1, col_utf16: 1 });
+        assert_eq!(index.line_col(6.into()), LineCol { line: 1, col_utf16: 5 });
+        assert_eq!(index.line_col(7.into()), LineCol { line: 2, col_utf16: 0 });
     }
 
     fn arb_text_with_offset() -> BoxedStrategy<(TextUnit, String)> {
-        arb_text()
-            .prop_flat_map(|text| (arb_offset(&text), Just(text)))
-            .boxed()
+        arb_text().prop_flat_map(|text| (arb_offset(&text), Just(text))).boxed()
     }
 
     fn to_line_col(text: &str, offset: TextUnit) -> LineCol {
-        let mut res = LineCol {
-            line: 0,
-            col_utf16: 0,
-        };
+        let mut res = LineCol { line: 0, col_utf16: 0 };
         for (i, c) in text.char_indices() {
             if i + c.len_utf8() > offset.to_usize() {
                 // if it's an invalid offset, inside a multibyte char
@@ -333,13 +232,7 @@ const C: char = 'メ';
 
         assert_eq!(col_index.utf16_lines.len(), 1);
         assert_eq!(col_index.utf16_lines[&1].len(), 1);
-        assert_eq!(
-            col_index.utf16_lines[&1][0],
-            Utf16Char {
-                start: 17.into(),
-                end: 20.into()
-            }
-        );
+        assert_eq!(col_index.utf16_lines[&1][0], Utf16Char { start: 17.into(), end: 20.into() });
 
         // UTF-8 to UTF-16, no changes
         assert_eq!(col_index.utf8_to_utf16_col(1, 15.into()), 15);
@@ -364,20 +257,8 @@ const C: char = \"メ メ\";
 
         assert_eq!(col_index.utf16_lines.len(), 1);
         assert_eq!(col_index.utf16_lines[&1].len(), 2);
-        assert_eq!(
-            col_index.utf16_lines[&1][0],
-            Utf16Char {
-                start: 17.into(),
-                end: 20.into()
-            }
-        );
-        assert_eq!(
-            col_index.utf16_lines[&1][1],
-            Utf16Char {
-                start: 21.into(),
-                end: 24.into()
-            }
-        );
+        assert_eq!(col_index.utf16_lines[&1][0], Utf16Char { start: 17.into(), end: 20.into() });
+        assert_eq!(col_index.utf16_lines[&1][1], Utf16Char { start: 21.into(), end: 24.into() });
 
         // UTF-8 to UTF-16
         assert_eq!(col_index.utf8_to_utf16_col(1, 15.into()), 15);
diff --git a/crates/ra_ide_api_light/src/line_index_utils.rs b/crates/ra_ide_api_light/src/line_index_utils.rs
index 5d9ab6fd2..799a920ad 100644
--- a/crates/ra_ide_api_light/src/line_index_utils.rs
+++ b/crates/ra_ide_api_light/src/line_index_utils.rs
@@ -17,11 +17,7 @@ struct LineIndexStepIter<'a> {
 
 impl<'a> LineIndexStepIter<'a> {
     fn from(line_index: &LineIndex) -> LineIndexStepIter {
-        let mut x = LineIndexStepIter {
-            line_index,
-            next_newline_idx: 0,
-            utf16_chars: None,
-        };
+        let mut x = LineIndexStepIter { line_index, next_newline_idx: 0, utf16_chars: None };
         // skip first newline since it's not real
         x.next();
         x
@@ -35,10 +31,7 @@ impl<'a> Iterator for LineIndexStepIter<'a> {
             .as_mut()
             .and_then(|(newline, x)| {
                 let x = x.next()?;
-                Some(Step::Utf16Char(TextRange::from_to(
-                    *newline + x.start,
-                    *newline + x.end,
-                )))
+                Some(Step::Utf16Char(TextRange::from_to(*newline + x.start, *newline + x.end)))
             })
             .or_else(|| {
                 let next_newline = *self.line_index.newlines.get(self.next_newline_idx)?;
@@ -113,11 +106,7 @@ struct Edits<'a> {
 
 impl<'a> Edits<'a> {
     fn from_text_edit(text_edit: &'a TextEdit) -> Edits<'a> {
-        let mut x = Edits {
-            edits: text_edit.as_atoms(),
-            current: None,
-            acc_diff: 0,
-        };
+        let mut x = Edits { edits: text_edit.as_atoms(), current: None, acc_diff: 0 };
         x.advance_edit();
         x
     }
@@ -127,11 +116,7 @@ impl<'a> Edits<'a> {
             Some((next, rest)) => {
                 let delete = self.translate_range(next.delete);
                 let diff = next.insert.len() as i64 - next.delete.len().to_usize() as i64;
-                self.current = Some(TranslatedEdit {
-                    delete,
-                    insert: &next.insert,
-                    diff,
-                });
+                self.current = Some(TranslatedEdit { delete, insert: &next.insert, diff });
                 self.edits = rest;
             }
             None => {
@@ -142,10 +127,7 @@ impl<'a> Edits<'a> {
 
     fn next_inserted_steps(&mut self) -> Option<OffsetStepIter<'a>> {
         let cur = self.current.as_ref()?;
-        let res = Some(OffsetStepIter {
-            offset: cur.delete.start(),
-            text: &cur.insert,
-        });
+        let res = Some(OffsetStepIter { offset: cur.delete.start(), text: &cur.insert });
         self.advance_edit();
         res
     }
@@ -160,18 +142,12 @@ impl<'a> Edits<'a> {
                 if step_pos <= edit.delete.start() {
                     NextSteps::Use
                 } else if step_pos <= edit.delete.end() {
-                    let iter = OffsetStepIter {
-                        offset: edit.delete.start(),
-                        text: &edit.insert,
-                    };
+                    let iter = OffsetStepIter { offset: edit.delete.start(), text: &edit.insert };
                     // empty slice to avoid returning steps again
                     edit.insert = &edit.insert[edit.insert.len()..];
                     NextSteps::ReplaceMany(iter)
                 } else {
-                    let iter = OffsetStepIter {
-                        offset: edit.delete.start(),
-                        text: &edit.insert,
-                    };
+                    let iter = OffsetStepIter { offset: edit.delete.start(), text: &edit.insert };
                     // empty slice to avoid returning steps again
                     edit.insert = &edit.insert[edit.insert.len()..];
                     self.advance_edit();
@@ -222,11 +198,7 @@ struct RunningLineCol {
 
 impl RunningLineCol {
     fn new() -> RunningLineCol {
-        RunningLineCol {
-            line: 0,
-            last_newline: TextUnit::from(0),
-            col_adjust: TextUnit::from(0),
-        }
+        RunningLineCol { line: 0, last_newline: TextUnit::from(0), col_adjust: TextUnit::from(0) }
     }
 
     fn to_line_col(&self, offset: TextUnit) -> LineCol {
@@ -339,12 +311,7 @@ mod test {
                 let edited_text = x.edit.apply(&x.text);
                 let arb_offset = arb_offset(&edited_text);
                 (Just(x), Just(edited_text), arb_offset).prop_map(|(x, edited_text, offset)| {
-                    ArbTextWithEditAndOffset {
-                        text: x.text,
-                        edit: x.edit,
-                        edited_text,
-                        offset,
-                    }
+                    ArbTextWithEditAndOffset { text: x.text, edit: x.edit, edited_text, offset }
                 })
             })
             .boxed()
diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs
index 330a3694c..75afd1181 100644
--- a/crates/ra_ide_api_light/src/structure.rs
+++ b/crates/ra_ide_api_light/src/structure.rs
@@ -70,10 +70,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
             node_range: node.syntax().range(),
             kind: node.syntax().kind(),
             detail,
-            deprecated: node
-                .attrs()
-                .filter_map(|x| x.as_named())
-                .any(|x| x == "deprecated"),
+            deprecated: node.attrs().filter_map(|x| x.as_named()).any(|x| x == "deprecated"),
         })
     }
 
@@ -123,11 +120,9 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
             let target_trait = im.target_trait();
             let label = match target_trait {
                 None => format!("impl {}", target_type.syntax().text()),
-                Some(t) => format!(
-                    "impl {} for {}",
-                    t.syntax().text(),
-                    target_type.syntax().text(),
-                ),
+                Some(t) => {
+                    format!("impl {} for {}", t.syntax().text(), target_type.syntax().text(),)
+                }
             };
 
             let node = StructureNode {
diff --git a/crates/ra_ide_api_light/src/typing.rs b/crates/ra_ide_api_light/src/typing.rs
index 861027b9f..a08a5a8c5 100644
--- a/crates/ra_ide_api_light/src/typing.rs
+++ b/crates/ra_ide_api_light/src/typing.rs
@@ -8,9 +8,8 @@ use ra_syntax::{
 use crate::{LocalEdit, TextEditBuilder, formatting::leading_indent};
 
 pub fn on_enter(file: &SourceFile, offset: TextUnit) -> Option<LocalEdit> {
-    let comment = find_leaf_at_offset(file.syntax(), offset)
-        .left_biased()
-        .and_then(ast::Comment::cast)?;
+    let comment =
+        find_leaf_at_offset(file.syntax(), offset).left_biased().and_then(ast::Comment::cast)?;
 
     if let ast::CommentFlavor::Multiline = comment.flavor() {
         return None;
@@ -64,12 +63,7 @@ pub fn on_eq_typed(file: &SourceFile, eq_offset: TextUnit) -> Option<LocalEdit>
         if expr_range.contains(eq_offset) && eq_offset != expr_range.start() {
             return None;
         }
-        if file
-            .syntax()
-            .text()
-            .slice(eq_offset..expr_range.start())
-            .contains('\n')
-        {
+        if file.syntax().text().slice(eq_offset..expr_range.start()).contains('\n') {
             return None;
         }
     } else {
@@ -100,10 +94,7 @@ pub fn on_dot_typed(file: &SourceFile, dot_offset: TextUnit) -> Option<LocalEdit
     let current_indent_len = TextUnit::of_str(current_indent);
 
     // Make sure dot is a part of call chain
-    let field_expr = whitespace
-        .syntax()
-        .parent()
-        .and_then(ast::FieldExpr::cast)?;
+    let field_expr = whitespace.syntax().parent().and_then(ast::FieldExpr::cast)?;
     let prev_indent = leading_indent(field_expr.syntax())?;
     let target_indent = format!("    {}", prev_indent);
     let target_indent_len = TextUnit::of_str(&target_indent);
-- 
cgit v1.2.3