Skip to content

Commit 94afbe3

Browse files
committed
Deunwrap inline call v2
1 parent aa6344f commit 94afbe3

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

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

+18-10
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
117117
.map(|(call_info, mut_node)| {
118118
let replacement =
119119
inline(&ctx.sema, def_file, function, &func_body, &params, &call_info)
120-
.unwrap();
120+
.expect("inline() should return an Expr");
121121
ted::replace(mut_node, replacement.syntax());
122122
})
123123
.count();
@@ -363,17 +363,23 @@ fn inline(
363363
.collect();
364364

365365
if function.self_param(sema.db).is_some() {
366-
let this = || make::name_ref("this").syntax().clone_for_update().first_token();
366+
let this = || {
367+
make::name_ref("this")
368+
.syntax()
369+
.clone_for_update()
370+
.first_token()
371+
.expect("NameRef should have had a token.")
372+
};
367373
if let Some(self_local) = params[0].2.as_local(sema.db) {
368-
let usages = usages_for_locals(self_local).filter_map(
369-
|FileReference { name, range, .. }| match name {
374+
usages_for_locals(self_local)
375+
.filter_map(|FileReference { name, range, .. }| match name {
370376
ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
371377
_ => None,
372-
},
373-
);
374-
for usage in usages {
375-
ted::replace(usage, &this()?);
376-
}
378+
})
379+
.into_iter()
380+
.for_each(|usage| {
381+
ted::replace(usage, &this());
382+
});
377383
}
378384
}
379385

@@ -471,7 +477,9 @@ fn inline(
471477
}
472478
} else if let Some(stmt_list) = body.stmt_list() {
473479
ted::insert_all(
474-
ted::Position::after(stmt_list.l_curly_token()?),
480+
ted::Position::after(
481+
stmt_list.l_curly_token().expect("L_CURLY for StatementList is missing."),
482+
),
475483
let_stmts.into_iter().map(|stmt| stmt.syntax().clone().into()).collect(),
476484
);
477485
}

0 commit comments

Comments
 (0)