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`
This commit is contained in:
bors 2023-09-25 11:53:34 +00:00
commit d3cc3bc00e

View file

@ -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)