Skip to content

unimplemented!() does not typecheck functions that return impl Trait #72840

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

Closed
BookOwl opened this issue May 31, 2020 · 1 comment
Closed

unimplemented!() does not typecheck functions that return impl Trait #72840

BookOwl opened this issue May 31, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@BookOwl
Copy link

BookOwl commented May 31, 2020

I tried this code:

trait Spam {
    fn eggs(&self) -> u8;
}

fn foo(bar: u8) -> impl Spam {
    unimplemented!();
}

From my reading of the docs for unimplemented!(), this code should typecheck. However, when I try to compile it I get this type error:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `(): Spam` is not satisfied
 --> src/lib.rs:5:20
  |
5 | fn foo(bar: u8) -> impl Spam {
  |                    ^^^^^^^^^ the trait `Spam` is not implemented for `()`
6 |     unimplemented!();
  |     -------- consider removing this semicolon
  |
  = note: the return type of a function must have a statically known size

error: aborting due to previous error

If I remove the semicolon I get this error:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `(): Spam` is not satisfied
 --> src/lib.rs:5:20
  |
5 | fn foo(bar: u8) -> impl Spam {
  |                    ^^^^^^^^^ the trait `Spam` is not implemented for `()`
6 |     unimplemented!()
  |     ---------------- this returned value is of type `!`
  |
  = note: the return type of a function must have a statically known size

error: aborting due to previous error

The same issue happens with the todo!() macro.

Meta

When tested in the playground I get this error in stable 1.43.1, beta, and nightly.
Playground link to example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c62d0cbe9dd4e72fe0aaff17a18b53d0

@BookOwl BookOwl added the C-bug Category: This is a bug. label May 31, 2020
@jonas-schievink
Copy link
Contributor

Duplicate of #69882

@jonas-schievink jonas-schievink marked this as a duplicate of #69882 May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants