Skip to content

Is it a bug? #72943

Closed
Closed
@heckad

Description

@heckad

I tried this code:

fn get_numbers<T>() -> impl Iterator<Item=Result<i32, String>>
{
    unimplemented!()
}

I expected to see this happen: compile success

Instead, this happened:

error[E0277]: `()` is not an iterator
  --> src\main.rs:68:24
   |
68 | fn get_numbers<T>() -> impl Iterator<Item=Result<i32, String>>
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
69 | {
70 |     unimplemented!()
   |     ---------------- this returned value is of type `!`
   |
   = 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.45.0-nightly (fe10f1a49 2020-06-02)
binary: rustc
commit-hash: fe10f1a49f5ca46e57261b95f46f519523f418fe
commit-date: 2020-06-02
host: x86_64-pc-windows-gnu
release: 1.45.0-nightly
LLVM version: 10.0

If you use templates then compile success.

fn get_numbers<T>() -> T
    where T: Iterator<Item=Result<i32, String>>
{
    unimplemented!()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions