Skip to content

Error when concrete type doesn't satisfy impl trait is poorly spanned #80583

Closed
@SNCPlay42

Description

@SNCPlay42
trait Trait {}

fn foo() -> impl Trait {
    0u8
}

Currently emits

error[E0277]: the trait bound `u8: Trait` is not satisfied
 --> src/lib.rs:3:13
  |
3 | fn foo() -> impl Trait {
  |             ^^^^^^^^^^ the trait `Trait` is not implemented for `u8`

It should probably point to the return value as the span of the actual error, with the current span appearing in a note, e.g.

error[E0277]: the trait bound `u8: Trait` is not satisfied
 --> src/lib.rs:4:4
  |
3 | fn foo() -> impl Trait {
  |             ---------- the return value of this function must implement `Trait`
4 |     0u8
  |     ^^^  the trait `Trait` is not implemented for `u8`

@rustbot label T-compiler A-impl-trait A-diagnostics D-terse

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.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