Skip to content

Avoid misleading return-type note for foreign Fn callees#155877

Open
qaijuang wants to merge 1 commit intorust-lang:mainfrom
qaijuang:fix-155727-fnmut-diagnostic
Open

Avoid misleading return-type note for foreign Fn callees#155877
qaijuang wants to merge 1 commit intorust-lang:mainfrom
qaijuang:fix-155727-fnmut-diagnostic

Conversation

@qaijuang
Copy link
Copy Markdown
Contributor

@qaijuang qaijuang commented Apr 27, 2026

Fixes #155727.

The issue occurred because the code that emitted the Fn/FnMut suggestion only avoided the return-type fallback when it could point at a local callee argument. The local case from #125325 was fixed in #126226, but nested cross-crate cases could still suggest changing the enclosing function's return type even though the relevant Fn requirement came from the callee argument.

This is also the broader diagnostic shape discussed in #119985.

This PR checks the instantiated callee predicates for an exact Fn bound
on the closure argument, and extends wrong-closure-arg-suggestion-125325 with cross-crate function and method cases for that path.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 27, 2026
@qaijuang
Copy link
Copy Markdown
Contributor Author

cc @rustily-indecisive

@qaijuang qaijuang marked this pull request as ready for review April 27, 2026 17:44
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 27, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 27, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 27, 2026

r? @wesleywiser

rustbot has assigned @wesleywiser.
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 73 candidates
  • Random selection from 20 candidates

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.

E0594 suggests changing an unrelated return type when assigning to a captured variable in a nested Fn closure

3 participants