diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 8ad0c152dc8ed..7965c00a36510 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -18,6 +18,7 @@ use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering}; use core::default::Default; use core::fmt; use core::hash::{self, Hash}; +use core::iter::Iterator; use core::marker::Sized; use core::mem; use core::option::Option; @@ -185,6 +186,20 @@ impl DerefMut for Box { fn deref_mut(&mut self) -> &mut T { &mut **self } } +// FIXME(#21363) remove `old_impl_check` when bug is fixed +#[old_impl_check] +impl<'a, T> Iterator for Box + 'a> { + type Item = T; + + fn next(&mut self) -> Option { + (**self).next() + } + + fn size_hint(&self) -> (usize, Option) { + (**self).size_hint() + } +} + #[cfg(test)] mod test { #[test] diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 811e32e747dfd..47715fe9e5dbe 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -70,6 +70,8 @@ #![feature(lang_items, unsafe_destructor)] #![feature(box_syntax)] #![feature(optin_builtin_traits)] +// FIXME(#21363) remove `old_impl_check` when bug is fixed +#![feature(old_impl_check)] #![allow(unknown_features)] #![feature(int_uint)] #[macro_use] diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 0005db36c278a..2a21ceef7a152 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -99,6 +99,20 @@ pub trait Iterator { fn size_hint(&self) -> (uint, Option) { (0, None) } } +// FIXME(#21363) remove `old_impl_check` when bug is fixed +#[old_impl_check] +impl<'a, T> Iterator for &'a mut (Iterator + 'a) { + type Item = T; + + fn next(&mut self) -> Option { + (**self).next() + } + + fn size_hint(&self) -> (usize, Option) { + (**self).size_hint() + } +} + /// Conversion from an `Iterator` #[stable] #[rustc_on_unimplemented="a collection of type `{Self}` cannot be \ diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 0b150d1ecf90b..f7ba07fd2a68a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -63,6 +63,8 @@ #![feature(unboxed_closures)] #![allow(unknown_features)] #![feature(int_uint)] #![feature(on_unimplemented)] +// FIXME(#21363) remove `old_impl_check` when bug is fixed +#![feature(old_impl_check)] #![deny(missing_docs)] #[macro_use] diff --git a/src/test/run-pass/issue-20953.rs b/src/test/run-pass/issue-20953.rs new file mode 100644 index 0000000000000..647302bbc9304 --- /dev/null +++ b/src/test/run-pass/issue-20953.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let mut shrinker: Box> = Box::new(vec![1].into_iter()); + println!("{:?}", shrinker.next()); + for v in shrinker { assert!(false); } + + let mut shrinker: &mut Iterator = &mut vec![1].into_iter(); + println!("{:?}", shrinker.next()); + for v in shrinker { assert!(false); } +} diff --git a/src/test/run-pass/issue-21361.rs b/src/test/run-pass/issue-21361.rs new file mode 100644 index 0000000000000..bb20b3a321569 --- /dev/null +++ b/src/test/run-pass/issue-21361.rs @@ -0,0 +1,19 @@ +// 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 or the MIT license +// , 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> = Box::new(v.into_iter()); + assert_eq!(boxed.max(), Some(3)); + + let v = vec![1, 2, 3]; + let boxed: &mut Iterator = &mut v.into_iter(); + assert_eq!(boxed.max(), Some(3)); +}