From b441b4e8effeaf4532fd2e45c4d864480857c49e Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 30 Oct 2019 13:36:37 -0400 Subject: 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 ++-- 13 files changed, 17 insertions(+), 21 deletions(-) (limited to 'crates') 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) -> 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 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) -> 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 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) -> 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 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 { 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 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 { 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 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) { }); } } - _ => return, + _ => {} }; } 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 { 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 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 { 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 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 { 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 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( 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 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( } 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 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 { "#, ); 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 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) -> 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 { -- cgit v1.2.3