New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"trait is not implemented" error when returning "impl Trait" hides a more useful error #55027

jebrosen opened this Issue Oct 13, 2018 · 0 comments


None yet
2 participants
Copy link

jebrosen commented Oct 13, 2018

This code:

trait Trait { }
struct Oops;
impl Trait for Oops { }

fn make_oops() {

fn make_trait() -> impl Trait {


fails to compile with the following error:

error[E0277]: the trait bound `(): Trait` is not satisfied
 --> src/
8 | fn make_trait() -> impl Trait {
  |                    ^^^^^^^^^^ the trait `Trait` is not implemented for `()`
  = note: the return type of a function must have a statically known size

error: aborting due to previous error

Commenting out the make_trait function reveals this error, which in my opinion is much better:

error[E0308]: mismatched types
 --> src/
5 | fn make_oops() {
  |                - help: try adding a return type: `-> Oops`
6 |     Oops
  |     ^^^^ expected (), found struct `Oops`
  = note: expected type `()`
             found type `Oops`

Apologies if this is a duplicate; I didn't find an issue that looked similar.

Interestingly, using Clone or Debug instead of Trait also reveals the "better" error message. Using and implementing Read in place of Trait still shows the bad error message -- I originally encountered this when trying to return an impl Read.

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