clippy::redundant_closure

This commit is contained in:
Maan2003 2021-06-13 09:29:36 +05:30
parent 705f7e6e26
commit 75370312fb
No known key found for this signature in database
GPG Key ID: E9AF024BA63C70ED
12 changed files with 17 additions and 17 deletions

View File

@ -583,13 +583,13 @@ fn source_of_id(&self, id: AttrId) -> InFile<Either<ast::Attr, ast::Comment>> {
.get(id.ast_index as usize) .get(id.ast_index as usize)
.unwrap_or_else(|| panic!("cannot find doc comment at index {:?}", id)) .unwrap_or_else(|| panic!("cannot find doc comment at index {:?}", id))
.clone() .clone()
.map(|attr| Either::Right(attr)) .map(Either::Right)
} else { } else {
self.attrs self.attrs
.get(id.ast_index as usize) .get(id.ast_index as usize)
.unwrap_or_else(|| panic!("cannot find `Attr` at index {:?}", id)) .unwrap_or_else(|| panic!("cannot find `Attr` at index {:?}", id))
.clone() .clone()
.map(|attr| Either::Left(attr)) .map(Either::Left)
} }
} }
} }

View File

@ -431,7 +431,7 @@ pub(crate) fn trait_datum_query(
}; };
let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars); let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
let associated_ty_ids = let associated_ty_ids =
trait_data.associated_types().map(|type_alias| to_assoc_type_id(type_alias)).collect(); trait_data.associated_types().map(to_assoc_type_id).collect();
let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses }; let trait_datum_bound = rust_ir::TraitDatumBound { where_clauses };
let well_known = let well_known =
lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));

View File

@ -49,7 +49,7 @@ pub fn usize_const(value: Option<u64>) -> Const {
ConstData { ConstData {
ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner), ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner),
value: ConstValue::Concrete(chalk_ir::ConcreteConst { value: ConstValue::Concrete(chalk_ir::ConcreteConst {
interned: value.map(|value| ConstScalar::Usize(value)).unwrap_or(ConstScalar::Unknown), interned: value.map(ConstScalar::Usize).unwrap_or(ConstScalar::Unknown),
}), }),
} }
.intern(&Interner) .intern(&Interner)

View File

@ -784,7 +784,7 @@ pub(crate) fn lower_type_bound(
let trait_ref = match bound { let trait_ref = match bound {
TypeBound::Path(path) => { TypeBound::Path(path) => {
bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); bindings = self.lower_trait_ref_from_path(path, Some(self_ty));
bindings.clone().map(WhereClause::Implemented).map(|b| crate::wrap_empty_binders(b)) bindings.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders)
} }
TypeBound::Lifetime(_) => None, TypeBound::Lifetime(_) => None,
TypeBound::Error => None, TypeBound::Error => None,

View File

@ -60,7 +60,7 @@ pub fn for_inherent_impl(ty: &Ty) -> Option<TyFingerprint> {
TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt), TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt),
TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability), TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability),
TyKind::Foreign(alias_id, ..) => TyFingerprint::ForeignType(*alias_id), TyKind::Foreign(alias_id, ..) => TyFingerprint::ForeignType(*alias_id),
TyKind::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?, TyKind::Dyn(_) => ty.dyn_trait().map(TyFingerprint::Dyn)?,
_ => return None, _ => return None,
}; };
Some(fp) Some(fp)
@ -77,7 +77,7 @@ pub fn for_trait_impl(ty: &Ty) -> Option<TyFingerprint> {
TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt), TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt),
TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability), TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability),
TyKind::Foreign(alias_id, ..) => TyFingerprint::ForeignType(*alias_id), TyKind::Foreign(alias_id, ..) => TyFingerprint::ForeignType(*alias_id),
TyKind::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?, TyKind::Dyn(_) => ty.dyn_trait().map(TyFingerprint::Dyn)?,
TyKind::Ref(_, _, ty) => return TyFingerprint::for_trait_impl(ty), TyKind::Ref(_, _, ty) => return TyFingerprint::for_trait_impl(ty),
TyKind::Tuple(_, subst) => { TyKind::Tuple(_, subst) => {
let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner)); let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner));

View File

