Skip to content

Commit d3cc3bc

Browse files
committed
Auto merge of #15665 - Milo123459:milo/remove-unwraps, r=lnicola
internal: De-`unwrap` `generate_function.rs` Fixes rust-lang/rust-analyzer#15398 (comment) cc `@Inicola`
2 parents 972a19f + 85ead6e commit d3cc3bc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ impl FunctionBuilder {
404404
leading_ws,
405405
ret_type: fn_def.ret_type(),
406406
// PANIC: we guarantee we always create a function body with a tail expr
407-
tail_expr: fn_def.body().unwrap().tail_expr().unwrap(),
407+
tail_expr: fn_def
408+
.body()
409+
.expect("generated function should have a body")
410+
.tail_expr()
411+
.expect("function body should have a tail expression"),
408412
should_focus_return_type: self.should_focus_return_type,
409413
fn_def,
410414
trailing_ws,
@@ -683,7 +687,7 @@ where
683687
{
684688
// This function should be only called with `Impl`, `Trait`, or `Function`, for which it's
685689
// infallible to get source ast.
686-
let node = ctx.sema.source(def).unwrap().value;
690+
let node = ctx.sema.source(def).expect("definition's source couldn't be found").value;
687691
let generic_params = node.generic_param_list().into_iter().flat_map(|it| it.generic_params());
688692
let where_clauses = node.where_clause().into_iter().flat_map(|it| it.predicates());
689693
(generic_params, where_clauses)

0 commit comments

Comments
 (0)