Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0525 should point at where a closure trait obligation was introduced #101157

Closed
estebank opened this issue Aug 29, 2022 · 2 comments
Closed

E0525 should point at where a closure trait obligation was introduced #101157

estebank opened this issue Aug 29, 2022 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given a closure that doesn't fulfill a trait bound, E0525 is emitted but there's no span pointing at where the obligation was introduced:

error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnMut`
  --> src/lib.rs:6:9
   |
6  |         move || {
   |         ^^^^^^^ this closure implements `FnMut`, not `Fn`
7  |             i += 1;
   |             - closure is `FnMut` because it mutates the variable `i` here
...
11 |     is_fn(f);
   |     ----- the requirement to implement `Fn` derives from here

We should point at it, like we already do for E0277:

error[E0277]: expected a `Fn<()>` closure, found `[closure@src/lib.rs:7:31: 7:36]`
 --> src/lib.rs:9:11
  |
9 |     is_fn(f);
  |     ----- ^ expected an `Fn<()>` closure, found `[closure@src/lib.rs:7:31: 7:36]`
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `Fn<()>` is not implemented for `[closure@src/lib.rs:7:31: 7:36]`
  = note: wrap the `[closure@src/lib.rs:7:31: 7:36]` in a closure with no arguments: `|| { /* code */ }`
  = note: `[closure@src/lib.rs:7:31: 7:36]` implements `FnOnce`, but it must implement `Fn`, which is more general
note: required by a bound in `is_fn`
 --> src/lib.rs:2:13
  |
2 | fn is_fn<F: Fn()>(_: F) {}
  |             ^^^^ required by this bound in `is_fn`
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Aug 29, 2022
@compiler-errors
Copy link
Member

compiler-errors commented Aug 29, 2022

@estebank on nightly:

error[[E0525]](https://doc.rust-lang.org/nightly/error-index.html#E0525): expected a closure that implements the `Fn` trait, but this closure only implements `FnMut`
  --> src/lib.rs:6:9
   |
6  |         move || {
   |         ^^^^^^^ this closure implements `FnMut`, not `Fn`
7  |             i += 1;
   |             - closure is `FnMut` because it mutates the variable `i` here
...
11 |     is_fn(f);
   |     ----- - the requirement to implement `Fn` derives from here
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `is_fn`
  --> src/lib.rs:1:13
   |
1  | fn is_fn<F: Fn()>(_: F) {}
   |             ^^^^ required by this bound in `is_fn`

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

Am I missing something? I think the "required by a bound in" was added in #100654.

@estebank
Copy link
Contributor Author

@compiler-errors I could have sworn that I tried it on nightly in the playground 🤦‍♂️

I knew that you'd done something "similar" recently (very similar) which is why this was in my head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants