diff options
| author | bors <bors@rust-lang.org> | 2023-09-22 07:03:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-22 07:03:02 +0000 |
| commit | 2ededa2f14a342cbdf3f0ca6c09a72e5c85f1abe (patch) | |
| tree | aaee3a2ab605f31940e9ac53b3f84c2f3c75cc5c | |
| parent | 11ffcc08a34d6507284cb601676bdde5b2dcb1ed (diff) | |
| parent | 893e19137e85e0fa11187a100b7fc716f7a99c76 (diff) | |
| download | rust-2ededa2f14a342cbdf3f0ca6c09a72e5c85f1abe.tar.gz rust-2ededa2f14a342cbdf3f0ca6c09a72e5c85f1abe.zip | |
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.
| -rw-r--r-- | crates/ide-assists/src/handlers/inline_call.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index a80c1e23941..f8c75bdb0de 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -224,7 +224,6 @@ pub(crate) fn inline_call(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option< syntax.text_range(), |builder| { let replacement = inline(&ctx.sema, file_id, function, &fn_body, ¶ms, &call_info); - builder.replace_ast( match call_info.node { ast::CallableExpr::Call(it) => ast::Expr::CallExpr(it), @@ -363,16 +362,22 @@ fn inline( .collect(); if function.self_param(sema.db).is_some() { - let this = || make::name_ref("this").syntax().clone_for_update().first_token().unwrap(); + let this = || { + make::name_ref("this") + .syntax() + .clone_for_update() + .first_token() + .expect("NameRef should have had a token.") + }; if let Some(self_local) = params[0].2.as_local(sema.db) { usages_for_locals(self_local) .filter_map(|FileReference { name, range, .. }| match name { ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)), _ => None, }) - .for_each(|it| { - ted::replace(it, &this()); - }) + .for_each(|usage| { + ted::replace(usage, &this()); + }); } } @@ -470,7 +475,9 @@ fn inline( } } else if let Some(stmt_list) = body.stmt_list() { ted::insert_all( - ted::Position::after(stmt_list.l_curly_token().unwrap()), + ted::Position::after( + stmt_list.l_curly_token().expect("L_CURLY for StatementList is missing."), + ), let_stmts.into_iter().map(|stmt| stmt.syntax().clone().into()).collect(), ); } |
