Change:
This code fails to compile: error message: A similar error occurs if is used instead of . However, if you comment out the for loop, the call to works just fine. I thought maybe it had something to do with auto-deref, so I tried dereferencing the iterator: but dumps core: I'm not sure, but this may be related to ? dumps core when I try too. version:
CC
I think the problem is worse than this; trait objects in general don’t seem to be being recognised as implementing their traits: All three fail:
I'm not sure this is a bug at all. You're pretty much asking for an automatic - I did come up with a & -based model that would kinda work for this and IIRC pointed out that object-safe traits would eventually qualify for this. We do have object safety now, so it might be doable, but I wouldn't bet on it making into 1.0. In the meanwhile, does work? If it doesn't, is it just the case of missing in a couple places?
This a particular case of . See comments over there. is leaning towards an opt-in syntax extension that handles the boiler plate code, instead of automatic s by the compiler.
ByRef for trait objects seems to hit the same llvm assertion: output:
Interesting. So if I have a value with type where is a trait, then we can't say that implements in the general case? (Assuming object safety.) So my guess is that can still call because of auto deref? Shouldn't that mean it can work with ? Maybe that is what is about... You have to explicitly deref a to use it in ? (Sorry for all the questions. I'm just confused!)
doing autoderef on the iterator in seems like something reasonable to have. looks like the compiler is mistakenly treating an unsized lvalue as an rvalue, in trans.
On Mon, Jan 12, 2015 at 01:33:08PM -0800, Andrew Gallant wrote: Actually, I believe it works with , but not with the other types.
Just thank you for this issue. It resolves all my problems perfectly!

Discussion:
use core::default::Default; use core::fmt; use core::hash::{self, Hash}; <ins> use core::iter::Iterator; </ins> use core::marker::Sized; use core::mem; use core::option::Option;

fn deref_mut(&mut self) -> &mut T { &mut **self } } <ins> // FIXME(#21363) remove `old_impl_check` when bug is fixed #[old_impl_check] impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> { type Item = T; fn next(&mut self) -> Option<T> { (**self).next() } fn size_hint(&self) -> (usize, Option<usize>) { (**self).size_hint() } } </ins> #[cfg(test)] mod test { #[test]

#![feature(lang_items, unsafe_destructor)] #![feature(box_syntax)] #![feature(optin_builtin_traits)] <ins> // FIXME(#21363) remove `old_impl_check` when bug is fixed #![feature(old_impl_check)] </ins> #![allow(unknown_features)] #![feature(int_uint)] #[macro_use]

fn size_hint(&self) -> (uint, Option<uint>) { (0, None) } } <ins> // FIXME(#21363) remove `old_impl_check` when bug is fixed #[old_impl_check] impl<'a, T> Iterator for &'a mut (Iterator<Item=T> + 'a) { type Item = T; fn next(&mut self) -> Option<T> { (**self).next() } fn size_hint(&self) -> (usize, Option<usize>) { (**self).size_hint() } } </ins> /// Conversion from an `Iterator` #[stable] #[rustc_on_unimplemented="a collection of type `{Self}` cannot be 

#![feature(unboxed_closures)] #![allow(unknown_features)] #![feature(int_uint)] #![feature(on_unimplemented)] <ins> // FIXME(#21363) remove `old_impl_check` when bug is fixed #![feature(old_impl_check)] </ins> #![deny(missing_docs)] #[macro_use]

<ins> // Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn main() { let mut shrinker: Box<Iterator<Item=i32>> = Box::new(vec![1].into_iter()); println!("{:?}", shrinker.next()); for v in shrinker { assert!(false); } let mut shrinker: &mut Iterator<Item=i32> = &mut vec![1].into_iter(); println!("{:?}", shrinker.next()); for v in shrinker { assert!(false); } } </ins>

<ins> // Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn main() { let v = vec![1, 2, 3]; let boxed: Box<Iterator<Item=i32>> = Box::new(v.into_iter()); assert_eq!(boxed.max(), Some(3)); let v = vec![1, 2, 3]; let boxed: &mut Iterator<Item=i32> = &mut v.into_iter(); assert_eq!(boxed.max(), Some(3)); } </ins>