From 721e79035d563feca091e986b658edd3e4087943 Mon Sep 17 00:00:00 2001 From: dfireBird Date: Sat, 20 Jan 2024 19:26:50 +0530 Subject: [PATCH] include `for` in convert to guarded return assist --- .../src/handlers/convert_to_guarded_return.rs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs index 73ba3f5c4c..b18f87b4f6 100644 --- a/crates/ide-assists/src/handlers/convert_to_guarded_return.rs +++ b/crates/ide-assists/src/handlers/convert_to_guarded_return.rs @@ -8,7 +8,7 @@ use syntax::{ make, }, ted, AstNode, - SyntaxKind::{FN, LOOP_EXPR, WHILE_EXPR, WHITESPACE}, + SyntaxKind::{FN, FOR_EXPR, LOOP_EXPR, WHILE_EXPR, WHITESPACE}, T, }; @@ -82,7 +82,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext<' let parent_container = parent_block.syntax().parent()?; let early_expression: ast::Expr = match parent_container.kind() { - WHILE_EXPR | LOOP_EXPR => make::expr_continue(None), + WHILE_EXPR | LOOP_EXPR | FOR_EXPR => make::expr_continue(None), FN => make::expr_return(None), _ => return None, }; @@ -426,6 +426,32 @@ fn main() { ); } + #[test] + fn convert_let_inside_for() { + check_assist( + convert_to_guarded_return, + r#" +fn main() { + for n in ns { + if$0 let Some(n) = n { + foo(n); + bar(); + } + } +} +"#, + r#" +fn main() { + for n in ns { + let Some(n) = n else { continue }; + foo(n); + bar(); + } +} +"#, + ); + } + #[test] fn convert_arbitrary_if_let_patterns() { check_assist(