Skip to content

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

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.

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    P-lowLow priority
    D-papercutDiagnostics: An error or lint that needs small tweaks.
    on Dec 14, 2019
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Dec 14, 2019
  3. Centril commented on Dec 14, 2019

    @Centril
    Contributor
  4. estebank commented on Dec 14, 2019

    @estebank
    Contributor

    What are some appropriate wordings? fn signature? fn? fn type? Revert this one back to just type?

  5. oli-obk commented on Dec 14, 2019

    @oli-obk
    ContributorAuthor

    Maybe without any descriptive word?

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

    Is there any particular reason we're displaying the note at all? In the examples I was able to coax out of the compiler the main message was the part that was helpful, the note was just redundant.

  6. estebank commented on Dec 15, 2019

    @estebank
    Contributor

    This used to be "expected type" which was also confusing when showing things that weren't really something that people associated with types, so it's using the TyKind description now. We could remove it entirely, but I find that having a small level of redundancy in our wording can help introduce and teach concepts to new users. This is why when I saw this I didn't change this to something like "function", but I'm really happy you opened this conversation.

  7. oli-obk commented on Dec 15, 2019

    @oli-obk
    ContributorAuthor

    This used to be "expected type"

    Yea that was quite suboptimal

    We could remove it entirely, but I find that having a small level of redundancy in our wording can help introduce and teach concepts to new users

    Right, having different verbosity levels for different experience levels is a different discussion, so: more verbosity is better for now. What do you think about

      = note: expected function with signature `fn(&())`
                 found function with signature `fn(())`
    

    or does that get too long for complex signatures?

  8. estebank commented on Dec 15, 2019

    @estebank
    Contributor

    It makes sense but seems a bit long, I wonder if we can simultaneously make it shorter and less "jargony" by doing something like (for fn pointers specifically):

      = note: expected function like `fn(&())`
                 found function like `fn(())`
    
  9. oli-obk commented on Dec 15, 2019

    @oli-obk
    ContributorAuthor

    Oh yea, that's good

  10. compiler-errors commented on Jan 7, 2023

    @compiler-errors
    Contributor

    Original problem is fixed by #106131, not sure about the rest of the discussion but probably should be moved to a different issue.

  11. added 2 commits that reference this issue on Jan 9, 2023
    2c6368f
    6afd161
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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