Skip to content

Commit 35659ed

Browse files
committed
---
yaml --- r: 63691 b: refs/heads/snap-stage3 c: ca2966c h: refs/heads/master i: 63689: 705e341 63687: d472828 v: v3
1 parent 499fd59 commit 35659ed

File tree

230 files changed

+760
-512
lines changed

Some content is hidden

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

230 files changed

+760
-512
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: e9ac7194ff31792e2eca2c745fbef309a2daba86
4+
refs/heads/snap-stage3: ca2966c6d04958241f13e61310298a5ff69061e2
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 finalize(&self) {
186+
fn drop(&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: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,13 @@ 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+
15551562
As a caller, if we use a closure to provide the final operator
15561563
argument, we can write it in a way that has a pleasant, block-like
15571564
structure.
@@ -1609,9 +1616,6 @@ To enable `debug!` logging, set the RUST_LOG environment variable to the name of
16091616

16101617
## For loops
16111618

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-
16151619
The most common way to express iteration in Rust is with a `for`
16161620
loop. Like `do`, `for` is a nice syntax for describing control flow
16171621
with closures. Additionally, within a `for` loop, `break`, `loop`,
@@ -1636,16 +1640,7 @@ fn each(v: &[int], op: &fn(v: &int) -> bool) -> bool {
16361640
And using this function to iterate over a vector:
16371641

16381642
~~~~
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-
# }
1643+
# use each = std::vec::each;
16491644
each([2, 4, 8, 5, 16], |n| {
16501645
if *n % 2 != 0 {
16511646
println("found odd number!");
@@ -1661,16 +1656,7 @@ out of the loop, you just write `break`. To skip ahead
16611656
to the next iteration, write `loop`.
16621657

16631658
~~~~
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-
# }
1659+
# use each = std::vec::each;
16741660
for each([2, 4, 8, 5, 16]) |n| {
16751661
if *n % 2 != 0 {
16761662
println("found odd number!");
@@ -1685,16 +1671,7 @@ normally allowed in closures, in a block that appears as the body of a
16851671
the enclosing function, not just the loop body.
16861672

16871673
~~~~
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-
# }
1674+
# use each = std::vec::each;
16981675
fn contains(v: &[int], elt: int) -> bool {
16991676
for each(v) |x| {
17001677
if (*x == elt) { return true; }
@@ -1709,16 +1686,7 @@ In these situations it can be convenient to lean on Rust's
17091686
argument patterns to bind `x` to the actual value, not the pointer.
17101687

17111688
~~~~
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-
# }
1689+
# use each = std::vec::each;
17221690
# fn contains(v: &[int], elt: int) -> bool {
17231691
for each(v) |&x| {
17241692
if (x == elt) { return true; }
@@ -1873,9 +1841,10 @@ vector consisting of the result of applying `function` to each element
18731841
of `vector`:
18741842

18751843
~~~~
1844+
# use std::vec;
18761845
fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
18771846
let mut accumulator = ~[];
1878-
for vector.iter().advance |element| {
1847+
for vec::each(vector) |element| {
18791848
accumulator.push(function(element));
18801849
}
18811850
return accumulator;
@@ -2010,7 +1979,7 @@ types by the compiler, and may not be overridden:
20101979
> iterations of the language, and often still are.
20111980
20121981
Additionally, the `Drop` trait is used to define destructors. This
2013-
trait defines one method called `finalize`, which is automatically
1982+
trait defines one method called `drop`, which is automatically
20141983
called when a value of the type that implements this trait is
20151984
destroyed, either because the value went out of scope or because the
20161985
garbage collector reclaimed it.
@@ -2021,15 +1990,15 @@ struct TimeBomb {
20211990
}
20221991
20231992
impl Drop for TimeBomb {
2024-
fn finalize(&self) {
1993+
fn drop(&self) {
20251994
for self.explosivity.times {
20261995
println("blam!");
20271996
}
20281997
}
20291998
}
20301999
~~~
20312000

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

20352004
## 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 props.aux_builds.iter().advance |rel_ab| {
532+
for vec::each(props.aux_builds) |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 drop extern
18+
syn keyword rustKeyword break copy do 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: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct PoisonOnFail {
247247
}
248248

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

526525
#[test]
527526
fn manually_share_arc() {
@@ -791,20 +790,18 @@ mod tests {
791790
}
792791
assert_eq!(*state, 42);
793792
*state = 31337;
794-
// FIXME: #7372: hits type inference bug with iterators
795793
// send to other readers
796-
for uint::range(0, reader_convos.len()) |i| {
797-
match reader_convos[i] {
794+
for vec::each(reader_convos) |x| {
795+
match *x {
798796
(ref rc, _) => rc.send(()),
799797
}
800798
}
801799
}
802800
let read_mode = arc.downgrade(write_mode);
803801
do (&read_mode).read |state| {
804-
// FIXME: #7372: hits type inference bug with iterators
805802
// complete handshake with other readers
806-
for uint::range(0, reader_convos.len()) |i| {
807-
match reader_convos[i] {
803+
for vec::each(reader_convos) |x| {
804+
match *x {
808805
(_, ref rp) => rp.recv(),
809806
}
810807
}

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 finalize(&self) {
80+
fn drop(&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 finalize(&self) {
60+
fn drop(&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 finalize(&self) {}
47+
fn drop(&self) {}
4848
}
4949

5050
priv enum FutureState<A> {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,10 @@ 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-
let r = opt_vals(mm, nm);
422-
for r.iter().advance |v| {
421+
for vec::each(opt_vals(mm, nm)) |v| {
423422
match *v { Val(ref s) => acc.push(copy *s), _ => () }
424423
}
425-
acc
424+
return acc;
426425
}
427426

428427
/// 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.iter().advance |(k, v0)| {
1126+
for d0.each |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.iter().advance |(k, v)| {
1189+
for d0.each |k, v| {
11901190
d0_flat.push((@copy *k, @copy *v));
11911191
}
11921192
d0_flat.qsort();
11931193

1194-
for d1.iter().advance |(k, v)| {
1194+
for d1.each |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.iter().advance |(key, value)| {
1329+
for self.each |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 finalize(&self) {
60+
fn drop(&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.iter().advance |(key, values)| {
210+
for m.each |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 finalize(&self) {
71+
fn drop(&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 finalize(&self) {
223+
fn drop(&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.iter().advance |(key, val)| {
713+
for self.each |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.iter().advance |e| {
747+
for self.each |e| {
748748
s.emit_seq_elt(i, |s| e.encode(s));
749749
i += 1;
750750
}

0 commit comments

Comments
 (0)