-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Box<Iterator> (and &mut Iterator) does not implement Iterator #20953
Comments
I think the problem is worse than this; trait objects in general don’t seem to be being recognised as implementing their traits: trait Trait { }
fn a(x: &Trait) { try(x); }
fn b(x: &mut Trait) { try(x); }
fn c(x: Box<Trait>) { try(x); }
fn try<T: Trait>(t: T) { }
fn main() { } All three fail:
|
I'm not sure this is a bug at all. You're pretty much asking for an automatic |
This a particular case of #20617. See comments over there. @nikomatsakis is leaning towards an opt-in |
ByRef for trait objects seems to hit the same llvm assertion: fn main() {
struct ByRef<'r, I: ?Sized>(&'r mut I) where I: 'r;
impl<'r, I: ?Sized> Iterator for ByRef<'r, I> where
I: 'r + Iterator
{
type Item = <I as Iterator>::Item;
fn next(&mut self) -> Option<<I as Iterator>::Item>
{
self.0.next()
}
}
let mut it = Box::new(0..10) as Box<Iterator<Item=i32>>;
assert_eq!(it.next(), Some(0));
let mut jt: &mut Iterator<Item=i32> = &mut *it;
assert_eq!(jt.next(), Some(1));
let mut r = ByRef(jt);
assert_eq!(r.next(), Some(2)); // No ICE without this line.
} output:
|
Interesting. So if I have a value with type (Sorry for all the questions. I'm just confused!) |
@BurntSushi doing autoderef on the iterator in |
On Mon, Jan 12, 2015 at 01:33:08PM -0800, Andrew Gallant wrote:
Actually, I believe it works with |
closes rust-lang#20953 closes rust-lang#21361 --- In the future, we will likely derive these `impl`s via syntax extensions or using compiler magic (see rust-lang#20617). For the time being we can use these manual `impl`s. r? @aturon cc @BurntSushi @Kroisse
Just thank you for this issue. It resolves all my problems perfectly! |
This code fails to compile:
error message:
A similar error occurs if
&mut Iterator
is used instead ofBox<Iterator>
. However, if you comment out the for loop, the call tonext
works just fine. I thought maybe it had something to do with auto-deref, so I tried dereferencing the iterator:but
rustc
dumps core:I'm not sure, but this may be related to #20605?
rustc
dumps core when I try&mut Iterator
too.rustc
version:The text was updated successfully, but these errors were encountered: