Skip to content

Commit

Permalink
Auto merge of #15665 - Milo123459:milo/remove-unwraps, r=lnicola
Browse files Browse the repository at this point in the history
internal: De-`unwrap` `generate_function.rs`

Fixes rust-lang/rust-analyzer#15398 (comment)

cc `@Inicola`
  • Loading branch information
bors committed Sep 25, 2023
2 parents 972a19f + 85ead6e commit d3cc3bc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/ide-assists/src/handlers/generate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d3cc3bc

Please sign in to comment.