Skip to content

unimplemented!() doesn't work with return impl #81518

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
crone123 opened this issue Jan 29, 2021 · 1 comment
Closed

unimplemented!() doesn't work with return impl #81518

crone123 opened this issue Jan 29, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@crone123
Copy link

Hello,
I tried this code:

fn test() -> impl Fn(i32) -> i32
{
    unimplemented!()
}

Or this code:

fn test() -> impl Display
{
    unimplemented!()
}

I expected to see this happen: Compilation works, but panic with unimplemented at runtime.

Instead, this happened: Unable to compile, I got these errors:

error[E0277]: expected a `Fn<(i32,)>` closure, found `()`
 --> bug.rs:1:14
  |
1 | fn test() -> impl Fn(i32) -> i32
  |              ^^^^^^^^^^^^^^^^^^^ expected an `Fn<(i32,)>` closure, found `()`
  |
  = help: the trait `Fn<(i32,)>` is not implemented for `()`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error[E0277]: `()` doesn't implement `std::fmt::Display`
 --> bug.rs:6:14
  |
6 | fn test() -> impl Display
  |              ^^^^^^^^^^^^ `()` cannot be formatted with the default formatter
  |
  = help: the trait `std::fmt::Display` is not implemented for `()`
  = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

In theory, unimplemented!() dosen't return, and just panic, so the type problem is not to be solved. And this is the purpose of unimplemented, to let functions.... unimplemented... just a draft... if we need to implements unimplemented functions.... they become implemented....

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (44e3daf5e 2020-12-31)
binary: rustc
commit-hash: 44e3daf5eee8263dfc3a2509e78ddd1f6f783a0e
commit-date: 2020-12-31
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Thank you :)

@crone123 crone123 added the C-bug Category: This is a bug. label Jan 29, 2021
@memoryruins
Copy link
Contributor

Thanks for reporting! This is a duplicate of #36375

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

3 participants