@ -288,7 +288,7 @@ fn runnable_action(
) -> Option<HoverAction> { ) -> Option<HoverAction> {
match def { match def {
Definition::ModuleDef(it) => match it { Definition::ModuleDef(it) => match it {
ModuleDef::Module(it) => runnable_mod(sema, it).map(|it| HoverAction::Runnable(it)), ModuleDef::Module(it) => runnable_mod(sema, it).map(HoverAction::Runnable),
ModuleDef::Function(func) => { ModuleDef::Function(func) => {
let src = func.source(sema.db)?; let src = func.source(sema.db)?;
if src.file_id != file_id.into() { if src.file_id != file_id.into() {

View File

@ -426,7 +426,7 @@ fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
None None
} }
let impl_def = self_param.syntax().ancestors().find_map(|it| ast::Impl::cast(it))?; let impl_def = self_param.syntax().ancestors().find_map(ast::Impl::cast)?;
let type_name = target_type_name(&impl_def)?; let type_name = target_type_name(&impl_def)?;
let mut replacement_text = String::from(new_name); let mut replacement_text = String::from(new_name);

View File

@ -78,12 +78,12 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<(
terms.sort_by_key(|t| t.syntax().text_range().start()); terms.sort_by_key(|t| t.syntax().text_range().start());
let mut terms = VecDeque::from(terms); let mut terms = VecDeque::from(terms);
let paren_expr = expr.syntax().parent().and_then(|parent| ast::ParenExpr::cast(parent)); let paren_expr = expr.syntax().parent().and_then(ast::ParenExpr::cast);
let neg_expr = paren_expr let neg_expr = paren_expr
.clone() .clone()
.and_then(|paren_expr| paren_expr.syntax().parent()) .and_then(|paren_expr| paren_expr.syntax().parent())
.and_then(|parent| ast::PrefixExpr::cast(parent)) .and_then(ast::PrefixExpr::cast)
.and_then(|prefix_expr| { .and_then(|prefix_expr| {
if prefix_expr.op_kind().unwrap() == ast::PrefixOp::Not { if prefix_expr.op_kind().unwrap() == ast::PrefixOp::Not {
Some(prefix_expr) Some(prefix_expr)

View File

@ -202,7 +202,7 @@ impl ExtendedEnum {
fn variants(self, db: &RootDatabase) -> Vec<ExtendedVariant> { fn variants(self, db: &RootDatabase) -> Vec<ExtendedVariant> {
match self { match self {
ExtendedEnum::Enum(e) => { ExtendedEnum::Enum(e) => {
e.variants(db).into_iter().map(|x| ExtendedVariant::Variant(x)).collect::<Vec<_>>() e.variants(db).into_iter().map(ExtendedVariant::Variant).collect::<Vec<_>>()
} }
ExtendedEnum::Bool => { ExtendedEnum::Bool => {
Vec::<ExtendedVariant>::from([ExtendedVariant::True, ExtendedVariant::False]) Vec::<ExtendedVariant>::from([ExtendedVariant::True, ExtendedVariant::False])

View File

@ -380,7 +380,7 @@ fn expected_type_and_name(&self) -> (Option<Type>, Option<NameOrNameRef>) {
(|| { (|| {
let expr_field = self.token.prev_sibling_or_token()? let expr_field = self.token.prev_sibling_or_token()?
.into_node() .into_node()
.and_then(|node| ast::RecordExprField::cast(node))?; .and_then(ast::RecordExprField::cast)?;
let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?; let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?;
Some(( Some((
Some(ty), Some(ty),

View File

@ -259,7 +259,7 @@ fn test_inside_impl_trait_block() {
} }
pub(crate) fn previous_token(element: SyntaxElement) -> Option<SyntaxToken> { pub(crate) fn previous_token(element: SyntaxElement) -> Option<SyntaxToken> {
element.into_token().and_then(|it| previous_non_trivia_token(it)) element.into_token().and_then(previous_non_trivia_token)
} }
/// Check if the token previous to the previous one is `for`. /// Check if the token previous to the previous one is `for`.
@ -267,8 +267,8 @@ pub(crate) fn previous_token(element: SyntaxElement) -> Option<SyntaxToken> {
pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool { pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool {
element element
.into_token() .into_token()
.and_then(|it| previous_non_trivia_token(it)) .and_then(previous_non_trivia_token)
.and_then(|it| previous_non_trivia_token(it)) .and_then(previous_non_trivia_token)
.filter(|it| it.kind() == T![for]) .filter(|it| it.kind() == T![for])
.is_some() .is_some()
} }

View File

@ -781,7 +781,7 @@ pub(crate) fn handle_completion_resolve(
let resolve_data = match original_completion let resolve_data = match original_completion
.data .data
.take() .take()
.map(|data| serde_json::from_value::<CompletionResolveData>(data)) .map(serde_json::from_value::<CompletionResolveData>)
.transpose()? .transpose()?
{ {
Some(data) => data, Some(data) => data,