Skip to content

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

Closed
@estebank

Description

@estebank

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions