diff options
author | kjeremy <[email protected]> | 2019-10-30 17:36:37 +0000 |
---|---|---|
committer | kjeremy <[email protected]> | 2019-10-30 17:36:37 +0000 |
commit | b441b4e8effeaf4532fd2e45c4d864480857c49e (patch) | |
tree | 5f25f7478b8ec365b2a2d5f7bea4ec2386bdd244 | |
parent | 5806195bc1cdb1ca3fa257e99fd6e0dd897713a9 (diff) |
Some clippy fixes
-rw-r--r-- | crates/ra_assists/src/assists/early_return.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/inline_local_variable.rs | 6 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/raw_string.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/call_info.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/change.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/search_scope.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_api/src/typing.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 2 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/matcher.rs | 3 | ||||
-rw-r--r-- | crates/ra_mbe/src/syntax_bridge.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 4 | ||||
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 2 | ||||
-rw-r--r-- | xtask/src/codegen/gen_parser_tests.rs | 8 | ||||
-rw-r--r-- | xtask/src/main.rs | 2 | ||||
-rw-r--r-- | xtask/tests/tidy-tests/docs.rs | 2 |
17 files changed, 23 insertions, 29 deletions
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs index e839d831e..ad6c5695a 100644 --- a/crates/ra_assists/src/assists/early_return.rs +++ b/crates/ra_assists/src/assists/early_return.rs | |||
@@ -50,7 +50,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt | |||
50 | } | 50 | } |
51 | 51 | ||
52 | // check for early return and continue | 52 | // check for early return and continue |
53 | let first_in_then_block = then_block.syntax().first_child()?.clone(); | 53 | let first_in_then_block = then_block.syntax().first_child()?; |
54 | if ast::ReturnExpr::can_cast(first_in_then_block.kind()) | 54 | if ast::ReturnExpr::can_cast(first_in_then_block.kind()) |
55 | || ast::ContinueExpr::can_cast(first_in_then_block.kind()) | 55 | || ast::ContinueExpr::can_cast(first_in_then_block.kind()) |
56 | || first_in_then_block | 56 | || first_in_then_block |
diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index f43910574..a7fd9b6d2 100644 --- a/crates/ra_assists/src/assists/inline_local_variable.rs +++ b/crates/ra_assists/src/assists/inline_local_variable.rs | |||
@@ -51,10 +51,8 @@ pub(crate) fn inline_local_varialbe(ctx: AssistCtx<impl HirDatabase>) -> Option< | |||
51 | let mut wrap_in_parens = vec![true; refs.len()]; | 51 | let mut wrap_in_parens = vec![true; refs.len()]; |
52 | 52 | ||
53 | for (i, desc) in refs.iter().enumerate() { | 53 | for (i, desc) in refs.iter().enumerate() { |
54 | let usage_node = ctx | 54 | let usage_node = |
55 | .covering_node_for_range(desc.range) | 55 | ctx.covering_node_for_range(desc.range).ancestors().find_map(ast::PathExpr::cast)?; |
56 | .ancestors() | ||
57 | .find_map(|node| ast::PathExpr::cast(node))?; | ||
58 | let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast); | 56 | let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast); |
59 | let usage_parent = match usage_parent_option { | 57 | let usage_parent = match usage_parent_option { |
60 | Some(u) => u, | 58 | Some(u) => u, |
diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs index 6f4b66c31..58f7157ae 100644 --- a/crates/ra_assists/src/assists/raw_string.rs +++ b/crates/ra_assists/src/assists/raw_string.rs | |||
@@ -131,7 +131,7 @@ pub(crate) fn remove_hash(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
131 | ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| { | 131 | ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| { |
132 | edit.target(token.text_range()); | 132 | edit.target(token.text_range()); |
133 | let result = &text[2..text.len() - 1]; | 133 | let result = &text[2..text.len() - 1]; |
134 | let result = if result.starts_with("\"") { | 134 | let result = if result.starts_with('\"') { |
135 | // no more hash, escape | 135 | // no more hash, escape |
136 | let internal_str = &result[1..result.len() - 1]; | 136 | let internal_str = &result[1..result.len() - 1]; |
137 | format!("\"{}\"", internal_str.escape_default().to_string()) | 137 | format!("\"{}\"", internal_str.escape_default().to_string()) |
diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 175af3fd9..e494f5620 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs | |||
@@ -95,7 +95,7 @@ impl FnCallNode { | |||
95 | Some(FnCallNode::CallExpr(expr)) | 95 | Some(FnCallNode::CallExpr(expr)) |
96 | } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { | 96 | } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { |
97 | Some(FnCallNode::MethodCallExpr(expr)) | 97 | Some(FnCallNode::MethodCallExpr(expr)) |
98 | } else if let Some(expr) = ast::MacroCall::cast(node.clone()) { | 98 | } else if let Some(expr) = ast::MacroCall::cast(node) { |
99 | Some(FnCallNode::MacroCallExpr(expr)) | 99 | Some(FnCallNode::MacroCallExpr(expr)) |
100 | } else { | 100 | } else { |
101 | None | 101 | None |
diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 050249c0e..39c5946c7 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs | |||
@@ -43,7 +43,7 @@ impl fmt::Debug for AnalysisChange { | |||
43 | if !self.libraries_added.is_empty() { | 43 | if !self.libraries_added.is_empty() { |
44 | d.field("libraries_added", &self.libraries_added.len()); | 44 | d.field("libraries_added", &self.libraries_added.len()); |
45 | } | 45 | } |
46 | if !self.crate_graph.is_some() { | 46 | if !self.crate_graph.is_none() { |
47 | d.field("crate_graph", &self.crate_graph); | 47 | d.field("crate_graph", &self.crate_graph); |
48 | } | 48 | } |
49 | d.finish() | 49 | d.finish() |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 956d8ce49..a58fdc036 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -67,7 +67,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
67 | }); | 67 | }); |
68 | } | 68 | } |
69 | } | 69 | } |
70 | _ => return, | 70 | _ => {} |
71 | }; | 71 | }; |
72 | } | 72 | } |
73 | 73 | ||
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index f7e98e6df..65bb639ed 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -136,7 +136,7 @@ impl Completions { | |||
136 | for (idx, s) in docs.match_indices(¯o_name) { | 136 | for (idx, s) in docs.match_indices(¯o_name) { |
137 | let (before, after) = (&docs[..idx], &docs[idx + s.len()..]); | 137 | let (before, after) = (&docs[..idx], &docs[idx + s.len()..]); |
138 | // Ensure to match the full word | 138 | // Ensure to match the full word |
139 | if after.starts_with("!") | 139 | if after.starts_with('!') |
140 | && before | 140 | && before |
141 | .chars() | 141 | .chars() |
142 | .rev() | 142 | .rev() |
@@ -225,7 +225,7 @@ impl Completions { | |||
225 | } else { | 225 | } else { |
226 | (format!("{}($0)", data.name()), format!("{}(…)", name)) | 226 | (format!("{}($0)", data.name()), format!("{}(…)", name)) |
227 | }; | 227 | }; |
228 | builder = builder.lookup_by(name.clone()).label(label).insert_snippet(snippet); | 228 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); |
229 | } | 229 | } |
230 | 230 | ||
231 | self.add(builder) | 231 | self.add(builder) |
diff --git a/crates/ra_ide_api/src/references/search_scope.rs b/crates/ra_ide_api/src/references/search_scope.rs index dbd1af597..f2789e0b2 100644 --- a/crates/ra_ide_api/src/references/search_scope.rs +++ b/crates/ra_ide_api/src/references/search_scope.rs | |||
@@ -111,8 +111,7 @@ impl NameDefinition { | |||
111 | if vis.as_str() != "" { | 111 | if vis.as_str() != "" { |
112 | let source_root_id = db.file_source_root(file_id); | 112 | let source_root_id = db.file_source_root(file_id); |
113 | let source_root = db.source_root(source_root_id); | 113 | let source_root = db.source_root(source_root_id); |
114 | let mut res = | 114 | let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>(); |
115 | source_root.walk().map(|id| (id.into(), None)).collect::<FxHashMap<_, _>>(); | ||
116 | 115 | ||
117 | // FIXME: add "pub(in path)" | 116 | // FIXME: add "pub(in path)" |
118 | 117 | ||
@@ -128,7 +127,7 @@ impl NameDefinition { | |||
128 | let root_file = crate_graph.crate_root(crate_id); | 127 | let root_file = crate_graph.crate_root(crate_id); |
129 | let source_root_id = db.file_source_root(root_file); | 128 | let source_root_id = db.file_source_root(root_file); |
130 | let source_root = db.source_root(source_root_id); | 129 | let source_root = db.source_root(source_root_id); |
131 | res.extend(source_root.walk().map(|id| (id.into(), None))); | 130 | res.extend(source_root.walk().map(|id| (id, None))); |
132 | } | 131 | } |
133 | } | 132 | } |
134 | return SearchScope::new(res); | 133 | return SearchScope::new(res); |
diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 2dfbe6944..d51132f73 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs | |||
@@ -261,7 +261,7 @@ impl S { | |||
261 | 261 | ||
262 | fn type_char(char_typed: char, before: &str, after: &str) { | 262 | fn type_char(char_typed: char, before: &str, after: &str) { |
263 | let (actual, file_change) = do_type_char(char_typed, before) | 263 | let (actual, file_change) = do_type_char(char_typed, before) |
264 | .expect(&format!("typing `{}` did nothing", char_typed)); | 264 | .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); |
265 | 265 | ||
266 | if after.contains("<|>") { | 266 | if after.contains("<|>") { |
267 | let (offset, after) = extract_offset(after); | 267 | let (offset, after) = extract_offset(after); |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 1a87706fe..379dab438 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -196,7 +196,7 @@ pub fn main_loop( | |||
196 | task_receiver.into_iter().for_each(|task| { | 196 | task_receiver.into_iter().for_each(|task| { |
197 | on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state) | 197 | on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state) |
198 | }); | 198 | }); |
199 | libdata_receiver.into_iter().for_each(|lib| drop(lib)); | 199 | libdata_receiver.into_iter().for_each(drop); |
200 | log::info!("...tasks have finished"); | 200 | log::info!("...tasks have finished"); |
201 | log::info!("joining threadpool..."); | 201 | log::info!("joining threadpool..."); |
202 | drop(pool); | 202 | drop(pool); |
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index 0548e8512..33b9d483d 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -123,7 +123,6 @@ fn match_subtree( | |||
123 | } | 123 | } |
124 | None => bindings.push_optional(name), | 124 | None => bindings.push_optional(name), |
125 | } | 125 | } |
126 | () | ||
127 | } | 126 | } |
128 | Op::Repeat { subtree, kind, separator } => { | 127 | Op::Repeat { subtree, kind, separator } => { |
129 | match_repeat(bindings, subtree, kind, separator, src)? | 128 | match_repeat(bindings, subtree, kind, separator, src)? |
@@ -159,7 +158,7 @@ impl<'a> TtIter<'a> { | |||
159 | pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> { | 158 | pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> { |
160 | let ident = self.expect_ident()?; | 159 | let ident = self.expect_ident()?; |
161 | // check if it start from "`" | 160 | // check if it start from "`" |
162 | if ident.text.chars().next() != Some('\'') { | 161 | if !ident.text.starts_with('\'') { |
163 | return Err(()); | 162 | return Err(()); |
164 | } | 163 | } |
165 | Ok(ident) | 164 | Ok(ident) |
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 1b543c84b..592fcf527 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs | |||
@@ -383,7 +383,7 @@ mod tests { | |||
383 | "#, | 383 | "#, |
384 | ); | 384 | ); |
385 | let expansion = expand(&rules, "literals!(foo);"); | 385 | let expansion = expand(&rules, "literals!(foo);"); |
386 | let tts = &[expansion.clone().into()]; | 386 | let tts = &[expansion.into()]; |
387 | let buffer = tt::buffer::TokenBuffer::new(tts); | 387 | let buffer = tt::buffer::TokenBuffer::new(tts); |
388 | let mut tt_src = SubtreeTokenSource::new(&buffer); | 388 | let mut tt_src = SubtreeTokenSource::new(&buffer); |
389 | let mut tokens = vec![]; | 389 | let mut tokens = vec![]; |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 76dad9155..3d5f18bfa 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -129,11 +129,11 @@ pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereCl | |||
129 | } | 129 | } |
130 | 130 | ||
131 | pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { | 131 | pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { |
132 | return ast_from_text(&format!( | 132 | ast_from_text(&format!( |
133 | "fn f() {{ if !{} {{\n {}\n}}\n}}", | 133 | "fn f() {{ if !{} {{\n {}\n}}\n}}", |
134 | condition.syntax().text(), | 134 | condition.syntax().text(), |
135 | statement | 135 | statement |
136 | )); | 136 | )) |
137 | } | 137 | } |
138 | 138 | ||
139 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 139 | fn ast_from_text<N: AstNode>(text: &str) -> N { |
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 0c4cf2152..05afda8f1 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs | |||
@@ -53,7 +53,7 @@ fn collect_assists() -> Result<Vec<Assist>> { | |||
53 | 53 | ||
54 | let doc = take_until(lines.by_ref(), "```").trim().to_string(); | 54 | let doc = take_until(lines.by_ref(), "```").trim().to_string(); |
55 | assert!( | 55 | assert!( |
56 | doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."), | 56 | doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'), |
57 | "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", | 57 | "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", |
58 | id, doc, | 58 | id, doc, |
59 | ); | 59 | ); |
diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index db1e59dac..d0f0f683b 100644 --- a/xtask/src/codegen/gen_parser_tests.rs +++ b/xtask/src/codegen/gen_parser_tests.rs | |||
@@ -102,12 +102,10 @@ fn tests_from_dir(dir: &Path) -> Result<Tests> { | |||
102 | for test in collect_tests(&text) { | 102 | for test in collect_tests(&text) { |
103 | if test.ok { | 103 | if test.ok { |
104 | if let Some(old_test) = res.ok.insert(test.name.clone(), test) { | 104 | if let Some(old_test) = res.ok.insert(test.name.clone(), test) { |
105 | Err(format!("Duplicate test: {}", old_test.name))? | 105 | return Err(format!("Duplicate test: {}", old_test.name).into()); |
106 | } | ||
107 | } else { | ||
108 | if let Some(old_test) = res.err.insert(test.name.clone(), test) { | ||
109 | Err(format!("Duplicate test: {}", old_test.name))? | ||
110 | } | 106 | } |
107 | } else if let Some(old_test) = res.err.insert(test.name.clone(), test) { | ||
108 | return Err(format!("Duplicate test: {}", old_test.name).into()); | ||
111 | } | 109 | } |
112 | } | 110 | } |
113 | Ok(()) | 111 | Ok(()) |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 04dca402c..4d20232ff 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -60,7 +60,7 @@ fn main() -> Result<()> { | |||
60 | matches.finish().or_else(handle_extra_flags)?; | 60 | matches.finish().or_else(handle_extra_flags)?; |
61 | let opts = InstallOpt { | 61 | let opts = InstallOpt { |
62 | client: if server { None } else { Some(ClientOpt::VsCode) }, | 62 | client: if server { None } else { Some(ClientOpt::VsCode) }, |
63 | server: if client_code { None } else { Some(ServerOpt { jemalloc: jemalloc }) }, | 63 | server: if client_code { None } else { Some(ServerOpt { jemalloc }) }, |
64 | }; | 64 | }; |
65 | install(opts)? | 65 | install(opts)? |
66 | } | 66 | } |
diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs index b766aeff1..6a629ce63 100644 --- a/xtask/tests/tidy-tests/docs.rs +++ b/xtask/tests/tidy-tests/docs.rs | |||
@@ -29,7 +29,7 @@ fn is_exclude_file(d: &DirEntry) -> bool { | |||
29 | } | 29 | } |
30 | 30 | ||
31 | fn is_hidden(entry: &DirEntry) -> bool { | 31 | fn is_hidden(entry: &DirEntry) -> bool { |
32 | entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false) | 32 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) |
33 | } | 33 | } |
34 | 34 | ||
35 | #[test] | 35 | #[test] |