Skip to content

Diagnostics talk about fn pointer when no pointers are in the source #67296

Closed
@oli-obk

Description

@oli-obk

Trait function API mismatches (where the impl differs from the declaration) report the correct error about the mismatch, but also give a more detailed note like

  = note: expected fn pointer `fn(&())`
             found fn pointer `fn(())`

This could cause some confusion as the user hasn't done anything with function pointers.

trait Foo {
    fn foo(&self);
}

impl Foo for () {
    fn foo(self) {}
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0053]: method `foo` has an incompatible type for trait
 --> src/lib.rs:6:12
  |
2 |     fn foo(&self);
  |            ----- type in trait
...
6 |     fn foo(self) {}
  |            ^^^^ expected `&()`, found `()`
  |
  = note: expected fn pointer `fn(&())`
             found fn pointer `fn(())`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0053`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-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