2825: Some clippy lints r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
bors[bot] 2020-01-13 17:06:19 +00:00 committed by GitHub
commit 7ea7de338f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 45 deletions

View file

@ -10,7 +10,7 @@ use ra_syntax::{
TextRange, TextUnit,
};
const DERIVE_TRAIT: &'static str = "derive";
const DERIVE_TRAIT: &str = "derive";
// Assist: add_custom_impl
//

View file

@ -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,

View file

@ -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
}

View file

@ -1,10 +1,10 @@
//! FIXME: write short doc here
use hir::db::AstDatabase;
use ra_syntax::{
ast::{self, ArgListOwner},
match_ast, AstNode, SyntaxNode,
};
use test_utils::tested_by;
use crate::{
@ -51,36 +51,39 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
// If we have a calling expression let's find which argument we are on
let num_params = call_info.parameters().len();
if num_params == 1 {
if !has_self {
call_info.active_parameter = Some(0);
match num_params {
0 => (),
1 => {
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();
_ => {
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);
}
}

View file

@ -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;

View file

@ -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();

View file

@ -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::<ast::LetStmt>(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<Referenc
}
}
}
return Some(ReferenceAccess::Read);
Some(ReferenceAccess::Read)
},
_ => {None}
}

View file

@ -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) {

View file

@ -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