Skip to content

Never type for impl Trait in return position fails to impl trait bound #51001

New issue

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

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

Already on GitHub? # to your account

Closed
Darkspear7 opened this issue May 23, 2018 · 3 comments
Closed

Comments

@Darkspear7
Copy link

From what I understand the "never" type (!) returned by unimplemented!() should satisfy any type constrain but this seems to fail when using impl Trait as a output.

I tried this code:

fn f() -> impl Iterator<Item = usize> {
    unimplemented!()
}
fn main() {}

I expected this to compile.

Instead, this happened:

error[E0277]: the trait bound `(): std::iter::Iterator` is not satisfied
 --> src/main.rs:1:11
  |
1 | fn f() -> impl Iterator<Item = usize> {
  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator; maybe try calling `.iter()` or a similar method
  |
  = help: the trait `std::iter::Iterator` is not implemented for `()`
  = note: the return type of a function must have a statically known size

Meta

$ rustc --version --verbose
rustc 1.28.0-nightly (952f344cd 2018-05-18)
binary: rustc
commit-hash: 952f344cdc0bca58d9f6c54dcfbae0890246e886
commit-date: 2018-05-18
host: x86_64-unknown-linux-gnu
release: 1.28.0-nightly
LLVM version: 6.0
@sfackler
Copy link
Member

That function returns (), not ! as of #50121.

@hanna-kruppe
Copy link
Contributor

But aside from that, this is a known issue that's tricky/impossible to solve: #36375

@Darkspear7
Copy link
Author

Thanks for the quick clarification. My bad regarding the returned value, I should have done my homework better.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants