Skip to content

Commit 2ededa2

Browse files
committed
Auto merge of #15432 - alibektas:deunwrap/inline_call, r=Veykril
minor : Deunwrap inline call #15398 subtask 4. There is still one instance of unwrap, which I found pretty hard to change.
2 parents 11ffcc0 + 893e191 commit 2ededa2

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
224224
syntax.text_range(),
225225
|builder| {
226226
let replacement = inline(&ctx.sema, file_id, function, &fn_body, &params, &call_info);
227-
228227
builder.replace_ast(
229228
match call_info.node {
230229
ast::CallableExpr::Call(it) => ast::Expr::CallExpr(it),
@@ -363,16 +362,22 @@ fn inline(
363362
.collect();
364363

365364
if function.self_param(sema.db).is_some() {
366-
let this = || make::name_ref("this").syntax().clone_for_update().first_token().unwrap();
365+
let this = || {
366+
make::name_ref("this")
367+
.syntax()
368+
.clone_for_update()
369+
.first_token()
370+
.expect("NameRef should have had a token.")
371+
};
367372
if let Some(self_local) = params[0].2.as_local(sema.db) {
368373
usages_for_locals(self_local)
369374
.filter_map(|FileReference { name, range, .. }| match name {
370375
ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
371376
_ => None,
372377
})
373-
.for_each(|it| {
374-
ted::replace(it, &this());
375-
})
378+
.for_each(|usage| {
379+
ted::replace(usage, &this());
380+
});
376381
}
377382
}
378383

@@ -470,7 +475,9 @@ fn inline(
470475
}
471476
} else if let Some(stmt_list) = body.stmt_list() {
472477
ted::insert_all(
473-
ted::Position::after(stmt_list.l_curly_token().unwrap()),
478+
ted::Position::after(
479+
stmt_list.l_curly_token().expect("L_CURLY for StatementList is missing."),
480+
),
474481
let_stmts.into_iter().map(|stmt| stmt.syntax().clone().into()).collect(),
475482
);
476483
}

0 commit comments

Comments
 (0)