Skip to content

Issue with impl Trait and panic!() #55022

Closed
@futile

Description

@futile

The following code does not compile on nightly (and 1.29.1 stable) (playground):

fn foo() -> impl Iterator<Item = i32> {
    panic!()
}

I expected this code to compile, but instead I get the following error:

error[E0277]: the trait bound `(): std::iter::Iterator` is not satisfied
 --> src/lib.rs:1:13
  |
1 | fn foo() -> impl Iterator<Item = i32> {
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^ `()` 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

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

This seems like it should work to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.F-never_type`#![feature(never_type)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions