clippy::redundant_closure
This commit is contained in:
parent
705f7e6e26
commit
75370312fb
@ -583,13 +583,13 @@ fn source_of_id(&self, id: AttrId) -> InFile<Either<ast::Attr, ast::Comment>> {
|
||||
.get(id.ast_index as usize)
|
||||
.unwrap_or_else(|| panic!("cannot find doc comment at index {:?}", id))
|
||||
.clone()
|
||||
.map(|attr| Either::Right(attr))
|
||||
.map(Either::Right)
|
||||
} else {
|
||||
self.attrs
|
||||
.get(id.ast_index as usize)
|
||||
.unwrap_or_else(|| panic!("cannot find `Attr` at index {:?}", id))
|
||||
.clone()
|
||||
.map(|attr| Either::Left(attr))
|
||||
.map(Either::Left)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ pub(crate) fn trait_datum_query(
|
||||
};
|
||||
let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
|
||||
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 well_known =
|
||||
lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
|
||||
|
@ -49,7 +49,7 @@ pub fn usize_const(value: Option<u64>) -> Const {
|
||||
ConstData {
|
||||
ty: TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&Interner),
|
||||
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)
|
||||
|
@ -784,7 +784,7 @@ pub(crate) fn lower_type_bound(
|
||||
let trait_ref = match bound {
|
||||
TypeBound::Path(path) => {
|
||||
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::Error => None,
|
||||
|
@ -60,7 +60,7 @@ pub fn for_inherent_impl(ty: &Ty) -> Option<TyFingerprint> {
|
||||
TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt),
|
||||
TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability),
|
||||
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,
|
||||
};
|
||||
Some(fp)
|
||||
@ -77,7 +77,7 @@ pub fn for_trait_impl(ty: &Ty) -> Option<TyFingerprint> {
|
||||
TyKind::Adt(AdtId(adt), _) => TyFingerprint::Adt(*adt),
|
||||
TyKind::Raw(mutability, ..) => TyFingerprint::RawPtr(*mutability),
|
||||
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::Tuple(_, subst) => {
|
||||
let first_ty = subst.interned().get(0).map(|arg| arg.assert_ty_ref(&Interner));
|
||||
|
@ -288,7 +288,7 @@ fn runnable_action(
|
||||
) -> Option<HoverAction> {
|
||||
match def {
|
||||
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) => {
|
||||
let src = func.source(sema.db)?;
|
||||
if src.file_id != file_id.into() {
|
||||
|
@ -426,7 +426,7 @@ fn target_type_name(impl_def: &ast::Impl) -> Option<String> {
|
||||
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 mut replacement_text = String::from(new_name);
|
||||
|
@ -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());
|
||||
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
|
||||
.clone()
|
||||
.and_then(|paren_expr| paren_expr.syntax().parent())
|
||||
.and_then(|parent| ast::PrefixExpr::cast(parent))
|
||||
.and_then(ast::PrefixExpr::cast)
|
||||
.and_then(|prefix_expr| {
|
||||
if prefix_expr.op_kind().unwrap() == ast::PrefixOp::Not {
|
||||
Some(prefix_expr)
|
||||
|
@ -202,7 +202,7 @@ impl ExtendedEnum {
|
||||
fn variants(self, db: &RootDatabase) -> Vec<ExtendedVariant> {
|
||||
match self {
|
||||
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 => {
|
||||
Vec::<ExtendedVariant>::from([ExtendedVariant::True, ExtendedVariant::False])
|
||||
|
@ -380,7 +380,7 @@ fn expected_type_and_name(&self) -> (Option<Type>, Option<NameOrNameRef>) {
|
||||
(|| {
|
||||
let expr_field = self.token.prev_sibling_or_token()?
|
||||
.into_node()
|
||||
.and_then(|node| ast::RecordExprField::cast(node))?;
|
||||
.and_then(ast::RecordExprField::cast)?;
|
||||
let (_, _, ty) = self.sema.resolve_record_field(&expr_field)?;
|
||||
Some((
|
||||
Some(ty),
|
||||
|
@ -259,7 +259,7 @@ fn test_inside_impl_trait_block() {
|
||||
}
|
||||
|
||||
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`.
|
||||
@ -267,8 +267,8 @@ pub(crate) fn previous_token(element: SyntaxElement) -> Option<SyntaxToken> {
|
||||
pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool {
|
||||
element
|
||||
.into_token()
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.and_then(|it| previous_non_trivia_token(it))
|
||||
.and_then(previous_non_trivia_token)
|
||||
.and_then(previous_non_trivia_token)
|
||||
.filter(|it| it.kind() == T![for])
|
||||
.is_some()
|
||||
}
|
||||
|
@ -781,7 +781,7 @@ pub(crate) fn handle_completion_resolve(
|
||||
let resolve_data = match original_completion
|
||||
.data
|
||||
.take()
|
||||
.map(|data| serde_json::from_value::<CompletionResolveData>(data))
|
||||
.map(serde_json::from_value::<CompletionResolveData>)
|
||||
.transpose()?
|
||||
{
|
||||
Some(data) => data,
|
||||
|
Loading…
Reference in New Issue
Block a user