Description
I recently wrote a type that implemented IntoIterator with a tuple as the Item type. I then tried to test this by using this iterator in a for loop. I got the following error:
for (i, j) in foo
^^^^^^ expected struct `MyIter`, found tuple
This left me confused, because I had assumed that foo's type was MyIter. Why was the iterator returning itself, instead of the item type I had specified? I began to suspect my implementation of IntoIterator before I realized that foo was actually Option<MyIter>
. As it turns out, Option also implements IntoIterator (#27996), so the compiler thought I was trying to iterate over the Option instead of the enclosed type!
It'd be nice if there were a note associated with the compiler error in cases where the iterator is type Option<T : IntoIterator>
. Something like this, maybe?
"Note: `iter` is `Option<MyIter>`. Did you forget to unwrap?"
Simple reproduction of the compiler error: