Skip to content

Fix tuple struct pat expected type#21333

Merged
Veykril merged 1 commit intorust-lang:masterfrom
A4-Tacks:expected-tuple-struct-pat
Mar 20, 2026
Merged

Fix tuple struct pat expected type#21333
Veykril merged 1 commit intorust-lang:masterfrom
A4-Tacks:expected-tuple-struct-pat

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

Example

struct Foo(Option<i32>);
fn foo(x: Foo) -> Foo {
   match x { Foo($0) => () }
}

Before this PR

ty: Foo, name: ?

After this PR

ty: Option<i32>, name: ?

Example
---
```rust
struct Foo(Option<i32>);
fn foo(x: Foo) -> Foo {
   match x { Foo($0) => () }
}
```

**Before this PR**

```rust
ty: Foo, name: ?
```

**After this PR**

```rust
ty: Option<i32>, name: ?
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 25, 2025
@ChayimFriedman2
Copy link
Copy Markdown
Contributor

I'm really not pleased with the ways the expected type inference in completion is going. We're essentially duplicating the entire logic of type inference. I don't think that's sustainable.

We need to find a better way, and I hesitate to merge more PRs in this area until we have a plan. A possible half-solution is to wait for speculative execution, then query the type of the inserted identifier.

@rust-lang/rust-analyzer thoughts?

@lnicola
Copy link
Copy Markdown
Member

lnicola commented Dec 25, 2025

Sounds like a good idea, but I think we can merge this one since A4-Tacks already did the work and it's not very complex.

@A4-Tacks
Copy link
Copy Markdown
Member Author

then query the type of the inserted identifier.

Is inference on the modified syntax tree beneficial for caching?

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

No, it is beneficial for completion (only possible when Salsa will gain speculative execution).

@A4-Tacks
Copy link
Copy Markdown
Member Author

Can this PR be merged now?

@A4-Tacks
Copy link
Copy Markdown
Member Author

This bug quite affects the user experience. I often type Some(a$0) and backspace

Similar tuple also has this bug, but the frequency of encountering it is far lower than this

@Veykril Veykril added this pull request to the merge queue Mar 20, 2026
Merged via the queue into rust-lang:master with commit 721a1c5 Mar 20, 2026
15 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 20, 2026
@A4-Tacks A4-Tacks deleted the expected-tuple-struct-pat branch March 20, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants