about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-25 11:53:34 +0000
committerbors <bors@rust-lang.org>2023-09-25 11:53:34 +0000
commitd3cc3bc00e310ff49268ce0c593eaa6bf4724bbd (patch)
tree8fd2c39bef5022bb265b62bfe8cb785e7a1a9599
parent972a19f4cb3c7e78dcbf21cdc0859c91d18ad863 (diff)
parent85ead6ec278c7bb99173189d5baba00429c0b32e (diff)
downloadrust-d3cc3bc00e310ff49268ce0c593eaa6bf4724bbd.tar.gz
rust-d3cc3bc00e310ff49268ce0c593eaa6bf4724bbd.zip
Auto merge of #15665 - Milo123459:milo/remove-unwraps, r=lnicola
internal: De-`unwrap` `generate_function.rs`

Fixes https://github.com/rust-lang/rust-analyzer/issues/15398#issuecomment-1733462185

cc `@Inicola`
-rw-r--r--crates/ide-assists/src/handlers/generate_function.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs
index 5b13e01b133..f74fc5df4bd 100644
--- a/crates/ide-assists/src/handlers/generate_function.rs
+++ b/crates/ide-assists/src/handlers/generate_function.rs
@@ -404,7 +404,11 @@ impl FunctionBuilder {
             leading_ws,
             ret_type: fn_def.ret_type(),
             // PANIC: we guarantee we always create a function body with a tail expr
-            tail_expr: fn_def.body().unwrap().tail_expr().unwrap(),
+            tail_expr: fn_def
+                .body()
+                .expect("generated function should have a body")
+                .tail_expr()
+                .expect("function body should have a tail expression"),
             should_focus_return_type: self.should_focus_return_type,
             fn_def,
             trailing_ws,
@@ -683,7 +687,7 @@ where
 {
     // This function should be only called with `Impl`, `Trait`, or `Function`, for which it's
     // infallible to get source ast.
-    let node = ctx.sema.source(def).unwrap().value;
+    let node = ctx.sema.source(def).expect("definition's source couldn't be found").value;
     let generic_params = node.generic_param_list().into_iter().flat_map(|it| it.generic_params());
     let where_clauses = node.where_clause().into_iter().flat_map(|it| it.predicates());
     (generic_params, where_clauses)