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
This commit is contained in:
A4-Tacks 2025-10-14 14:47:08 +08:00
parent 986bb35e75
commit 1597162eea
No known key found for this signature in database
GPG key ID: DBD861323040663B

View file

@ -182,7 +182,7 @@ fn let_stmt_to_guarded_return(
let cursor_in_range =
let_token_range.cover(let_pattern_range).contains_range(ctx.selection_trimmed());
if !cursor_in_range {
if !cursor_in_range || let_stmt.let_else().is_some() {
return None;
}
@ -911,6 +911,19 @@ fn main() {
);
}
#[test]
fn ignore_let_else_branch() {
check_assist_not_applicable(
convert_to_guarded_return,
r#"
//- minicore: option
fn main() {
let$0 Some(x) = Some(2) else { return };
}
"#,
);
}
#[test]
fn ignore_statements_after_if() {
check_assist_not_applicable(