From a82c679c97af1e0aabe9eb375573d5d23fc75391 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 13 Jan 2020 11:27:06 -0500 Subject: [PATCH] Some clippy lints --- .../ra_assists/src/assists/add_custom_impl.rs | 2 +- crates/ra_cli/src/main.rs | 2 +- crates/ra_ide/src/call_hierarchy.rs | 2 +- crates/ra_ide/src/call_info.rs | 59 ++++++++++--------- crates/ra_ide/src/completion/complete_path.rs | 2 +- crates/ra_ide/src/extend_selection.rs | 2 +- crates/ra_ide/src/references.rs | 13 ++-- crates/ra_ide/src/references/search_scope.rs | 3 +- crates/ra_parser/src/grammar/paths.rs | 2 +- crates/ra_syntax/src/ast/expr_extensions.rs | 4 +- 10 files changed, 45 insertions(+), 46 deletions(-) diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs index 037306fd67d2..9b89557104a3 100644 --- a/crates/ra_assists/src/assists/add_custom_impl.rs +++ b/crates/ra_assists/src/assists/add_custom_impl.rs @@ -10,7 +10,7 @@ use ra_syntax::{ TextRange, TextUnit, }; -const DERIVE_TRAIT: &'static str = "derive"; +const DERIVE_TRAIT: &str = "derive"; // Assist: add_custom_impl // diff --git a/crates/ra_cli/src/main.rs b/crates/ra_cli/src/main.rs index 3808590abe5c..806612c2ce12 100644 --- a/crates/ra_cli/src/main.rs +++ b/crates/ra_cli/src/main.rs @@ -22,7 +22,7 @@ pub enum Verbosity { } impl Verbosity { - fn is_verbose(&self) -> bool { + fn is_verbose(self) -> bool { match self { Verbosity::Verbose => true, _ => false, diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index 1cb712e32d58..aa5d60c7b5a3 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -121,7 +121,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio Some(macro_def.to_nav(db)) } } { - Some((func_target.clone(), name_ref.value.text_range())) + Some((func_target, name_ref.value.text_range())) } else { None } diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index a7023529b692..14f5ead6b16b 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -1,10 +1,10 @@ //! FIXME: write short doc here - use hir::db::AstDatabase; use ra_syntax::{ ast::{self, ArgListOwner}, match_ast, AstNode, SyntaxNode, }; +use std::cmp::Ordering; use test_utils::tested_by; use crate::{ @@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option {} + Ordering::Equal => { + if !has_self { + call_info.active_parameter = Some(0); + } } - } else if num_params > 1 { - // Count how many parameters into the call we are. - if let Some(arg_list) = calling_node.arg_list() { - // Number of arguments specified at the call site - let num_args_at_callsite = arg_list.args().count(); + Ordering::Greater => { + if let Some(arg_list) = calling_node.arg_list() { + // Number of arguments specified at the call site + let num_args_at_callsite = arg_list.args().count(); - let arg_list_range = arg_list.syntax().text_range(); - if !arg_list_range.contains_inclusive(position.offset) { - tested_by!(call_info_bad_offset); - return None; + let arg_list_range = arg_list.syntax().text_range(); + if !arg_list_range.contains_inclusive(position.offset) { + tested_by!(call_info_bad_offset); + return None; + } + + let mut param = std::cmp::min( + num_args_at_callsite, + arg_list + .args() + .take_while(|arg| arg.syntax().text_range().end() < position.offset) + .count(), + ); + + // If we are in a method account for `self` + if has_self { + param += 1; + } + + call_info.active_parameter = Some(param); } - - let mut param = std::cmp::min( - num_args_at_callsite, - arg_list - .args() - .take_while(|arg| arg.syntax().text_range().end() < position.offset) - .count(), - ); - - // If we are in a method account for `self` - if has_self { - param += 1; - } - - call_info.active_parameter = Some(param); } } diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index cc1f7c830528..0dce9dc2d887 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs @@ -26,7 +26,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { } if let ScopeDef::Unknown = def { if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { - if &name_ref.syntax().text() == name.to_string().as_str() { + if name_ref.syntax().text() == name.to_string().as_str() { // for `use self::foo<|>`, don't suggest `foo` as a completion tested_by!(dont_complete_current_use); continue; diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs index 70b6fde82f27..930e0c4c2431 100644 --- a/crates/ra_ide/src/extend_selection.rs +++ b/crates/ra_ide/src/extend_selection.rs @@ -339,7 +339,7 @@ mod tests { let (cursor, before) = extract_offset(before); let (analysis, file_id) = single_file(&before); let range = TextRange::offset_len(cursor, 0.into()); - let mut frange = FileRange { file_id: file_id, range }; + let mut frange = FileRange { file_id, range }; for &after in afters { frange.range = analysis.extend_selection(frange).unwrap(); diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 4e52e0e7bfb2..2c753dade290 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -166,7 +166,7 @@ pub(crate) fn find_all_refs( Some(RangeInfo::new(range, ReferenceSearchResult { declaration, references })) } -fn find_name<'a>( +fn find_name( db: &RootDatabase, syntax: &SyntaxNode, position: FilePosition, @@ -253,13 +253,10 @@ fn decl_access( let stmt = find_node_at_offset::(syntax, range.start())?; if let Some(_) = stmt.initializer() { let pat = stmt.pat()?; - match pat { - ast::Pat::BindPat(it) => { - if it.name()?.text().as_str() == name { - return Some(ReferenceAccess::Write); - } + if let ast::Pat::BindPat(it) = pat { + if it.name()?.text().as_str() == name { + return Some(ReferenceAccess::Write); } - _ => {} } } @@ -286,7 +283,7 @@ fn reference_access(kind: &NameKind, name_ref: &ast::NameRef) -> Option {None} } diff --git a/crates/ra_ide/src/references/search_scope.rs b/crates/ra_ide/src/references/search_scope.rs index 241dd358f9a6..f8211a74692b 100644 --- a/crates/ra_ide/src/references/search_scope.rs +++ b/crates/ra_ide/src/references/search_scope.rs @@ -82,8 +82,7 @@ impl NameDefinition { return SearchScope::new(res); } - let vis = - self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or("".to_string()); + let vis = self.visibility.as_ref().map(|v| v.syntax().to_string()).unwrap_or_default(); if vis.as_str() == "pub(super)" { if let Some(parent_module) = self.container.parent(db) { diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index ca8e075a1a93..e125c6b9cded 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs @@ -94,7 +94,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { fn opt_path_type_args(p: &mut Parser, mode: Mode) { match mode { - Mode::Use => return, + Mode::Use => {} Mode::Type => { // test path_fn_trait_args // type F = Box ()>; diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 3dfecfe76259..6da4b1309acb 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -127,8 +127,8 @@ pub enum BinOp { } impl BinOp { - pub fn is_assignment(&self) -> bool { - match *self { + pub fn is_assignment(self) -> bool { + match self { BinOp::Assignment | BinOp::AddAssign | BinOp::DivAssign