Skip to content

Commit f4beb80

Browse files
authored
Merge pull request rust-lang#20838 from A4-Tacks/conv-to-guard-ret-exist-else
Fix applicable on let-else for convert_to_guarded_return
2 parents 4cb250b + 1597162 commit f4beb80

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)