Skip to content

Suggest wrapping in a closure instead of call parens when a method is passed where an Fn callable is expected - #162185

Open
Yogeshwaran-Projects wants to merge 1 commit into
rust-lang:mainfrom
Yogeshwaran-Projects:rock/e0615-closure-sugg
Open

Yogeshwaran-Projects wants to merge 1 commit into
rust-lang:mainfrom
Yogeshwaran-Projects:rock/e0615-closure-sugg

Conversation

@Yogeshwaran-Projects

@Yogeshwaran-Projects Yogeshwaran-Projects commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #162033
When an uncalled method is passed where an Fn callable is expected, E0615's "use parentheses to call the method" help leads into a second error — this instead suggests wrapping it in a closure (call(|| foo.print())) falling through to the old suggestion everywhere else.

Before:

error[E0615]: attempted to take value of method `print` on type `FooPrinter`
  --> src/main.rs:21:28
   |
21 |     call(FooPrinter::new().print);
   |                            ^^^^^ method, not a field
   |
help: use parentheses to call the method
   |
21 |     call(FooPrinter::new().print());
   |                                 ++

For more information about this error, try `rustc --explain E0615`.

After:

error[E0615]: attempted to take value of method `print` on type `FooPrinter`
  --> $DIR/method-value-expected-fn-arg.rs:20:28
   |
LL |     call(FooPrinter::new().print);
   |                            ^^^^^ method, not a field
   |
help: consider wrapping the method call in a closure
   |
LL |     call(|| FooPrinter::new().print());
   |          ++                        ++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0615`.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 2, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @TaKO8Ki (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 21 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.

unhelpful error when giving an instance method to a generic function requiring a function

3 participants