Skip to content

Conversation

@ada4a
Copy link
Contributor

@ada4a ada4a commented Aug 27, 2025

Fixes #15187

changelog: [ignored_unit_patterns]: include refs in the suggestion

r? @flip1995

@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 27, 2025
@rustbot rustbot assigned flip1995 and unassigned Jarcho Aug 27, 2025
@github-actions
Copy link

Lintcheck changes for 4aaa667

Lint Added Removed Changed
clippy::ignored_unit_patterns 0 0 25

This comment will be updated if you push new changes

let x: (usize, &&&&&()) = (1, &&&&&&());
match x {
(1, ()) => unimplemented!(),
(1, &&&&&()) => unimplemented!(),
Copy link
Member

Choose a reason for hiding this comment

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

Hm, seems like matching () is also valid and the &s are not required. Does that also work (without compiler error) in closures?

Copy link
Contributor Author

@ada4a ada4a Aug 28, 2025

Choose a reason for hiding this comment

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

Well it depends. You're right that the refs are not required in match arms, and they are not required in closures most of the time. But as #15187 shows, it stops working when you try casting the closure to impl Fn(&()), for example.

The solution I tried first was to eliminate all the cases where we know the refs aren't needed (e.g. all match arm patterns), but it now looks like the only case where they are needed are the situations where a closure accepting &() later gets coerced to fn(&())/impl Fn*(&()). Therefore, we could theoretically try catching only those cases, but that will probably require writing some kind of a HIR visitor, and those things are kind of intimidating to me tbh...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Imo the first solution (don't add refs when suggesting for match arms, but do add them for all closure params) is a good balance of simplicity and correctness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it's not even that!

  1. casting/coercing the closure to both an fn and a Fn* trait object works actually just fine

  2. changing anything about the issue's reproducer, like:

    • using the type directly instead of the LifetimeBound type alias
    • replacing dyn with impl in the type alias

    either stops the thing from compiling, or makes it so that () starts getting accepted as well

I guess I'm not well-versed enough in the type system shenanigans to pinpoint the combination of factors that makes this exact expression require &() instead of (). If you have any ideas, let me know (and let me know if you know a way I could test for said factors) -- otherwise, we might want to just close the issue as WONTFIX, given how specific it is?..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flip1995 friendly ping

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.

ignored-unit-patterns suggestion is missing a reference

4 participants