diff options
author | Alan Du <[email protected]> | 2018-10-16 16:51:58 +0100 |
---|---|---|
committer | Alan Du <[email protected]> | 2018-10-18 00:42:23 +0100 |
commit | d493a4476c2059924d032fbf01dda091601f9667 (patch) | |
tree | 74c1249cba67c8c9824e618fcdea53b97b571a7b /crates | |
parent | 5db663d61fb8b006e3b84ef3bcc9cddbe94e5f49 (diff) |
clippy: Use if lets and remove redundant returns
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 4 | ||||
-rw-r--r-- | crates/ra_editor/src/line_index.rs | 4 | ||||
-rw-r--r-- | crates/ra_editor/src/symbols.rs | 6 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/algo/mod.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/mod.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/expressions/atom.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/items/mod.rs | 6 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/patterns.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/src/utils.rs | 2 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 5 |
11 files changed, 22 insertions, 29 deletions
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<Fold> { | |||
38 | continue; | 38 | continue; |
39 | } | 39 | } |
40 | if node.kind() == COMMENT { | 40 | if node.kind() == COMMENT { |
41 | contiguous_range_for_comment(node, &mut visited_comments).map(|range| { | 41 | if let Some(range) = contiguous_range_for_comment(node, &mut visited_comments) { |
42 | res.push(Fold { | 42 | res.push(Fold { |
43 | range, | 43 | range, |
44 | kind: FoldKind::Comment, | 44 | kind: FoldKind::Comment, |
45 | }) | 45 | }) |
46 | }); | 46 | } |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
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 { | |||
29 | let line = self.newlines.upper_bound(&offset) - 1; | 29 | let line = self.newlines.upper_bound(&offset) - 1; |
30 | let line_start_offset = self.newlines[line]; | 30 | let line_start_offset = self.newlines[line]; |
31 | let col = offset - line_start_offset; | 31 | let col = offset - line_start_offset; |
32 | return LineCol { | 32 | LineCol { |
33 | line: line as u32, | 33 | line: line as u32, |
34 | col, | 34 | col, |
35 | }; | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | pub fn offset(&self, line_col: LineCol) -> TextUnit { | 38 | 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<StructureNode> { | |||
54 | let mut res = Vec::new(); | 54 | let mut res = Vec::new(); |
55 | let mut stack = Vec::new(); | 55 | let mut stack = Vec::new(); |
56 | 56 | ||
57 | |||
57 | for event in file.syntax().preorder() { | 58 | for event in file.syntax().preorder() { |
58 | match event { | 59 | match event { |
59 | WalkEvent::Enter(node) => match structure_node(node) { | 60 | WalkEvent::Enter(node) => { |
60 | Some(mut symbol) => { | 61 | if let Some(mut symbol) = structure_node(node) { |
61 | symbol.parent = stack.last().map(|&n| n); | 62 | symbol.parent = stack.last().map(|&n| n); |
62 | stack.push(res.len()); | 63 | stack.push(res.len()); |
63 | res.push(symbol); | 64 | res.push(symbol); |
64 | } | 65 | } |
65 | None => (), | ||
66 | }, | 66 | }, |
67 | WalkEvent::Leave(node) => { | 67 | WalkEvent::Leave(node) => { |
68 | if structure_node(node).is_some() { | 68 | 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 { | |||
73 | events | 73 | events |
74 | .into_iter() | 74 | .into_iter() |
75 | .map(|event| { | 75 | .map(|event| { |
76 | let text = match event.kind { | 76 | let FileEventKind::Add(text) = event.kind; |
77 | FileEventKind::Add(text) => text, | ||
78 | }; | ||
79 | (event.path, text) | 77 | (event.path, text) |
80 | }) | 78 | }) |
81 | .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text)) | 79 | .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 | |||
30 | let left = children.next().unwrap(); | 30 | let left = children.next().unwrap(); |
31 | let right = children.next(); | 31 | let right = children.next(); |
32 | assert!(children.next().is_none()); | 32 | assert!(children.next().is_none()); |
33 | return if let Some(right) = right { | 33 | |
34 | if let Some(right) = right { | ||
34 | match ( | 35 | match ( |
35 | find_leaf_at_offset(left, offset), | 36 | find_leaf_at_offset(left, offset), |
36 | find_leaf_at_offset(right, offset), | 37 | find_leaf_at_offset(right, offset), |
@@ -42,7 +43,7 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse | |||
42 | } | 43 | } |
43 | } else { | 44 | } else { |
44 | find_leaf_at_offset(left, offset) | 45 | find_leaf_at_offset(left, offset) |
45 | }; | 46 | } |
46 | } | 47 | } |
47 | 48 | ||
48 | #[derive(Clone, Copy, Debug)] | 49 | #[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> { | |||
259 | type Item = N; | 259 | type Item = N; |
260 | fn next(&mut self) -> Option<N> { | 260 | fn next(&mut self) -> Option<N> { |
261 | loop { | 261 | loop { |
262 | match N::cast(self.inner.next()?) { | 262 | if let Some(n) = N::cast(self.inner.next()?) { |
263 | Some(n) => return Some(n), | 263 | return Some(n); |
264 | None => (), | ||
265 | } | 264 | } |
266 | } | 265 | } |
267 | } | 266 | } |
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![ | |||
62 | const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; | 62 | const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW]; |
63 | 63 | ||
64 | pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { | 64 | pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { |
65 | match literal(p) { | 65 | if let Some(m) = literal(p) { |
66 | Some(m) => return Some(m), | 66 | return Some(m); |
67 | None => (), | ||
68 | } | 67 | } |
69 | if paths::is_path_start(p) || p.at(L_ANGLE) { | 68 | if paths::is_path_start(p) || p.at(L_ANGLE) { |
70 | return Some(path_expr(p, r)); | 69 | 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 { | |||
352 | pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { | 352 | pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { |
353 | p.expect(EXCL); | 353 | p.expect(EXCL); |
354 | p.eat(IDENT); | 354 | p.eat(IDENT); |
355 | let flavor = match p.current() { | 355 | match p.current() { |
356 | L_CURLY => { | 356 | L_CURLY => { |
357 | token_tree(p); | 357 | token_tree(p); |
358 | BlockLike::Block | 358 | BlockLike::Block |
@@ -365,9 +365,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike { | |||
365 | p.error("expected `{`, `[`, `(`"); | 365 | p.error("expected `{`, `[`, `(`"); |
366 | BlockLike::NotBlock | 366 | BlockLike::NotBlock |
367 | } | 367 | } |
368 | }; | 368 | } |
369 | |||
370 | flavor | ||
371 | } | 369 | } |
372 | 370 | ||
373 | pub(crate) fn token_tree(p: &mut Parser) { | 371 | 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<CompletedMarker> { | |||
49 | // "hello" => (), | 49 | // "hello" => (), |
50 | // } | 50 | // } |
51 | // } | 51 | // } |
52 | match expressions::literal(p) { | 52 | if let Some(m) = expressions::literal(p) { |
53 | Some(m) => return Some(m), | 53 | return Some(m); |
54 | None => (), | ||
55 | } | 54 | } |
56 | 55 | ||
57 | let m = match la0 { | 56 | 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 { | |||
42 | writeln!(buf, "err: `{}`", err.msg).unwrap(); | 42 | writeln!(buf, "err: `{}`", err.msg).unwrap(); |
43 | } | 43 | } |
44 | 44 | ||
45 | return buf; | 45 | buf |
46 | } | 46 | } |
47 | 47 | ||
48 | pub fn check_fuzz_invariants(text: &str) { | 48 | 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<HashMap<String, (PathBuf, Test)>> { | |||
112 | name: name.clone(), | 112 | name: name.clone(), |
113 | text, | 113 | text, |
114 | }; | 114 | }; |
115 | match res.insert(name, (path, test)) { | 115 | if let Some(old) = res.insert(name, (path, test)) { |
116 | Some(old) => println!("Duplicate test: {:?}", old), | 116 | println!("Duplicate test: {:?}", old); |
117 | None => (), | ||
118 | } | 117 | } |
119 | } | 118 | } |
120 | Ok(res) | 119 | Ok(res) |