Skip to content

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

@Darkspear7

Description

@Darkspear7

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions