Skip to content

Commit f1a3d33

Browse files
committed
---
yaml --- r: 63692 b: refs/heads/snap-stage3 c: 6a77273 h: refs/heads/master v: v3
1 parent 35659ed commit f1a3d33

File tree

181 files changed

+440
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+440
-538
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ca2966c6d04958241f13e61310298a5ff69061e2
4+
refs/heads/snap-stage3: 6a772731045bc6bf0ffe4d75fd5522c0d073d14e
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/doc/tutorial-ffi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<T: Owned> Unique<T> {
183183
184184
#[unsafe_destructor]
185185
impl<T: Owned> Drop for Unique<T> {
186-
fn drop(&self) {
186+
fn finalize(&self) {
187187
unsafe {
188188
let x = intrinsics::init(); // dummy value to swap in
189189
// moving the object out is needed to call the destructor

branches/snap-stage3/doc/tutorial.md

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,13 +1552,6 @@ fn each(v: &[int], op: &fn(v: &int)) {
15521552
}
15531553
~~~~
15541554

1555-
As an aside, the reason we pass in a *pointer* to an integer rather
1556-
than the integer itself is that this is how the actual `each()`
1557-
function for vectors works. `vec::each` though is a
1558-
[generic](#generics) function, so must be efficient to use for all
1559-
types. Passing the elements by pointer avoids copying potentially
1560-
large objects.
1561-
15621555
As a caller, if we use a closure to provide the final operator
15631556
argument, we can write it in a way that has a pleasant, block-like
15641557
structure.
@@ -1616,6 +1609,9 @@ To enable `debug!` logging, set the RUST_LOG environment variable to the name of
16161609

16171610
## For loops
16181611

1612+
> ***Note:*** The closure-based protocol used `for` loop is on the way out. The `for` loop will
1613+
> use iterator objects in the future instead.
1614+
16191615
The most common way to express iteration in Rust is with a `for`
16201616
loop. Like `do`, `for` is a nice syntax for describing control flow
16211617
with closures. Additionally, within a `for` loop, `break`, `loop`,
@@ -1640,7 +1636,16 @@ fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
16401636
And using this function to iterate over a vector:
16411637

16421638
~~~~
1643-
# use each = std::vec::each;
1639+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1640+
# let mut n = 0;
1641+
# while n < v.len() {
1642+
# if !op(&v[n]) {
1643+
# return false;
1644+
# }
1645+
# n += 1;
1646+
# }
1647+
# return true;
1648+
# }
16441649
each([2, 4, 8, 5, 16], |n| {
16451650
if *n % 2 != 0 {
16461651
println("found odd number!");
@@ -1656,7 +1661,16 @@ out of the loop, you just write `break`. To skip ahead
16561661
to the next iteration, write `loop`.
16571662

16581663
~~~~
1659-
# use each = std::vec::each;
1664+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1665+
# let mut n = 0;
1666+
# while n < v.len() {
1667+
# if !op(&v[n]) {
1668+
# return false;
1669+
# }
1670+
# n += 1;
1671+
# }
1672+
# return true;
1673+
# }
16601674
for each([2, 4, 8, 5, 16]) |n| {
16611675
if *n % 2 != 0 {
16621676
println("found odd number!");
@@ -1671,7 +1685,16 @@ normally allowed in closures, in a block that appears as the body of a
16711685
the enclosing function, not just the loop body.
16721686

16731687
~~~~
1674-
# use each = std::vec::each;
1688+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1689+
# let mut n = 0;
1690+
# while n < v.len() {
1691+
# if !op(&v[n]) {
1692+
# return false;
1693+
# }
1694+
# n += 1;
1695+
# }
1696+
# return true;
1697+
# }
16751698
fn contains(v: &[int], elt: int) -> bool {
16761699
for each(v) |x| {
16771700
if (*x == elt) { return true; }
@@ -1686,7 +1709,16 @@ In these situations it can be convenient to lean on Rust's
16861709
argument patterns to bind `x` to the actual value, not the pointer.
16871710

16881711
~~~~
1689-
# use each = std::vec::each;
1712+
# fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
1713+
# let mut n = 0;
1714+
# while n < v.len() {
1715+
# if !op(&v[n]) {
1716+
# return false;
1717+
# }
1718+
# n += 1;
1719+
# }
1720+
# return true;
1721+
# }
16901722
# fn contains(v: &[int], elt: int) -> bool {
16911723
for each(v) |&x| {
16921724
if (x == elt) { return true; }
@@ -1841,10 +1873,9 @@ vector consisting of the result of applying `function` to each element
18411873
of `vector`:
18421874

18431875
~~~~
1844-
# use std::vec;
18451876
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
18461877
let mut accumulator = ~[];
1847-
for vec::each(vector) |element| {
1878+
for vector.iter().advance |element| {
18481879
accumulator.push(function(element));
18491880
}
18501881
return accumulator;
@@ -1979,7 +2010,7 @@ types by the compiler, and may not be overridden:
19792010
> iterations of the language, and often still are.
19802011
19812012
Additionally, the `Drop` trait is used to define destructors. This
1982-
trait defines one method called `drop`, which is automatically
2013+
trait defines one method called `finalize`, which is automatically
19832014
called when a value of the type that implements this trait is
19842015
destroyed, either because the value went out of scope or because the
19852016
garbage collector reclaimed it.
@@ -1990,15 +2021,15 @@ struct TimeBomb {
19902021
}
19912022
19922023
impl Drop for TimeBomb {
1993-
fn drop(&self) {
2024+
fn finalize(&self) {
19942025
for self.explosivity.times {
19952026
println("blam!");
19962027
}
19972028
}
19982029
}
19992030
~~~
20002031

2001-
It is illegal to call `drop` directly. Only code inserted by the compiler
2032+
It is illegal to call `finalize` directly. Only code inserted by the compiler
20022033
may call it.
20032034

20042035
## Declaring and implementing traits

branches/snap-stage3/src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn compose_and_run_compiler(
529529
let extra_link_args = ~[~"-L",
530530
aux_output_dir_name(config, testfile).to_str()];
531531

532-
for vec::each(props.aux_builds) |rel_ab| {
532+
for props.aux_builds.iter().advance |rel_ab| {
533533
let abs_ab = config.aux_base.push_rel(&Path(*rel_ab));
534534
let aux_args =
535535
make_compile_args(config, props, ~[~"--lib"] + extra_link_args,

branches/snap-stage3/src/etc/vim/syntax/rust.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ syn keyword rustOperator as
1515

1616
syn match rustAssert "\<assert\(\w\)*!"
1717
syn match rustFail "\<fail\(\w\)*!"
18-
syn keyword rustKeyword break copy do extern
18+
syn keyword rustKeyword break copy do drop extern
1919
syn keyword rustKeyword for if impl let log
2020
syn keyword rustKeyword copy do extern
2121
syn keyword rustKeyword for impl let log

branches/snap-stage3/src/libextra/arc.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct PoisonOnFail {
247247
}
248248

249249
impl Drop for PoisonOnFail {
250-
fn drop(&self) {
250+
fn finalize(&self) {
251251
unsafe {
252252
/* assert!(!*self.failed);
253253
-- might be false in case of cond.wait() */
@@ -521,6 +521,7 @@ mod tests {
521521
use core::cell::Cell;
522522
use core::comm;
523523
use core::task;
524+
use core::uint;
524525

525526
#[test]
526527
fn manually_share_arc() {
@@ -790,18 +791,20 @@ mod tests {
790791
}
791792
assert_eq!(*state, 42);
792793
*state = 31337;
794+
// FIXME: #7372: hits type inference bug with iterators
793795
// send to other readers
794-
for vec::each(reader_convos) |x| {
795-
match *x {
796+
for uint::range(0, reader_convos.len()) |i| {
797+
match reader_convos[i] {
796798
(ref rc, _) => rc.send(()),
797799
}
798800
}
799801
}
800802
let read_mode = arc.downgrade(write_mode);
801803
do (&read_mode).read |state| {
804+
// FIXME: #7372: hits type inference bug with iterators
802805
// complete handshake with other readers
803-
for vec::each(reader_convos) |x| {
804-
match *x {
806+
for uint::range(0, reader_convos.len()) |i| {
807+
match reader_convos[i] {
805808
(_, ref rp) => rp.recv(),
806809
}
807810
}

branches/snap-stage3/src/libextra/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub struct Arena {
7777

7878
#[unsafe_destructor]
7979
impl Drop for Arena {
80-
fn drop(&self) {
80+
fn finalize(&self) {
8181
unsafe {
8282
destroy_chunk(&self.head);
8383
for self.chunks.each |chunk| {

branches/snap-stage3/src/libextra/c_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct DtorRes {
5757

5858
#[unsafe_destructor]
5959
impl Drop for DtorRes {
60-
fn drop(&self) {
60+
fn finalize(&self) {
6161
match self.dtor {
6262
option::None => (),
6363
option::Some(f) => f()

branches/snap-stage3/src/libextra/future.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct Future<A> {
4444
// over ~fn's that have pipes and so forth within!
4545
#[unsafe_destructor]
4646
impl<A> Drop for Future<A> {
47-
fn drop(&self) {}
47+
fn finalize(&self) {}
4848
}
4949

5050
priv enum FutureState<A> {

branches/snap-stage3/src/libextra/getopts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
418418
*/
419419
pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
420420
let mut acc: ~[~str] = ~[];
421-
for vec::each(opt_vals(mm, nm)) |v| {
421+
let r = opt_vals(mm, nm);
422+
for r.iter().advance |v| {
422423
match *v { Val(ref s) => acc.push(copy *s), _ => () }
423424
}
424-
return acc;
425+
acc
425426
}
426427

427428
/// Returns the string argument supplied to a matching option or none

branches/snap-stage3/src/libextra/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ impl Eq for Json {
11231123
&Object(ref d1) => {
11241124
if d0.len() == d1.len() {
11251125
let mut equal = true;
1126-
for d0.each |k, v0| {
1126+
for d0.iter().advance |(k, v0)| {
11271127
match d1.find(k) {
11281128
Some(v1) if v0 == v1 => { },
11291129
_ => { equal = false; break }
@@ -1186,12 +1186,12 @@ impl Ord for Json {
11861186
let mut d1_flat = ~[];
11871187

11881188
// FIXME #4430: this is horribly inefficient...
1189-
for d0.each |k, v| {
1189+
for d0.iter().advance |(k, v)| {
11901190
d0_flat.push((@copy *k, @copy *v));
11911191
}
11921192
d0_flat.qsort();
11931193

1194-
for d1.each |k, v| {
1194+
for d1.iter().advance |(k, v)| {
11951195
d1_flat.push((@copy *k, @copy *v));
11961196
}
11971197
d1_flat.qsort();
@@ -1326,7 +1326,7 @@ impl<A:ToJson> ToJson for ~[A] {
13261326
impl<A:ToJson + Copy> ToJson for HashMap<~str, A> {
13271327
fn to_json(&self) -> Json {
13281328
let mut d = HashMap::new();
1329-
for self.each |key, value| {
1329+
for self.iter().advance |(key, value)| {
13301330
d.insert(copy *key, value.to_json());
13311331
}
13321332
Object(~d)

branches/snap-stage3/src/libextra/net_tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct TcpSocket {
5757

5858
#[unsafe_destructor]
5959
impl Drop for TcpSocket {
60-
fn drop(&self) {
60+
fn finalize(&self) {
6161
tear_down_socket_data(self.socket_data)
6262
}
6363
}

branches/snap-stage3/src/libextra/net_url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn encode_form_urlencoded(m: &HashMap<~str, ~[~str]>) -> ~str {
207207
let mut out = ~"";
208208
let mut first = true;
209209

210-
for m.each |key, values| {
210+
for m.iter().advance |(key, values)| {
211211
let key = encode_plus(*key);
212212

213213
for values.iter().advance |value| {

branches/snap-stage3/src/libextra/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<T> Rc<T> {
6868

6969
#[unsafe_destructor]
7070
impl<T> Drop for Rc<T> {
71-
fn drop(&self) {
71+
fn finalize(&self) {
7272
unsafe {
7373
if self.ptr.is_not_null() {
7474
(*self.ptr).count -= 1;
@@ -220,7 +220,7 @@ impl<T> RcMut<T> {
220220

221221
#[unsafe_destructor]
222222
impl<T> Drop for RcMut<T> {
223-
fn drop(&self) {
223+
fn finalize(&self) {
224224
unsafe {
225225
if self.ptr.is_not_null() {
226226
(*self.ptr).count -= 1;

branches/snap-stage3/src/libextra/serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<
710710
fn encode(&self, e: &mut E) {
711711
do e.emit_map(self.len()) |e| {
712712
let mut i = 0;
713-
for self.each |key, val| {
713+
for self.iter().advance |(key, val)| {
714714
e.emit_map_elt_key(i, |e| key.encode(e));
715715
e.emit_map_elt_val(i, |e| val.encode(e));
716716
i += 1;
@@ -744,7 +744,7 @@ impl<
744744
fn encode(&self, s: &mut S) {
745745
do s.emit_seq(self.len()) |s| {
746746
let mut i = 0;
747-
for self.each |e| {
747+
for self.iter().advance |e| {
748748
s.emit_seq_elt(i, |s| e.encode(s));
749749
i += 1;
750750
}

0 commit comments

Comments
 (0)