fix: use functional programming

This commit is contained in:
ice1000 2022-08-19 01:08:59 +00:00
parent b6fe46055b
commit 5a6c51ebb8

View File

@ -13,7 +13,7 @@ use ide_db::{
use itertools::{izip, Itertools}; use itertools::{izip, Itertools};
use syntax::{ use syntax::{
ast::{self, edit_in_place::Indent, HasArgList, PathExpr}, ast::{self, edit_in_place::Indent, HasArgList, PathExpr},
ted, AstNode, SyntaxKind, ted, AstNode, NodeOrToken, SyntaxKind,
}; };
use crate::{ use crate::{
@ -311,15 +311,12 @@ fn inline(
} else { } else {
fn_body.clone_for_update() fn_body.clone_for_update()
}; };
// TODO: use if-let chains - https://github.com/rust-lang/rust/pull/94927 if let Some(t) = body.syntax().ancestors().find_map(ast::Impl::cast).and_then(|i| i.self_ty()) {
if let Some(i) = body.syntax().ancestors().find_map(ast::Impl::cast) { body.syntax()
if let Some(st) = i.self_ty() { .descendants_with_tokens()
for tok in body.syntax().descendants_with_tokens().filter_map(|t| t.into_token()) { .filter_map(NodeOrToken::into_token)
if tok.kind() == SyntaxKind::SELF_TYPE_KW { .filter(|tok| tok.kind() == SyntaxKind::SELF_TYPE_KW)
ted::replace(tok, st.syntax()); .for_each(|tok| ted::replace(tok, t.syntax()));
}
}
}
} }
let usages_for_locals = |local| { let usages_for_locals = |local| {
Definition::Local(local) Definition::Local(local)