Skip to content
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

todo!(), unimplemented!(), panic!(), … don't play well with impl Trait #74363

Closed
robinmoussu opened this issue Jul 15, 2020 · 4 comments
Closed
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug.

Comments

@robinmoussu
Copy link

I tried this code:

fn test() -> impl Iterator<Item=f32> {
    todo!()
}

I expected to see this happen: the code should compile (and fails at runtime).

Instead, this happened:

error[E0277]: `()` is not an iterator
 --> src/lib.rs:1:14
  |
1 | fn test() -> impl Iterator<Item=f32> {
  |              ^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
2 |     todo!()
  |     ------- 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

error: aborting due to previous error

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

Note: The issue exists for similar macros: unimplemented, panic, and most probably others that I'm not aware of.


I'm using the following workaround (which obviously works only for iterators, but can be adapted for any kind of object being iterated on):

fn test() -> impl Iterator<Item=f32> {
    const TODO: [f32; 0] = [];
    todo!();
    #[allow(unreachable_code)]
    TODO.iter().cloned()    
}

Note: I'm relatively sure that this issue is known (given how easy it is to reproduce it), but I didn't found it in the bug tracker.

@robinmoussu robinmoussu added the C-bug Category: This is a bug. label Jul 15, 2020
@robinmoussu
Copy link
Author

Should this be added to #63066?

@robinmoussu
Copy link
Author

Consider adding the label A-impl-trait.

@robinmoussu robinmoussu changed the title todo!() and similar macro don't play well with impl Trait todo!(), unimplemented!(), panic!() and similar macros don't play well with impl Trait Jul 15, 2020
@robinmoussu robinmoussu changed the title todo!(), unimplemented!(), panic!() and similar macros don't play well with impl Trait todo!(), unimplemented!(), panic!(), … don't play well with impl Trait Jul 15, 2020
@wesleywiser
Copy link
Member

I believe this is a duplicate of #69882

@Alexendoo Alexendoo added the A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. label Jul 22, 2020
@jonas-schievink
Copy link
Contributor

Yes, closing in favor of #69882

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants