Skip to content

Commit 9227db3

Browse files
committed
rollup merge of #21392: japaric/iter
closes #20953 closes #21361 --- In the future, we will likely derive these `impl`s via syntax extensions or using compiler magic (see #20617). For the time being we can use these manual `impl`s. r? @aturon cc @BurntSushi @Kroisse
2 parents ad2c3e8 + 00cddb0 commit 9227db3

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

src/liballoc/boxed.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
1818
use core::default::Default;
1919
use core::fmt;
2020
use core::hash::{self, Hash};
21+
use core::iter::Iterator;
2122
use core::marker::Sized;
2223
use core::mem;
2324
use core::option::Option;
@@ -187,6 +188,20 @@ impl<T: ?Sized> DerefMut for Box<T> {
187188
fn deref_mut(&mut self) -> &mut T { &mut **self }
188189
}
189190

191+
// FIXME(#21363) remove `old_impl_check` when bug is fixed
192+
#[old_impl_check]
193+
impl<'a, T> Iterator for Box<Iterator<Item=T> + 'a> {
194+
type Item = T;
195+
196+
fn next(&mut self) -> Option<T> {
197+
(**self).next()
198+
}
199+
200+
fn size_hint(&self) -> (usize, Option<usize>) {
201+
(**self).size_hint()
202+
}
203+
}
204+
190205
#[cfg(test)]
191206
mod test {
192207
#[test]

src/liballoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@
7070
#![feature(lang_items, unsafe_destructor)]
7171
#![feature(box_syntax)]
7272
#![feature(optin_builtin_traits)]
73+
// FIXME(#21363) remove `old_impl_check` when bug is fixed
74+
#![feature(old_impl_check)]
7375
#![allow(unknown_features)] #![feature(int_uint)]
7476

7577
#[macro_use]

src/libcore/iter.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ pub trait Iterator {
9999
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
100100
}
101101

102+
// FIXME(#21363) remove `old_impl_check` when bug is fixed
103+
#[old_impl_check]
104+
impl<'a, T> Iterator for &'a mut (Iterator<Item=T> + 'a) {
105+
type Item = T;
106+
107+
fn next(&mut self) -> Option<T> {
108+
(**self).next()
109+
}
110+
111+
fn size_hint(&self) -> (usize, Option<usize>) {
112+
(**self).size_hint()
113+
}
114+
}
115+
102116
/// Conversion from an `Iterator`
103117
#[stable]
104118
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be \

src/libcore/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#![feature(unboxed_closures)]
6464
#![allow(unknown_features)] #![feature(int_uint)]
6565
#![feature(on_unimplemented)]
66+
// FIXME(#21363) remove `old_impl_check` when bug is fixed
67+
#![feature(old_impl_check)]
6668
#![deny(missing_docs)]
6769

6870
#[macro_use]

src/test/run-pass/issue-20953.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let mut shrinker: Box<Iterator<Item=i32>> = Box::new(vec![1].into_iter());
13+
println!("{:?}", shrinker.next());
14+
for v in shrinker { assert!(false); }
15+
16+
let mut shrinker: &mut Iterator<Item=i32> = &mut vec![1].into_iter();
17+
println!("{:?}", shrinker.next());
18+
for v in shrinker { assert!(false); }
19+
}

src/test/run-pass/issue-21361.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let v = vec![1, 2, 3];
13+
let boxed: Box<Iterator<Item=i32>> = Box::new(v.into_iter());
14+
assert_eq!(boxed.max(), Some(3));
15+
16+
let v = vec![1, 2, 3];
17+
let boxed: &mut Iterator<Item=i32> = &mut v.into_iter();
18+
assert_eq!(boxed.max(), Some(3));
19+
}

0 commit comments

Comments
 (0)