Skip to content

Conversation

@A4-Tacks
Copy link
Member

@A4-Tacks A4-Tacks commented Jan 2, 2026

  • Fix convert_to_guarded_return
  • Fix replace_let_with_if_let
  • Fix replace_if_let_with_match

Example

fn foo() -> &'static Option<i32> {
    &None
}

fn main() {
    let x$0 = foo();
}

Before this PR

Assist not applicable

After this PR

fn foo() -> &'static Option<i32> {
    &None
}

fn main() {
    let Some(x) = foo() else { return };
}

fn main(action: Action) {
    $0let x = compute();
}

fn compute() -> &'static Option<i32> { &None }

Before this PR

fn main(action: Action) {
    if let x = compute() {
    }
}

fn compute() -> &'static Option<i32> { &None }

After this PR

fn main(action: Action) {
    if let Some(x) = compute() {
    }
}

fn compute() -> &'static Option<i32> { &None }

fn foo(x: &Option<i32>) {
    $0if let Some(x) = x {
        println!("{}", x)
    } else {
        println!("none")
    }
}

Before this PR

fn foo(x: &Option<i32>) {
    match x {
        Some(x) => println!("{}", x),
        _ => println!("none"),
    }
}

After this PR

fn foo(x: &Option<i32>) {
    match x {
        Some(x) => println!("{}", x),
        None => println!("none"),
    }
}

- Fix `convert_to_guarded_return`
- Fix `replace_let_with_if_let`
- Fix `replace_if_let_with_match`

Example
---
```rust
fn foo() -> &'static Option<i32> {
    &None
}

fn main() {
    let x$0 = foo();
}
```

**Before this PR**

Assist not applicable

**After this PR**

```rust
fn foo() -> &'static Option<i32> {
    &None
}

fn main() {
    let Some(x) = foo() else { return };
}
```

---

```rust
fn main(action: Action) {
    $0let x = compute();
}

fn compute() -> &'static Option<i32> { &None }
```

**Before this PR**

```rust
fn main(action: Action) {
    if let x = compute() {
    }
}

fn compute() -> &'static Option<i32> { &None }
```

**After this PR**

```rust
fn main(action: Action) {
    if let Some(x) = compute() {
    }
}

fn compute() -> &'static Option<i32> { &None }
```

---

```rust
fn foo(x: &Option<i32>) {
    $0if let Some(x) = x {
        println!("{}", x)
    } else {
        println!("none")
    }
}
```

**Before this PR**

```rust
fn foo(x: &Option<i32>) {
    match x {
        Some(x) => println!("{}", x),
        _ => println!("none"),
    }
}
```

**After this PR**

```rust
fn foo(x: &Option<i32>) {
    match x {
        Some(x) => println!("{}", x),
        None => println!("none"),
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants