From d493a4476c2059924d032fbf01dda091601f9667 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 11:51:58 -0400 Subject: clippy: Use if lets and remove redundant returns --- crates/ra_editor/src/folding_ranges.rs | 4 ++-- crates/ra_editor/src/line_index.rs | 4 ++-- crates/ra_editor/src/symbols.rs | 6 +++--- crates/ra_lsp_server/src/server_world.rs | 4 +--- crates/ra_syntax/src/algo/mod.rs | 5 +++-- crates/ra_syntax/src/ast/mod.rs | 5 ++--- crates/ra_syntax/src/grammar/expressions/atom.rs | 5 ++--- crates/ra_syntax/src/grammar/items/mod.rs | 6 ++---- crates/ra_syntax/src/grammar/patterns.rs | 5 ++--- crates/ra_syntax/src/utils.rs | 2 +- crates/tools/src/main.rs | 5 ++--- 11 files changed, 22 insertions(+), 29 deletions(-) (limited to 'crates') diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index e5bc0c4ee..d0d4ed3d3 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs @@ -38,12 +38,12 @@ pub fn folding_ranges(file: &File) -> Vec { 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, }) - }); + } } } diff --git a/crates/ra_editor/src/line_index.rs b/crates/ra_editor/src/line_index.rs index da0f2a7f7..9abbb0d09 100644 --- a/crates/ra_editor/src/line_index.rs +++ b/crates/ra_editor/src/line_index.rs @@ -29,10 +29,10 @@ impl LineIndex { 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 { diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs index c3c66680d..0bab9dd67 100644 --- a/crates/ra_editor/src/symbols.rs +++ b/crates/ra_editor/src/symbols.rs @@ -54,15 +54,15 @@ pub fn file_structure(file: &File) -> Vec { 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() { diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 35ff65ea1..69b2a1cd1 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -73,9 +73,7 @@ impl ServerWorldState { 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)) diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index 9d2014bc7..87f1250bc 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -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)] diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index 34958b6cb..900426a8a 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs @@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { type Item = N; fn next(&mut self) -> Option { 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); } } } diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index 11f766d33..04087fd60 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs @@ -62,9 +62,8 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option { - 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)); diff --git a/crates/ra_syntax/src/grammar/items/mod.rs b/crates/ra_syntax/src/grammar/items/mod.rs index dc4742bce..06c6b5e6e 100644 --- a/crates/ra_syntax/src/grammar/items/mod.rs +++ b/crates/ra_syntax/src/grammar/items/mod.rs @@ -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) { diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 9d35dbb3d..10fa0e0be 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { // "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 { diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 7d0ef2fa2..ca4160378 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs @@ -42,7 +42,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { writeln!(buf, "err: `{}`", err.msg).unwrap(); } - return buf; + buf } pub fn check_fuzz_invariants(text: &str) { diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 152298014..fdb443690 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs @@ -112,9 +112,8 @@ fn existing_tests(dir: &Path) -> Result> { 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) -- cgit v1.2.3