]> git.lizzy.rs Git - rust.git/commitdiff
impl Iterator for &mut Iterator and Box<Iterator>
authorJorge Aparicio <japaricious@gmail.com>
Mon, 19 Jan 2015 14:48:05 +0000 (09:48 -0500)
committerJorge Aparicio <japaricious@gmail.com>
Mon, 19 Jan 2015 15:41:07 +0000 (10:41 -0500)
closes #20953
closes #21361

src/liballoc/boxed.rs
src/liballoc/lib.rs
src/libcore/iter.rs
src/libcore/lib.rs
src/test/run-pass/issue-20953.rs [new file with mode: 0644]
src/test/run-pass/issue-21361.rs [new file with mode: 0644]

index 8ad0c152dc8ed61a5758a35148f46556f161bf6d..89de2c953e4c2f6280a7397f3ca5418f687d4b2f 100644 (file)
@@ -18,6 +18,7 @@
 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,16 @@ impl<T: ?Sized> DerefMut for Box<T> {
     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<Iterator<Item=T> + 'a> {
+    type Item = T;
+
+    fn next(&mut self) -> Option<T> {
+        (**self).next()
+    }
+}
+
 #[cfg(test)]
 mod test {
     #[test]
index 811e32e747dfd194f29e85dbc95f598fdd878cb6..47715fe9e5dbe087babeb9b22a7efc55eea53577 100644 (file)
@@ -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]
index 0005db36c278a2ef78970551deea9705bfac4693..3d51f75d9b3097081c56cfe078f1b0dec10e4660 100644 (file)
@@ -99,6 +99,16 @@ pub trait Iterator {
     fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
 }
 
+// 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()
+    }
+}
+
 /// Conversion from an `Iterator`
 #[stable]
 #[rustc_on_unimplemented="a collection of type `{Self}` cannot be \
index 0b150d1ecf90bd9c7358593446f75f5f06b7761e..f7ba07fd2a68a1a9ae6c0b1e3a61c90b26eeb713 100644 (file)
@@ -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 (file)
index 0000000..647302b
--- /dev/null
@@ -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 <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); }
+}
diff --git a/src/test/run-pass/issue-21361.rs b/src/test/run-pass/issue-21361.rs
new file mode 100644 (file)
index 0000000..bb20b3a
--- /dev/null
@@ -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 <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));
+}