Skip to content

Commit cc6c820

Browse files
committed
Auto merge of rust-lang#15431 - alibektas:deunwrap/extract_function, r=Veykril
minor : Deunwrap extract_function rust-lang#15398 subtask 5.
2 parents 0e251ff + 0f1673c commit cc6c820

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

crates/ide-assists/src/handlers/extract_function.rs

+21-22
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl FunctionBody {
531531

532532
fn extracted_from_trait_impl(&self) -> bool {
533533
match self.node().ancestors().find_map(ast::Impl::cast) {
534-
Some(c) => return c.trait_().is_some(),
534+
Some(c) => c.trait_().is_some(),
535535
None => false,
536536
}
537537
}
@@ -1048,23 +1048,17 @@ impl GenericParent {
10481048
fn generic_parents(parent: &SyntaxNode) -> Vec<GenericParent> {
10491049
let mut list = Vec::new();
10501050
if let Some(parent_item) = parent.ancestors().find_map(ast::Item::cast) {
1051-
match parent_item {
1052-
ast::Item::Fn(ref fn_) => {
1053-
if let Some(parent_parent) = parent_item
1054-
.syntax()
1055-
.parent()
1056-
.and_then(|it| it.parent())
1057-
.and_then(ast::Item::cast)
1058-
{
1059-
match parent_parent {
1060-
ast::Item::Impl(impl_) => list.push(GenericParent::Impl(impl_)),
1061-
ast::Item::Trait(trait_) => list.push(GenericParent::Trait(trait_)),
1062-
_ => (),
1063-
}
1051+
if let ast::Item::Fn(ref fn_) = parent_item {
1052+
if let Some(parent_parent) =
1053+
parent_item.syntax().parent().and_then(|it| it.parent()).and_then(ast::Item::cast)
1054+
{
1055+
match parent_parent {
1056+
ast::Item::Impl(impl_) => list.push(GenericParent::Impl(impl_)),
1057+
ast::Item::Trait(trait_) => list.push(GenericParent::Trait(trait_)),
1058+
_ => (),
10641059
}
1065-
list.push(GenericParent::Fn(fn_.clone()));
10661060
}
1067-
_ => (),
1061+
list.push(GenericParent::Fn(fn_.clone()));
10681062
}
10691063
}
10701064
list
@@ -1728,7 +1722,7 @@ fn make_body(
17281722
let block = match &fun.body {
17291723
FunctionBody::Expr(expr) => {
17301724
let expr = rewrite_body_segment(ctx, &fun.params, &handler, expr.syntax());
1731-
let expr = ast::Expr::cast(expr).unwrap();
1725+
let expr = ast::Expr::cast(expr).expect("Body segment should be an expr");
17321726
match expr {
17331727
ast::Expr::BlockExpr(block) => {
17341728
// If the extracted expression is itself a block, there is no need to wrap it inside another block.
@@ -1868,9 +1862,8 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr
18681862

18691863
if let Some(stmt_list) = block.stmt_list() {
18701864
stmt_list.syntax().children_with_tokens().for_each(|node_or_token| {
1871-
match &node_or_token {
1872-
syntax::NodeOrToken::Token(_) => elements.push(node_or_token),
1873-
_ => (),
1865+
if let syntax::NodeOrToken::Token(_) = &node_or_token {
1866+
elements.push(node_or_token)
18741867
};
18751868
});
18761869
}
@@ -1934,12 +1927,18 @@ fn fix_param_usages(ctx: &AssistContext<'_>, params: &[Param], syntax: &SyntaxNo
19341927
Some(ast::Expr::RefExpr(node))
19351928
if param.kind() == ParamKind::MutRef && node.mut_token().is_some() =>
19361929
{
1937-
ted::replace(node.syntax(), node.expr().unwrap().syntax());
1930+
ted::replace(
1931+
node.syntax(),
1932+
node.expr().expect("RefExpr::expr() cannot be None").syntax(),
1933+
);
19381934
}
19391935
Some(ast::Expr::RefExpr(node))
19401936
if param.kind() == ParamKind::SharedRef && node.mut_token().is_none() =>
19411937
{
1942-
ted::replace(node.syntax(), node.expr().unwrap().syntax());
1938+
ted::replace(
1939+
node.syntax(),
1940+
node.expr().expect("RefExpr::expr() cannot be None").syntax(),
1941+
);
19431942
}
19441943
Some(_) | None => {
19451944
let p = &make::expr_prefix(T![*], usage.clone()).clone_for_update();

0 commit comments

Comments
 (0)