Skip to content

Tweak output of E0599 to make it less verbose #114430

@estebank

Description

@estebank

Code

struct Foo;
trait Bar {}
trait Baz {}
trait Bat { fn bat(&self); }
impl<T> Bat for T where T: 'static + Bar + Baz { fn bat(&self) { println!("generic bat"); } }

pub fn main() {
    Foo::bat(());
}

Current output

error[E0599]: the function or associated item `bat` exists for struct `Foo`, but its trait bounds were not satisfied
 --> src/main.rs:8:10
  |
1 | struct Foo;
  | ----------
  | |
  | function or associated item `bat` not found for this struct
  | doesn't satisfy `Foo: Bar`
  | doesn't satisfy `Foo: Bat`
  | doesn't satisfy `Foo: Baz`
...
8 |     Foo::bat(());
  |          ^^^ function or associated item cannot be called on `Foo` due to unsatisfied trait bounds
  |
note: the following trait bounds were not satisfied:
      `&Foo: Bar`
      `&Foo: Baz`
      `&mut Foo: Bar`
      `&mut Foo: Baz`
      `Foo: Bar`
      `Foo: Baz`
 --> src/main.rs:5:38
  |
5 | impl<T> Bat for T where T: 'static + Bar + Baz { fn bat(&self) { println!("generic bat"); } }
  |         ---     -                    ^^^   ^^^ unsatisfied trait bound introduced here
  |                                      |
  |                                      unsatisfied trait bound introduced here
note: the traits `Bar` and `Baz` must be implemented
 --> src/main.rs:2:1
  |
2 | trait Bar {}
  | ^^^^^^^^^
3 | trait Baz {}
  | ^^^^^^^^^

Desired output

error[E0599]: the function or associated item `bat` exists for struct `Foo`, but its trait bounds were not satisfied
 --> src/main.rs:8:10
  |
1 | struct Foo;
  | ----------
  | |
  | function or associated item `bat` not found for this struct
  | `Foo` doesn't implement `Bar`, `Bat` or `Baz`
...
8 |     Foo::bat(());
  |          ^^^ function or associated item cannot be called on `Foo` due to unsatisfied trait bounds
  |
note: for `bat` to be available, `Foo` must implement `Bar` and `Baz`
 --> src/main.rs:5:38
  |
5 | impl<T> Bat for T where T: 'static + Bar + Baz { fn bat(&self) { println!("generic bat"); } }
  |         ---     -                    ^^^   ^^^ unsatisfied trait bound introduced here
  |                                      |
  |                                      unsatisfied trait bound introduced here
note: the traits `Bar` and `Baz` must be implemented
 --> src/main.rs:2:1
  |
2 | trait Bar {}
  | ^^^^^^^^^
3 | trait Baz {}
  | ^^^^^^^^^

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

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-verboseDiagnostics: Too much output caused by a single piece of incorrect code.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions