Closed
Description
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