about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAli Bektas <bektasali@protonmail.com>2023-09-09 14:35:26 +0200
committerAli Bektas <bektasali@protonmail.com>2023-09-10 22:39:07 +0200
commit68d24b69d45f357e7309c497f683c8b1e6ad691a (patch)
treec555a798a10c391c3fc5ef6bd03d4a6d93bb5529
parent5683df2965f9577ca1307f10af766aeecd6b560e (diff)
downloadrust-68d24b69d45f357e7309c497f683c8b1e6ad691a.tar.gz
rust-68d24b69d45f357e7309c497f683c8b1e6ad691a.zip
Deunwrap inline call v2
-rw-r--r--crates/ide-assists/src/handlers/inline_call.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs
index b7787e4c33a..4751de31255 100644
--- a/crates/ide-assists/src/handlers/inline_call.rs
+++ b/crates/ide-assists/src/handlers/inline_call.rs
@@ -117,7 +117,7 @@ pub(crate) fn inline_into_callers(acc: &mut Assists, ctx: &AssistContext<'_>) ->
                     .map(|(call_info, mut_node)| {
                         let replacement =
                             inline(&ctx.sema, def_file, function, &func_body, &params, &call_info)
-                                .unwrap();
+                                .expect("inline() should return an Expr");
                         ted::replace(mut_node, replacement.syntax());
                     })
                     .count();
@@ -363,17 +363,23 @@ fn inline(
         .collect();
 
     if function.self_param(sema.db).is_some() {
-        let this = || make::name_ref("this").syntax().clone_for_update().first_token();
+        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) {
-            let usages = usages_for_locals(self_local).filter_map(
-                |FileReference { name, range, .. }| match name {
+            usages_for_locals(self_local)
+                .filter_map(|FileReference { name, range, .. }| match name {
                     ast::NameLike::NameRef(_) => Some(body.syntax().covering_element(range)),
                     _ => None,
-                },
-            );
-            for usage in usages {
-                ted::replace(usage, &this()?);
-            }
+                })
+                .into_iter()
+                .for_each(|usage| {
+                    ted::replace(usage, &this());
+                });
         }
     }
 
@@ -471,7 +477,9 @@ fn inline(
         }
     } else if let Some(stmt_list) = body.stmt_list() {
         ted::insert_all(
-            ted::Position::after(stmt_list.l_curly_token()?),
+            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(),
         );
     }