Skip to content

Fix some TryEnum reference assists#21389

Merged
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
A4-Tacks:assist-try-enum-ref
Feb 20, 2026
Merged

Fix some TryEnum reference assists#21389
ChayimFriedman2 merged 2 commits intorust-lang:masterfrom
A4-Tacks:assist-try-enum-ref

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"), } }
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 2, 2026
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could maybe benefit from a more structured approach to match ergonomics in IDE, but this is good enough as is IMO.

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Feb 12, 2026
@ChayimFriedman2 ChayimFriedman2 removed this pull request from the merge queue due to a manual request Feb 12, 2026
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think I prefer to put the strip_references() in TryEnum::from_ty().

@A4-Tacks
Copy link
Member Author

Actually, I think I prefer to put the strip_references() in TryEnum::from_ty().

I'm not sure if it will damage crates/ide-assists/src/handlers/desugar_try_expr.rs

Can I extract a method like from_ty_without_strip()?

@A4-Tacks A4-Tacks force-pushed the assist-try-enum-ref branch 2 times, most recently from 6b1a12d to 5340840 Compare February 19, 2026 02:33
- Fix `convert_to_guarded_return` - Fix `replace_let_with_if_let` - Fix `replace_if_let_with_match`
@A4-Tacks A4-Tacks force-pushed the assist-try-enum-ref branch from 5340840 to 1a1b624 Compare February 19, 2026 02:43
@ChayimFriedman2
Copy link
Contributor

I actually think it's good even there. True, ? is not valid with references, but it can make life easier for people and can't hurt.

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Feb 20, 2026
Merged via the queue into rust-lang:master with commit 46a214b Feb 20, 2026
16 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 20, 2026
@A4-Tacks A4-Tacks deleted the assist-try-enum-ref branch February 21, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants