Skip to content

Commit 2611a77

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 177655 b: refs/heads/tmp c: f9865ea h: refs/heads/master i: 177653: 0988755 177651: 59cb2c8 177647: 9bedeb5 v: v3
1 parent a33512d commit 2611a77

File tree

32 files changed

+119
-44
lines changed

32 files changed

+119
-44
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 44a287e6eb22ec3c2a687fc156813577464017f7
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 9fdc0effd292b097ae487ec4d927ca15102c5791
37+
refs/heads/tmp: f9865eac185ef2af4df661442d5d3bd2698b725f

branches/tmp/src/doc/trpl/unsafe.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,10 @@ extern fn panic_fmt(args: &core::fmt::Arguments,
576576
#[lang = "eh_personality"] extern fn eh_personality() {}
577577
# #[start] fn start(argc: isize, argv: *const *const u8) -> isize { 0 }
578578
# fn main() {}
579+
# mod std { // for-loops
580+
# pub use core::iter;
581+
# pub use core::option;
582+
# }
579583
```
580584

581585
Note that there is one extra lang item here which differs from the examples

branches/tmp/src/libcollections/bit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ type MatchWords<'a> = Chain<Enumerate<Blocks<'a>>, Skip<Take<Enumerate<Repeat<u3
104104

105105
fn reverse_bits(byte: u8) -> u8 {
106106
let mut result = 0;
107-
for i in 0..u8::BITS {
107+
// FIXME(#21245) use a for loop
108+
let mut iter = 0..u8::BITS;
109+
while let Some(i) = iter.next() {
108110
result |= ((byte >> i) & 1) << (u8::BITS - 1 - i);
109111
}
110112
result

branches/tmp/src/libcollections/btree/node.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<T> DoubleEndedIterator for RawItems<T> {
271271
#[unsafe_destructor]
272272
impl<T> Drop for RawItems<T> {
273273
fn drop(&mut self) {
274-
for _ in *self {}
274+
for _ in self.by_ref() {}
275275
}
276276
}
277277

@@ -1374,9 +1374,9 @@ impl<K, V> Drop for MoveTraversalImpl<K, V> {
13741374
fn drop(&mut self) {
13751375
// We need to cleanup the stored values manually, as the RawItems destructor would run
13761376
// after our deallocation.
1377-
for _ in self.keys {}
1378-
for _ in self.vals {}
1379-
for _ in self.edges {}
1377+
for _ in self.keys.by_ref() {}
1378+
for _ in self.vals.by_ref() {}
1379+
for _ in self.edges.by_ref() {}
13801380

13811381
let (alignment, size) =
13821382
calculate_allocation_generic::<K, V>(self.capacity, self.is_leaf);

branches/tmp/src/libcollections/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#![feature(unicode)]
3535
#![feature(hash)]
3636
#![cfg_attr(test, feature(test))]
37+
// NOTE(stage0): remove after a snapshot
38+
#![cfg_attr(not(stage0), allow(unused_mut))]
3739

3840
#[macro_use]
3941
extern crate core;
@@ -114,6 +116,8 @@ mod std {
114116
pub use core::marker; // derive(Copy)
115117
pub use core::hash; // derive(Hash)
116118
pub use core::ops; // RangeFull
119+
// for-loops
120+
pub use core::iter;
117121
}
118122

119123
#[cfg(test)]

branches/tmp/src/libcollections/ring_buf.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ pub struct Drain<'a, T: 'a> {
15101510
#[stable(feature = "rust1", since = "1.0.0")]
15111511
impl<'a, T: 'a> Drop for Drain<'a, T> {
15121512
fn drop(&mut self) {
1513-
for _ in *self {}
1513+
for _ in self.by_ref() {}
15141514
self.inner.head = 0;
15151515
self.inner.tail = 0;
15161516
}
@@ -1793,7 +1793,9 @@ mod tests {
17931793
fn bench_push_back_100(b: &mut test::Bencher) {
17941794
let mut deq = RingBuf::with_capacity(101);
17951795
b.iter(|| {
1796-
for i in 0i..100 {
1796+
// FIXME(#21245) use a for loop
1797+
let mut iter = 0i..100;
1798+
while let Some(i) = iter.next() {
17971799
deq.push_back(i);
17981800
}
17991801
deq.head = 0;
@@ -1805,7 +1807,9 @@ mod tests {
18051807
fn bench_push_front_100(b: &mut test::Bencher) {
18061808
let mut deq = RingBuf::with_capacity(101);
18071809
b.iter(|| {
1808-
for i in 0i..100 {
1810+
// FIXME(#21245) use a for loop
1811+
let mut iter = 0i..100;
1812+
while let Some(i) = iter.next() {
18091813
deq.push_front(i);
18101814
}
18111815
deq.head = 0;

branches/tmp/src/libcollections/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ mod tests {
19581958
let mut amt = 0;
19591959
let mut it = v.permutations();
19601960
let (min_size, max_opt) = it.size_hint();
1961-
for _perm in it {
1961+
for _perm in it.by_ref() {
19621962
amt += 1;
19631963
}
19641964
assert_eq!(amt, it.swaps.swaps_made);

branches/tmp/src/libcollections/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'a> Iterator for Recompositions<'a> {
279279
loop {
280280
match self.state {
281281
Composing => {
282-
for ch in self.iter {
282+
for ch in self.iter.by_ref() {
283283
let ch_class = unicode::char::canonical_combining_class(ch);
284284
if self.composee.is_none() {
285285
if ch_class != 0 {

branches/tmp/src/libcollections/vec.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,9 @@ impl<T> Drop for Vec<T> {
15671567
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
15681568
if self.cap != 0 {
15691569
unsafe {
1570-
for x in self.iter() {
1570+
// FIXME(#21245) use a for loop
1571+
let mut iter = self.iter();
1572+
while let Some(x) = iter.next() {
15711573
ptr::read(x);
15721574
}
15731575
dealloc(*self.ptr, self.cap)
@@ -1648,7 +1650,7 @@ impl<T> IntoIter<T> {
16481650
#[unstable(feature = "collections")]
16491651
pub fn into_inner(mut self) -> Vec<T> {
16501652
unsafe {
1651-
for _x in self { }
1653+
for _x in self.by_ref() { }
16521654
let IntoIter { allocation, cap, ptr: _ptr, end: _end } = self;
16531655
mem::forget(self);
16541656
Vec { ptr: NonZero::new(allocation), cap: cap, len: 0 }
@@ -1726,7 +1728,7 @@ impl<T> Drop for IntoIter<T> {
17261728
fn drop(&mut self) {
17271729
// destroy the remaining elements
17281730
if self.cap != 0 {
1729-
for _x in *self {}
1731+
for _x in self.by_ref() {}
17301732
unsafe {
17311733
dealloc(self.allocation, self.cap);
17321734
}
@@ -1816,7 +1818,7 @@ impl<'a, T> Drop for Drain<'a, T> {
18161818
// so we can use #[unsafe_no_drop_flag].
18171819

18181820
// destroy the remaining elements
1819-
for _x in *self {}
1821+
for _x in self.by_ref() {}
18201822
}
18211823
}
18221824

branches/tmp/src/libcore/iter.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub trait IteratorExt: Iterator + Sized {
195195
#[inline]
196196
#[stable(feature = "rust1", since = "1.0.0")]
197197
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
198-
for x in *self {
198+
for x in self.by_ref() {
199199
if n == 0 { return Some(x) }
200200
n -= 1;
201201
}
@@ -492,7 +492,7 @@ pub trait IteratorExt: Iterator + Sized {
492492
/// fn process<U: Iterator<Item=isize>>(it: U) -> isize {
493493
/// let mut it = it.fuse();
494494
/// let mut sum = 0;
495-
/// for x in it {
495+
/// for x in it.by_ref() {
496496
/// if x > 5 {
497497
/// break;
498498
/// }
@@ -660,7 +660,7 @@ pub trait IteratorExt: Iterator + Sized {
660660
#[inline]
661661
#[stable(feature = "rust1", since = "1.0.0")]
662662
fn any<F>(&mut self, mut f: F) -> bool where F: FnMut(Self::Item) -> bool {
663-
for x in *self { if f(x) { return true; } }
663+
for x in self.by_ref() { if f(x) { return true; } }
664664
false
665665
}
666666

@@ -680,7 +680,7 @@ pub trait IteratorExt: Iterator + Sized {
680680
fn find<P>(&mut self, mut predicate: P) -> Option<Self::Item> where
681681
P: FnMut(&Self::Item) -> bool,
682682
{
683-
for x in *self {
683+
for x in self.by_ref() {
684684
if predicate(&x) { return Some(x) }
685685
}
686686
None
@@ -703,7 +703,7 @@ pub trait IteratorExt: Iterator + Sized {
703703
P: FnMut(Self::Item) -> bool,
704704
{
705705
let mut i = 0;
706-
for x in *self {
706+
for x in self.by_ref() {
707707
if predicate(x) {
708708
return Some(i);
709709
}
@@ -1664,7 +1664,7 @@ impl<A, I, P> Iterator for Filter<A, I, P> where I: Iterator<Item=A>, P: FnMut(&
16641664

16651665
#[inline]
16661666
fn next(&mut self) -> Option<A> {
1667-
for x in self.iter {
1667+
for x in self.iter.by_ref() {
16681668
if (self.predicate)(&x) {
16691669
return Some(x);
16701670
} else {
@@ -1728,7 +1728,7 @@ impl<A, B, I, F> Iterator for FilterMap<A, B, I, F> where
17281728

17291729
#[inline]
17301730
fn next(&mut self) -> Option<B> {
1731-
for x in self.iter {
1731+
for x in self.iter.by_ref() {
17321732
match (self.f)(x) {
17331733
Some(y) => return Some(y),
17341734
None => ()
@@ -1914,7 +1914,7 @@ impl<A, I, P> Iterator for SkipWhile<A, I, P> where I: Iterator<Item=A>, P: FnMu
19141914

19151915
#[inline]
19161916
fn next(&mut self) -> Option<A> {
1917-
for x in self.iter {
1917+
for x in self.iter.by_ref() {
19181918
if self.flag || !(self.predicate)(&x) {
19191919
self.flag = true;
19201920
return Some(x);
@@ -2207,7 +2207,7 @@ impl<A, B, I, U, F> Iterator for FlatMap<A, B, I, U, F> where
22072207
fn next(&mut self) -> Option<B> {
22082208
loop {
22092209
for inner in self.frontiter.iter_mut() {
2210-
for x in *inner {
2210+
for x in inner.by_ref() {
22112211
return Some(x)
22122212
}
22132213
}

branches/tmp/src/libcore/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
#![allow(unknown_features)] #![feature(int_uint)]
6666
#![feature(on_unimplemented)]
6767
#![deny(missing_docs)]
68+
// NOTE(stage0) remove cfg_attr after a snapshot
69+
#![cfg_attr(not(stage0), allow(unused_mut))]
6870

6971
#[macro_use]
7072
mod macros;
@@ -158,4 +160,6 @@ mod std {
158160
pub use marker;
159161
pub use ops;
160162
pub use option;
163+
// for-loops
164+
pub use iter;
161165
}

branches/tmp/src/libcore/num/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,7 @@ macro_rules! from_str_radix_float_impl {
15241524
let mut exp_info = None::<(char, uint)>;
15251525

15261526
// Parse the integer part of the significand
1527-
for (i, c) in cs {
1527+
for (i, c) in cs.by_ref() {
15281528
match c.to_digit(radix) {
15291529
Some(digit) => {
15301530
// shift significand one digit left
@@ -1572,7 +1572,7 @@ macro_rules! from_str_radix_float_impl {
15721572
// part of the significand
15731573
if exp_info.is_none() {
15741574
let mut power = 1.0;
1575-
for (i, c) in cs {
1575+
for (i, c) in cs.by_ref() {
15761576
match c.to_digit(radix) {
15771577
Some(digit) => {
15781578
// Decrease power one order of magnitude

branches/tmp/src/librand/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ mod std {
498498
pub use core::{option, fmt}; // panic!()
499499
pub use core::clone; // derive Clone
500500
pub use core::marker;
501+
// for-loops
502+
pub use core::iter;
501503
}
502504

503505
#[cfg(test)]

branches/tmp/src/librustc/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#![feature(unicode)]
4242
#![feature(hash)]
4343
#![cfg_attr(test, feature(test))]
44+
#![allow(unstable)]
45+
// NOTE(stage0) remove cfg_attr after a snapshot
46+
#![cfg_attr(not(stage0), allow(unused_mut))]
4447

4548
extern crate arena;
4649
extern crate flate;

branches/tmp/src/librustc/middle/dataflow.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
352352
for (word_index, &word) in words.iter().enumerate() {
353353
if word != 0 {
354354
let base_index = word_index * uint::BITS;
355-
for offset in 0u..uint::BITS {
355+
// FIXME(#21245) use a for loop
356+
let mut iter = 0u..uint::BITS;
357+
while let Some(offset) = iter.next() {
356358
let bit = 1 << offset;
357359
if (word & bit) != 0 {
358360
// NB: we round up the total number of bits

branches/tmp/src/librustc_trans/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
#![feature(std_misc)]
4242
#![feature(unicode)]
4343
#![feature(hash)]
44+
#![allow(unstable)]
45+
// NOTE(stage0) remove cfg_attr after a snapshot
46+
#![cfg_attr(not(stage0), allow(unused_mut))]
4447

4548
extern crate arena;
4649
extern crate flate;

branches/tmp/src/librustc_typeck/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ This API is completely unstable and subject to change.
8484
#![feature(core)]
8585
#![feature(rustc_private)]
8686
#![feature(std_misc)]
87+
#![allow(unstable)]
88+
// NOTE(stage0) remove cfg_attr after a snapshot
89+
#![cfg_attr(not(stage0), allow(unused_mut))]
8790

8891
#[macro_use] extern crate log;
8992
#[macro_use] extern crate syntax;

branches/tmp/src/librustdoc/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#![feature(test)]
3333
#![feature(unicode)]
3434
#![feature(hash)]
35+
#![allow(unstable)]
36+
// NOTE(stage0) remove cfg_attr after a snapshot
37+
#![cfg_attr(not(stage0), allow(unused_mut))]
3538

3639
extern crate arena;
3740
extern crate getopts;

branches/tmp/src/libserialize/collection_impls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ impl<
148148
fn decode<D: Decoder>(d: &mut D) -> Result<EnumSet<T>, D::Error> {
149149
let bits = try!(d.read_uint());
150150
let mut set = EnumSet::new();
151-
for bit in 0..uint::BITS {
151+
// FIXME(#21245) use a for loop
152+
let mut iter = 0..uint::BITS;
153+
while let Some(bit) = iter.next() {
152154
if bits & (1 << bit) != 0 {
153155
set.insert(CLike::from_uint(1 << bit));
154156
}

branches/tmp/src/libstd/ascii.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ pub fn escape_default<F>(c: u8, mut f: F) where
232232
_ => {
233233
f(b'\\');
234234
f(b'x');
235-
for &offset in [4u, 0u].iter() {
235+
// FIXME(#21245) use a for loop
236+
let arr = [4u, 0u];
237+
let mut iter = arr.iter();
238+
while let ::option::Option::Some(&offset) = ::iter::Iterator::next(&mut iter) {
236239
match ((c as i32) >> offset) & 0xf {
237240
i @ 0 ... 9 => f(b'0' + (i as u8)),
238241
i => f(b'a' + (i as u8 - 10)),

branches/tmp/src/libstd/collections/hash/table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use self::BucketState::*;
1515
use clone::Clone;
1616
use cmp;
1717
use hash::{Hash, Hasher};
18-
use iter::{Iterator, ExactSizeIterator, count};
18+
use iter::{Iterator, IteratorExt, ExactSizeIterator, count};
1919
use marker::{Copy, Sized, self};
2020
use mem::{min_align_of, size_of};
2121
use mem;
@@ -921,7 +921,7 @@ impl<'a, K, V> ExactSizeIterator for Drain<'a, K, V> {
921921
#[unsafe_destructor]
922922
impl<'a, K: 'a, V: 'a> Drop for Drain<'a, K, V> {
923923
fn drop(&mut self) {
924-
for _ in *self {}
924+
for _ in self.by_ref() {}
925925
}
926926
}
927927

branches/tmp/src/libstd/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
#![feature(rand)]
124124
#![feature(hash)]
125125
#![cfg_attr(test, feature(test))]
126+
#![allow(unstable)]
127+
// NOTE(stage0): remove cfg_attr after a snapshot
128+
#![cfg_attr(not(stage0), allow(unused_mut))]
126129

127130
// Don't link to std. We are std.
128131
#![no_std]
@@ -310,4 +313,6 @@ mod std {
310313
pub use slice;
311314

312315
pub use boxed; // used for vec![]
316+
// for-loops
317+
pub use iter;
313318
}

branches/tmp/src/libstd/path/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl GenericPath for Path {
557557
}
558558
(Some(a), Some(_)) => {
559559
comps.push("..");
560-
for _ in itb {
560+
for _ in itb.by_ref() {
561561
comps.push("..");
562562
}
563563
comps.push(a);

0 commit comments

Comments
 (0)