Skip to content

Commit 1597162

Browse files
committed
Fix applicable on let-else for convert_to_guarded_return
Example --- ```rust fn foo() -> bool { let$0 Some(x) = Some(2) else { return false }; } ``` **Before this PR**: ```rust fn foo() -> bool { let Some(Some(x)) = Some(2) else { return }; } ``` **After this PR**: Assist not applicable
1 parent 986bb35 commit 1597162

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_to_guarded_return.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn let_stmt_to_guarded_return(
182182
let cursor_in_range =
183183
let_token_range.cover(let_pattern_range).contains_range(ctx.selection_trimmed());
184184

185-
if !cursor_in_range {
185+
if !cursor_in_range || let_stmt.let_else().is_some() {
186186
return None;
187187
}
188188

@@ -911,6 +911,19 @@ fn main() {
911911
);
912912
}
913913

914+
#[test]
915+
fn ignore_let_else_branch() {
916+
check_assist_not_applicable(
917+
convert_to_guarded_return,
918+
r#"
919+
//- minicore: option
920+
fn main() {
921+
let$0 Some(x) = Some(2) else { return };
922+
}
923+
"#,
924+
);
925+
}
926+
914927
#[test]
915928
fn ignore_statements_after_if() {
916929
check_assist_not_applicable(

0 commit comments

Comments
 (0)