Skip to content

Incompatible type error should explain when types come from default type parameters #67991

Description

@varkor
trait Trait<T = ()> {
    fn foo() -> T;
}

struct S;

impl Trait for S {
    fn foo() -> u32 { 0 }
}

produces:

error[E0053]: method `foo` has an incompatible type for trait
  --> src/lib.rs:28:17
   |
22 |     fn foo() -> T;
   |                 - type in trait
...
28 |     fn foo() -> u32 { 0 }
   |                 ^^^ expected `()`, found `u32`
   |
   = note: expected fn pointer `fn()`
              found fn pointer `fn() -> u32`

The diagnostic doesn't point out why T is (), which comes from the default type parameter. It would be helpful to explain this, as it may not be immediately apparent.

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.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