From b441b4e8effeaf4532fd2e45c4d864480857c49e Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 30 Oct 2019 13:36:37 -0400 Subject: [PATCH] Some clippy fixes --- crates/ra_assists/src/assists/early_return.rs | 2 +- crates/ra_assists/src/assists/inline_local_variable.rs | 6 ++---- crates/ra_assists/src/assists/raw_string.rs | 2 +- crates/ra_ide_api/src/call_info.rs | 2 +- crates/ra_ide_api/src/change.rs | 2 +- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- crates/ra_ide_api/src/completion/presentation.rs | 4 ++-- crates/ra_ide_api/src/references/search_scope.rs | 5 ++--- crates/ra_ide_api/src/typing.rs | 2 +- crates/ra_lsp_server/src/main_loop.rs | 2 +- crates/ra_mbe/src/mbe_expander/matcher.rs | 3 +-- crates/ra_mbe/src/syntax_bridge.rs | 2 +- crates/ra_syntax/src/ast/make.rs | 4 ++-- xtask/src/codegen/gen_assists_docs.rs | 2 +- xtask/src/codegen/gen_parser_tests.rs | 8 +++----- xtask/src/main.rs | 2 +- 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 e839d831e0..ad6c5695a3 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) -> Opt } // check for early return and continue - let first_in_then_block = then_block.syntax().first_child()?.clone(); + let first_in_then_block = then_block.syntax().first_child()?; if ast::ReturnExpr::can_cast(first_in_then_block.kind()) || ast::ContinueExpr::can_cast(first_in_then_block.kind()) || 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 f439105748..a7fd9b6d2d 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) -> Option< let mut wrap_in_parens = vec![true; refs.len()]; for (i, desc) in refs.iter().enumerate() { - let usage_node = ctx - .covering_node_for_range(desc.range) - .ancestors() - .find_map(|node| ast::PathExpr::cast(node))?; + let usage_node = + ctx.covering_node_for_range(desc.range).ancestors().find_map(ast::PathExpr::cast)?; let usage_parent_option = usage_node.syntax().parent().and_then(ast::Expr::cast); let usage_parent = match usage_parent_option { Some(u) => u, diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs index 6f4b66c313..58f7157ae2 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) -> Option { ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| { edit.target(token.text_range()); let result = &text[2..text.len() - 1]; - let result = if result.starts_with("\"") { + let result = if result.starts_with('\"') { // no more hash, escape let internal_str = &result[1..result.len() - 1]; 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 175af3fd92..e494f56206 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 { Some(FnCallNode::CallExpr(expr)) } else if let Some(expr) = ast::MethodCallExpr::cast(node.clone()) { Some(FnCallNode::MethodCallExpr(expr)) - } else if let Some(expr) = ast::MacroCall::cast(node.clone()) { + } else if let Some(expr) = ast::MacroCall::cast(node) { Some(FnCallNode::MacroCallExpr(expr)) } else { None diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 050249c0e6..39c5946c7f 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 { if !self.libraries_added.is_empty() { d.field("libraries_added", &self.libraries_added.len()); } - if !self.crate_graph.is_some() { + if !self.crate_graph.is_none() { d.field("crate_graph", &self.crate_graph); } 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 956d8ce49c..a58fdc036f 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) { }); } } - _ => return, + _ => {} }; } diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index f7e98e6df2..65bb639ed5 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 { for (idx, s) in docs.match_indices(¯o_name) { let (before, after) = (&docs[..idx], &docs[idx + s.len()..]); // Ensure to match the full word - if after.starts_with("!") + if after.starts_with('!') && before .chars() .rev() @@ -225,7 +225,7 @@ impl Completions { } else { (format!("{}($0)", data.name()), format!("{}(…)", name)) }; - builder = builder.lookup_by(name.clone()).label(label).insert_snippet(snippet); + builder = builder.lookup_by(name).label(label).insert_snippet(snippet); } 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 dbd1af5976..f2789e0b2a 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 { if vis.as_str() != "" { let source_root_id = db.file_source_root(file_id); let source_root = db.source_root(source_root_id); - let mut res = - source_root.walk().map(|id| (id.into(), None)).collect::>(); + let mut res = source_root.walk().map(|id| (id, None)).collect::>(); // FIXME: add "pub(in path)" @@ -128,7 +127,7 @@ impl NameDefinition { let root_file = crate_graph.crate_root(crate_id); let source_root_id = db.file_source_root(root_file); let source_root = db.source_root(source_root_id); - res.extend(source_root.walk().map(|id| (id.into(), None))); + res.extend(source_root.walk().map(|id| (id, None))); } } return SearchScope::new(res); diff --git a/crates/ra_ide_api/src/typing.rs b/crates/ra_ide_api/src/typing.rs index 2dfbe6944d..d51132f736 100644 --- a/crates/ra_ide_api/src/typing.rs +++ b/crates/ra_ide_api/src/typing.rs @@ -261,7 +261,7 @@ impl S { fn type_char(char_typed: char, before: &str, after: &str) { let (actual, file_change) = do_type_char(char_typed, before) - .expect(&format!("typing `{}` did nothing", char_typed)); + .unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed)); if after.contains("<|>") { 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 1a87706fee..379dab4384 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( task_receiver.into_iter().for_each(|task| { on_task(task, &connection.sender, &mut loop_state.pending_requests, &mut world_state) }); - libdata_receiver.into_iter().for_each(|lib| drop(lib)); + libdata_receiver.into_iter().for_each(drop); log::info!("...tasks have finished"); log::info!("joining threadpool..."); drop(pool); diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index 0548e8512e..33b9d483d2 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( } None => bindings.push_optional(name), } - () } Op::Repeat { subtree, kind, separator } => { match_repeat(bindings, subtree, kind, separator, src)? @@ -159,7 +158,7 @@ impl<'a> TtIter<'a> { pub(crate) fn expect_lifetime(&mut self) -> Result<&tt::Ident, ()> { let ident = self.expect_ident()?; // check if it start from "`" - if ident.text.chars().next() != Some('\'') { + if !ident.text.starts_with('\'') { return Err(()); } Ok(ident) diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs index 1b543c84b8..592fcf527b 100644 --- a/crates/ra_mbe/src/syntax_bridge.rs +++ b/crates/ra_mbe/src/syntax_bridge.rs @@ -383,7 +383,7 @@ mod tests { "#, ); let expansion = expand(&rules, "literals!(foo);"); - let tts = &[expansion.clone().into()]; + let tts = &[expansion.into()]; let buffer = tt::buffer::TokenBuffer::new(tts); let mut tt_src = SubtreeTokenSource::new(&buffer); let mut tokens = vec![]; diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 76dad91557..3d5f18bfae 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) -> ast::WhereCl } pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { - return ast_from_text(&format!( + ast_from_text(&format!( "fn f() {{ if !{} {{\n {}\n}}\n}}", condition.syntax().text(), statement - )); + )) } fn ast_from_text(text: &str) -> N { diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 0c4cf21529..05afda8f11 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> { let doc = take_until(lines.by_ref(), "```").trim().to_string(); assert!( - doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."), + doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with('.'), "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", id, doc, ); diff --git a/xtask/src/codegen/gen_parser_tests.rs b/xtask/src/codegen/gen_parser_tests.rs index db1e59dacc..d0f0f683b8 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 { for test in collect_tests(&text) { if test.ok { if let Some(old_test) = res.ok.insert(test.name.clone(), test) { - Err(format!("Duplicate test: {}", old_test.name))? - } - } else { - if let Some(old_test) = res.err.insert(test.name.clone(), test) { - Err(format!("Duplicate test: {}", old_test.name))? + return Err(format!("Duplicate test: {}", old_test.name).into()); } + } else if let Some(old_test) = res.err.insert(test.name.clone(), test) { + return Err(format!("Duplicate test: {}", old_test.name).into()); } } Ok(()) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 04dca402c1..4d20232ffd 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -60,7 +60,7 @@ fn main() -> Result<()> { matches.finish().or_else(handle_extra_flags)?; let opts = InstallOpt { client: if server { None } else { Some(ClientOpt::VsCode) }, - server: if client_code { None } else { Some(ServerOpt { jemalloc: jemalloc }) }, + server: if client_code { None } else { Some(ServerOpt { jemalloc }) }, }; install(opts)? } diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs index b766aeff16..6a629ce63e 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 { } fn is_hidden(entry: &DirEntry) -> bool { - entry.file_name().to_str().map(|s| s.starts_with(".")).unwrap_or(false) + entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) } #[test]