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.
I tried this code:
I expected to see this happen: the code should compile (and fails at runtime).
Instead, this happened:
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):
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.