From a82c679c97af1e0aabe9eb375573d5d23fc75391 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 13 Jan 2020 11:27:06 -0500 Subject: Some clippy lints --- crates/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(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs index 037306fd6..9b8955710 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 3808590ab..806612c2c 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 1cb712e32..aa5d60c7b 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 a7023529b..14f5ead6b 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 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(); - - 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; + match num_params.cmp(&1) { + Ordering::Less => {} + Ordering::Equal => { + if !has_self { + call_info.active_parameter = Some(0); } + } + 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 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; - } + 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); + 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 cc1f7c830..0dce9dc2d 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 70b6fde82..930e0c4c2 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 4e52e0e7b..2c753dade 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 241dd358f..f8211a746 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 ca8e075a1..e125c6b9c 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 3dfecfe76..6da4b1309 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 -- cgit v1.2.3 From c5c5f4260b4ab1a03d2d3f7a616202369adc9ade Mon Sep 17 00:00:00 2001 From: kjeremy Date: Mon, 13 Jan 2020 11:38:53 -0500 Subject: Readability --- crates/ra_ide/src/call_info.rs | 10 +++++----- crates/ra_parser/src/grammar/paths.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 14f5ead6b..72a68522e 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -4,7 +4,7 @@ use ra_syntax::{ ast::{self, ArgListOwner}, match_ast, AstNode, SyntaxNode, }; -use std::cmp::Ordering; + use test_utils::tested_by; use crate::{ @@ -51,14 +51,14 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option {} - Ordering::Equal => { + match num_params { + 0 => (), + 1 => { if !has_self { call_info.active_parameter = Some(0); } } - 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(); diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index e125c6b9c..ca8e075a1 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 => {} + Mode::Use => return, Mode::Type => { // test path_fn_trait_args // type F = Box ()>; -- cgit v1.2.3