Fix some more basic clippy lints

This commit is contained in:
Lukas Wirth 2021-07-21 20:52:08 +02:00
parent 9485d6efba
commit dfdf6fd9f8
9 changed files with 22 additions and 29 deletions

View File

@ -52,12 +52,12 @@ impl AssistKind {
match self { match self {
AssistKind::None | AssistKind::Generate => true, AssistKind::None | AssistKind::Generate => true,
AssistKind::Refactor => match other { AssistKind::Refactor => matches!(
other,
AssistKind::RefactorExtract AssistKind::RefactorExtract
| AssistKind::RefactorInline | AssistKind::RefactorInline
| AssistKind::RefactorRewrite => true, | AssistKind::RefactorRewrite
_ => false, ),
},
_ => false, _ => false,
} }
} }

View File

@ -166,7 +166,7 @@ impl ActiveParameter {
let idx = active_parameter?; let idx = active_parameter?;
let mut params = signature.params(sema.db); let mut params = signature.params(sema.db);
if !(idx < params.len()) { if params.len() <= idx {
cov_mark::hit!(too_many_arguments); cov_mark::hit!(too_many_arguments);
return None; return None;
} }

View File

@ -153,7 +153,7 @@ impl NameClass {
path_segment.name_ref() path_segment.name_ref()
}, },
PathSegmentKind::Name(name_ref) => Some(name_ref), PathSegmentKind::Name(name_ref) => Some(name_ref),
_ => return None, _ => None,
} }
}) })
.and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?; .and_then(|name_ref| NameRefClass::classify(sema, &name_ref))?;
@ -341,7 +341,7 @@ impl NameRefClass {
hir::AssocItem::TypeAlias(it) => Some(*it), hir::AssocItem::TypeAlias(it) => Some(*it),
_ => None, _ => 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( return Some(NameRefClass::Definition(Definition::ModuleDef(
ModuleDef::TypeAlias(ty), ModuleDef::TypeAlias(ty),

View File

@ -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. /// 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 _p = profile::span("insert_use");
let mut mb = match cfg.granularity { let mut mb = match cfg.granularity {
ImportGranularity::Crate => Some(MergeBehavior::Crate), ImportGranularity::Crate => Some(MergeBehavior::Crate),

View File

@ -162,7 +162,7 @@ fn recursive_merge(
} }
Err(_) Err(_)
if merge == MergeBehavior::Module if merge == MergeBehavior::Module
&& use_trees.len() > 0 && !use_trees.is_empty()
&& rhs_t.use_tree_list().is_some() => && rhs_t.use_tree_list().is_some() =>
{ {
return None return None

View File

@ -3,10 +3,7 @@
//! //!
//! It can be viewed as a dual for `Change`. //! It can be viewed as a dual for `Change`.
use std::{ use std::{collections::hash_map::Entry, iter};
collections::hash_map::Entry,
iter::{self, FromIterator},
};
use base_db::{AnchoredPathBuf, FileId}; use base_db::{AnchoredPathBuf, FileId};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -32,7 +29,7 @@ impl SourceChange {
pub fn from_text_edit(file_id: FileId, edit: TextEdit) -> Self { pub fn from_text_edit(file_id: FileId, edit: TextEdit) -> Self {
SourceChange { SourceChange {
source_file_edits: FxHashMap::from_iter(iter::once((file_id, edit))), source_file_edits: iter::once((file_id, edit)).collect(),
..Default::default() ..Default::default()
} }
} }

View File

@ -26,7 +26,7 @@ impl TryEnum {
_ => return None, _ => return None,
}; };
TryEnum::ALL.iter().find_map(|&var| { 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); return Some(var);
} }
None None

View File

@ -105,14 +105,12 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
patterns::pattern(p); patterns::pattern(p);
if variadic_param(p) { if variadic_param(p) {
res = Variadic(true) res = Variadic(true)
} else if p.at(T![:]) {
types::ascription(p)
} else { } else {
if p.at(T![:]) { // test_err missing_fn_param_type
types::ascription(p) // fn f(x y: i32, z, t: i32) {}
} else { 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 // test value_parameters_no_patterns
@ -131,12 +129,10 @@ fn param(p: &mut Parser, m: Marker, flavor: Flavor) -> Variadic {
patterns::pattern_single(p); patterns::pattern_single(p);
if variadic_param(p) { if variadic_param(p) {
res = Variadic(true) res = Variadic(true)
} else if p.at(T![:]) {
types::ascription(p)
} else { } else {
if p.at(T![:]) { p.error("missing type for function parameter")
types::ascription(p)
} else {
p.error("missing type for function parameter")
}
} }
} else { } else {
types::type_(p); types::type_(p);

View File

@ -91,7 +91,7 @@ impl ast::Expr {
| ast::Effect::Const(_) | ast::Effect::Const(_)
) )
} }
ast::Expr::ClosureExpr(__) => true, ast::Expr::ClosureExpr(_) => true,
_ => false, _ => false,
}; };
cb(expr); cb(expr);