Skip to content

Point at unit structs on foreign crates in type errors when they are the pattern of a binding#153894

Open
estebank wants to merge 2 commits intorust-lang:mainfrom
estebank:issue-129792
Open

Point at unit structs on foreign crates in type errors when they are the pattern of a binding#153894
estebank wants to merge 2 commits intorust-lang:mainfrom
estebank:issue-129792

Conversation

@estebank
Copy link
Contributor

@estebank estebank commented Mar 15, 2026

Consts and unit structs in patterns can be confusing if they are mistaken for new bindings. We already provide some context for unit structs and consts that come from the current crate, we now also point at those from foreign crates, and we properly skip cases where the pattern has type parameters which can't be confused with a new binding. Make new binding suggestion verbose.

Fix #129792.

error[E0308]: mismatched types
   --> tests/ui/suggestions/suggest-deref-in-match-issue-132784.rs:76:9
    |
 71 |     match y_mut {
    |           ----- this expression has type `&mut Box<Option<i32>>`
...
 76 |         None => {}
    |         ^^^^
    |         |
    |         expected `Box<Option<i32>>`, found `Option<_>`
    |         `None` is interpreted as a unit variant, not a new binding
    |
   ::: library/core/src/option.rs:604:5
    |
604 |     None,
    |     ---- unit variant defined here
    |
    = note: expected struct `Box<Option<i32>>`
                 found enum `Option<_>`
help: consider dereferencing to access the inner value using the Deref trait
    |
 71 |     match &**y_mut {
    |           +++
help: introduce a new binding instead
    |
 76 -         None => {}
 76 +         other_none => {}
    |

…the pattern of a let binding

Consts and unit structs in patterns can be confusing if they are mistaken for new bindings. We already provide some context for unit structs and consts that come from the current crate, we now also point at those from foreign crates, and we properly skip cases where the pattern has type parameters which can't be confused with a new binding. Make new binding suggestion verbose.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

@estebank estebank changed the title Point at unit structs on foreign crates in type errors when they are … Point at unit structs on foreign crates in type errors when they are the pattern of a let binding Mar 15, 2026
@estebank estebank changed the title Point at unit structs on foreign crates in type errors when they are the pattern of a let binding Point at unit structs on foreign crates in type errors when they are the pattern of a binding Mar 15, 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Point at unit structs in type errors when they are the pattern of a let binding

3 participants