Skip to content

Commit 493cabb

Browse files
committed
Treat scope info retrieval failure as assist failure
1 parent 3edde6f commit 493cabb

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl FunctionBuilder {
290290
);
291291

292292
let (generic_param_list, where_clause) =
293-
fn_generic_params(ctx, necessary_generic_params, &target);
293+
fn_generic_params(ctx, necessary_generic_params, &target)?;
294294

295295
Some(Self {
296296
target,
@@ -336,7 +336,7 @@ impl FunctionBuilder {
336336
);
337337

338338
let (generic_param_list, where_clause) =
339-
fn_generic_params(ctx, necessary_generic_params, &target);
339+
fn_generic_params(ctx, necessary_generic_params, &target)?;
340340

341341
Some(Self {
342342
target,
@@ -551,7 +551,8 @@ fn fn_args(
551551
))
552552
}
553553

554-
/// Gets parameter bounds and where predicates in scope and filters out irrelevant ones.
554+
/// Gets parameter bounds and where predicates in scope and filters out irrelevant ones. Returns
555+
/// `None` when it fails to get scope information.
555556
///
556557
/// See comment on `filter_unnecessary_bounds()` for what bounds we consider relevant.
557558
///
@@ -562,10 +563,10 @@ fn fn_generic_params(
562563
ctx: &AssistContext<'_>,
563564
necessary_params: FxHashSet<hir::GenericParam>,
564565
target: &GeneratedFunctionTarget,
565-
) -> (Option<ast::GenericParamList>, Option<ast::WhereClause>) {
566+
) -> Option<(Option<ast::GenericParamList>, Option<ast::WhereClause>)> {
566567
if necessary_params.is_empty() {
567568
// Not really needed but fast path.
568-
return (None, None);
569+
return Some((None, None));
569570
}
570571

571572
// 1. Get generic parameters (with bounds) and where predicates in scope.
@@ -592,8 +593,8 @@ fn fn_generic_params(
592593

593594
// 4. Rewrite paths
594595
if let Some(param) = generic_params.first() {
595-
let source_scope = ctx.sema.scope(param.syntax()).unwrap();
596-
let target_scope = ctx.sema.scope(&target.parent()).unwrap();
596+
let source_scope = ctx.sema.scope(param.syntax())?;
597+
let target_scope = ctx.sema.scope(&target.parent())?;
597598
if source_scope.module() != target_scope.module() {
598599
let transform = PathTransform::generic_transformation(&target_scope, &source_scope);
599600
let generic_params = generic_params.iter().map(|it| it.syntax());
@@ -606,7 +607,7 @@ fn fn_generic_params(
606607
let where_clause =
607608
if where_preds.is_empty() { None } else { Some(make::where_clause(where_preds)) };
608609

609-
(Some(generic_param_list), where_clause)
610+
Some((Some(generic_param_list), where_clause))
610611
}
611612

612613
fn params_and_where_preds_in_scope(

0 commit comments

Comments
 (0)