]> git.lizzy.rs Git - rust.git/commitdiff
clippy: Use if lets and remove redundant returns
authorAlan Du <alanhdu@gmail.com>
Tue, 16 Oct 2018 15:51:58 +0000 (11:51 -0400)
committerAlan Du <alanhdu@gmail.com>
Wed, 17 Oct 2018 23:42:23 +0000 (19:42 -0400)
crates/ra_editor/src/folding_ranges.rs
crates/ra_editor/src/line_index.rs
crates/ra_editor/src/symbols.rs
crates/ra_lsp_server/src/server_world.rs
crates/ra_syntax/src/algo/mod.rs
crates/ra_syntax/src/ast/mod.rs
crates/ra_syntax/src/grammar/expressions/atom.rs
crates/ra_syntax/src/grammar/items/mod.rs
crates/ra_syntax/src/grammar/patterns.rs
crates/ra_syntax/src/utils.rs
crates/tools/src/main.rs

index e5bc0c4ee5cfbc1848aed653336eea24261d9cb7..d0d4ed3d3db0a83fd6300ec23b38044b277983d5 100644 (file)
@@ -38,12 +38,12 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> {
             continue;
         }
         if node.kind() == COMMENT {
-            contiguous_range_for_comment(node, &mut visited_comments).map(|range| {
+            if let Some(range) = contiguous_range_for_comment(node, &mut visited_comments) {
                 res.push(Fold {
                     range,
                     kind: FoldKind::Comment,
                 })
-            });
+            }
         }
     }
 
index da0f2a7f7944816b0bf8f6a8481605e350723007..9abbb0d0955185edf22a6f1559559dbfffd071e6 100644 (file)
@@ -29,10 +29,10 @@ pub fn line_col(&self, offset: TextUnit) -> LineCol {
         let line = self.newlines.upper_bound(&offset) - 1;
         let line_start_offset = self.newlines[line];
         let col = offset - line_start_offset;
-        return LineCol {
+        LineCol {
             line: line as u32,
             col,
-        };
+        }
     }
 
     pub fn offset(&self, line_col: LineCol) -> TextUnit {
index c3c66680d58f64f90b6f7549966bd52114d3d00c..0bab9dd6725e5c831f9075db77f547968c8bc0d6 100644 (file)
@@ -54,15 +54,15 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
     let mut res = Vec::new();
     let mut stack = Vec::new();
 
+
     for event in file.syntax().preorder() {
         match event {
-            WalkEvent::Enter(node) => match structure_node(node) {
-                Some(mut symbol) => {
+            WalkEvent::Enter(node) => {
+                if let Some(mut symbol) = structure_node(node) {
                     symbol.parent = stack.last().map(|&n| n);
                     stack.push(res.len());
                     res.push(symbol);
                 }
-                None => (),
             },
             WalkEvent::Leave(node) => {
                 if structure_node(node).is_some() {
index 35ff65ea1610d126e15a84051ff0135a9f15339a..69b2a1cd1597a0f17ac3835b66a73cc7c777bc59 100644 (file)
@@ -73,9 +73,7 @@ pub fn events_to_files(
             events
                 .into_iter()
                 .map(|event| {
-                    let text = match event.kind {
-                        FileEventKind::Add(text) => text,
-                    };
+                    let FileEventKind::Add(text) = event.kind;
                     (event.path, text)
                 })
                 .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text))
index 9d2014bc7c406111fed438fc2d8e9178b1db55fa..87f1250bcf137b6a01e9abcb7ce62929f1a04f30 100644 (file)
@@ -30,7 +30,8 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
     let left = children.next().unwrap();
     let right = children.next();
     assert!(children.next().is_none());
-    return if let Some(right) = right {
+
+    if let Some(right) = right {
         match (
             find_leaf_at_offset(left, offset),
             find_leaf_at_offset(right, offset),
@@ -42,7 +43,7 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
         }
     } else {
         find_leaf_at_offset(left, offset)
-    };
+    }
 }
 
 #[derive(Clone, Copy, Debug)]
index 34958b6cb3b6b771bcb91c29a670c7126d1619fe..900426a8a91a9a9fe8e1acc27e2f6eb70505230e 100644 (file)
@@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
     type Item = N;
     fn next(&mut self) -> Option<N> {
         loop {
-            match N::cast(self.inner.next()?) {
-                Some(n) => return Some(n),
-                None => (),
+            if let Some(n) = N::cast(self.inner.next()?) {
+                return Some(n);
             }
         }
     }
index 11f766d3356de04ca5daa96a8bbdcd5245bd29b3..04087fd6004b9d61212e920f8c1ca71048fd6e4e 100644 (file)
@@ -62,9 +62,8 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
 const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
 
 pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
-    match literal(p) {
-        Some(m) => return Some(m),
-        None => (),
+    if let Some(m) = literal(p) {
+        return Some(m);
     }
     if paths::is_path_start(p) || p.at(L_ANGLE) {
         return Some(path_expr(p, r));
index dc4742bce95604b470a12341fb58f2c49322365e..06c6b5e6ebf01abaa7ea34250eceaddf5d4f993e 100644 (file)
@@ -352,7 +352,7 @@ fn macro_call(p: &mut Parser) -> BlockLike {
 pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
     p.expect(EXCL);
     p.eat(IDENT);
-    let flavor = match p.current() {
+    match p.current() {
         L_CURLY => {
             token_tree(p);
             BlockLike::Block
@@ -365,9 +365,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
             p.error("expected `{`, `[`, `(`");
             BlockLike::NotBlock
         }
-    };
-
-    flavor
+    }
 }
 
 pub(crate) fn token_tree(p: &mut Parser) {
index 9d35dbb3d8da42d470cb4dc6c30c070c96d9705d..10fa0e0be14bd1b6205f4555b4f650f5773adc7f 100644 (file)
@@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
     //         "hello" => (),
     //     }
     // }
-    match expressions::literal(p) {
-        Some(m) => return Some(m),
-        None => (),
+    if let Some(m) = expressions::literal(p) {
+        return Some(m);
     }
 
     let m = match la0 {
index 7d0ef2fa2730718ec5d6885ed99747e11f9f3b77..ca4160378288f337606c3cfcc383cefaf5094863 100644 (file)
@@ -42,7 +42,7 @@ macro_rules! indent {
         writeln!(buf, "err: `{}`", err.msg).unwrap();
     }
 
-    return buf;
+    buf
 }
 
 pub fn check_fuzz_invariants(text: &str) {
index 152298014e61f1c666a3810f1ed12cbc46f369bd..fdb443690bd97b03ff3077ee83833f9958a598e5 100644 (file)
@@ -112,9 +112,8 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> {
             name: name.clone(),
             text,
         };
-        match res.insert(name, (path, test)) {
-            Some(old) => println!("Duplicate test: {:?}", old),
-            None => (),
+        if let Some(old) = res.insert(name, (path, test)) {
+            println!("Duplicate test: {:?}", old);
         }
     }
     Ok(res)