From dfdf6fd9f8fd30b7fca495a43459e5cb7299cafa Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 21 Jul 2021 20:52:08 +0200 Subject: [PATCH] Fix some more basic clippy lints --- crates/ide_db/src/assists.rs | 10 +++++----- crates/ide_db/src/call_info.rs | 2 +- crates/ide_db/src/defs.rs | 4 ++-- crates/ide_db/src/helpers/insert_use.rs | 2 +- crates/ide_db/src/helpers/merge_imports.rs | 2 +- crates/ide_db/src/source_change.rs | 7 ++----- crates/ide_db/src/ty_filter.rs | 2 +- crates/parser/src/grammar/params.rs | 20 ++++++++------------ crates/syntax/src/ast/node_ext.rs | 2 +- 9 files changed, 22 insertions(+), 29 deletions(-) diff --git a/crates/ide_db/src/assists.rs b/crates/ide_db/src/assists.rs index 7881d83691b..be5f063f0fc 100644 --- a/crates/ide_db/src/assists.rs +++ b/crates/ide_db/src/assists.rs @@ -52,12 +52,12 @@ impl AssistKind { match self { AssistKind::None | AssistKind::Generate => true, - AssistKind::Refactor => match other { + AssistKind::Refactor => matches!( + other, AssistKind::RefactorExtract - | AssistKind::RefactorInline - | AssistKind::RefactorRewrite => true, - _ => false, - }, + | AssistKind::RefactorInline + | AssistKind::RefactorRewrite + ), _ => false, } } diff --git a/crates/ide_db/src/call_info.rs b/crates/ide_db/src/call_info.rs index 4795e25650b..da3b9bf1e9c 100644 --- a/crates/ide_db/src/call_info.rs +++ b/crates/ide_db/src/call_info.rs @@ -166,7 +166,7 @@ impl ActiveParameter { let idx = active_parameter?; let mut params = signature.params(sema.db); - if !(idx < params.len()) { + if params.len() <= idx { cov_mark::hit!(too_many_arguments); return None; } diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index 6b6cb145374..e9fb71fd8cd 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs @@ -153,7 +153,7 @@ impl NameClass { path_segment.name_ref() }, PathSegmentKind::Name(name_ref) => Some(name_ref), - _ => return None, + _ => None, } }) .and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?; @@ -341,7 +341,7 @@ impl NameRefClass { hir::AssocItem::TypeAlias(it) => Some(*it), _ => None, }) - .find(|alias| &alias.name(sema.db).to_string() == &name_ref.text()) + .find(|alias| alias.name(sema.db).to_string() == name_ref.text()) { return Some(NameRefClass::Definition(Definition::ModuleDef( ModuleDef::TypeAlias(ty), diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index e16021c82ff..80cc2ca815e 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs @@ -181,7 +181,7 @@ enum ImportGranularityGuess { } /// Insert an import path into the given file/node. A `merge` value of none indicates that no import merging is allowed to occur. -pub fn insert_use<'a>(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) { +pub fn insert_use(scope: &ImportScope, path: ast::Path, cfg: &InsertUseConfig) { let _p = profile::span("insert_use"); let mut mb = match cfg.granularity { ImportGranularity::Crate => Some(MergeBehavior::Crate), diff --git a/crates/ide_db/src/helpers/merge_imports.rs b/crates/ide_db/src/helpers/merge_imports.rs index ec29476a492..69fc84874c4 100644 --- a/crates/ide_db/src/helpers/merge_imports.rs +++ b/crates/ide_db/src/helpers/merge_imports.rs @@ -162,7 +162,7 @@ fn recursive_merge( } Err(_) if merge == MergeBehavior::Module - && use_trees.len() > 0 + && !use_trees.is_empty() && rhs_t.use_tree_list().is_some() => { return None diff --git a/crates/ide_db/src/source_change.rs b/crates/ide_db/src/source_change.rs index 846530f7845..4c2133e65b1 100644 --- a/crates/ide_db/src/source_change.rs +++ b/crates/ide_db/src/source_change.rs @@ -3,10 +3,7 @@ //! //! It can be viewed as a dual for `Change`. -use std::{ - collections::hash_map::Entry, - iter::{self, FromIterator}, -}; +use std::{collections::hash_map::Entry, iter}; use base_db::{AnchoredPathBuf, FileId}; use rustc_hash::FxHashMap; @@ -32,7 +29,7 @@ impl SourceChange { pub fn from_text_edit(file_id: FileId, edit: TextEdit) -> Self { SourceChange { - source_file_edits: FxHashMap::from_iter(iter::once((file_id, edit))), + source_file_edits: iter::once((file_id, edit)).collect(), ..Default::default() } } diff --git a/crates/ide_db/src/ty_filter.rs b/crates/ide_db/src/ty_filter.rs index 91f1d1cb7db..370d0df0076 100644 --- a/crates/ide_db/src/ty_filter.rs +++ b/crates/ide_db/src/ty_filter.rs @@ -26,7 +26,7 @@ impl TryEnum { _ => return None, }; TryEnum::ALL.iter().find_map(|&var| { - if &enum_.name(sema.db).to_string() == var.type_name() { + if enum_.name(sema.db).to_string() == var.type_name() { return Some(var); } None diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs index 8f028c61941..8b03ade81f7 100644 --- a/crates/parser/src/grammar/params.rs +++ b/crates/parser/src/grammar/params.rs @@ -105,14 +105,12 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic { patterns::pattern(p); if variadic_param(p) { res = Variadic(true) + } else if p.at(T![:]) { + types::ascription(p) } else { - if p.at(T![:]) { - types::ascription(p) - } else { - // test_err missing_fn_param_type - // fn f(x y: i32, z, t: i32) {} - p.error("missing type for function parameter") - } + // test_err missing_fn_param_type + // fn f(x y: i32, z, t: i32) {} + p.error("missing type for function parameter") } } // test value_parameters_no_patterns @@ -131,12 +129,10 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic { patterns::pattern_single(p); if variadic_param(p) { res = Variadic(true) + } else if p.at(T![:]) { + types::ascription(p) } else { - if p.at(T![:]) { - types::ascription(p) - } else { - p.error("missing type for function parameter") - } + p.error("missing type for function parameter") } } else { types::type_(p); diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index e54c3f430c3..73d66281802 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -91,7 +91,7 @@ impl ast::Expr { | ast::Effect::Const(_) ) } - ast::Expr::ClosureExpr(__) => true, + ast::Expr::ClosureExpr(_) => true, _ => false, }; cb(expr);