Skip to content

fix: do not type match unknown type - #23408

Merged
A4-Tacks merged 2 commits into
rust-lang:masterfrom
A4-Tacks:ty-match-unknown
Sep 25, 2026
Merged

A4-Tacks merged 2 commits into
rust-lang:masterfrom
A4-Tacks:ty-match-unknown

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Example

use core::cmp::max;
struct Matches;
impl Matches { fn opt_present(&self) -> bool {} }
fn test(matches: &Matches) {
    if m$0
}

Before this PR

ex false  [type]
ex true  [type]
fn max(…) fn(T, T) -> T [type_could_unify]
fn min(…) fn(T, T) -> T [type_could_unify+requires_import]
lc matches &Matches [local]
st Matches Matches []
md module::  []
fn test(…) fn(&Matches) []

After this PR

ex false  [type]
ex true  [type]
lc matches &Matches [local]
st Matches Matches []
fn max(…) fn(T, T) -> T []
md module::  []
fn test(…) fn(&Matches) []
fn min(…) fn(T, T) -> T [requires_import]

fn foo() -> Unknown {}
fn test() {
    let unit = ();
    let unknown = unknown;
    let _ = $0;
}

Before this PR

fn foo() fn() -> {unknown} [type]
lc unit () [type_could_unify+local]
fn test() fn() [type_could_unify]

After this PR

lc unit () [local]
fn foo() fn() -> {unknown} []
fn test() fn() []

Example
---
```rust
fn foo() -> Unknown {}
fn test() {
    let unit = ();
    let unknown = unknown;
    let _ = $0;
}
```

**Before this PR**

```text
fn foo() fn() -> {unknown} [type]
lc unit () [type_could_unify+local]
fn test() fn() [type_could_unify]
```

**After this PR**

```text
lc unit () [local]
fn foo() fn() -> {unknown} []
fn test() fn() []
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 23, 2026
}
"#,
expect![[r#"
fn fn_direct_ctr() fn() -> Foo<T> [type_could_unify]

@A4-Tacks A4-Tacks Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test is very strange, should it be Result instead of Res?

View changes since the review

@ChayimFriedman2 ChayimFriedman2 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Error types are really not useful, but generic types are. I wonder if we should give them some score, higher than other types but lower than real match?

Feel free to merge if you don't want to do that (also, not sure exactly how to do that).

View changes since this review

@A4-Tacks

Copy link
Copy Markdown
Member Author

Local variables only have 2 scores, perhaps we can increase 1 score in generic matching?

But I think this is beyond this PR and may not be as important. When someone complains, make improvements

@A4-Tacks
A4-Tacks added this pull request to the merge queue Sep 25, 2026
Merged via the queue into rust-lang:master with commit 28ba14c Sep 25, 2026
20 checks passed
@A4-Tacks
A4-Tacks deleted the ty-match-unknown branch September 25, 2026 03:21
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2026
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.

3 participants