Skip to content

Commit e492606

Browse files
committed
---
yaml --- r: 51662 b: refs/heads/incoming c: de7d558 h: refs/heads/master v: v3
1 parent ce4b65f commit e492606

File tree

33 files changed

+464
-478
lines changed

33 files changed

+464
-478
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: c88a20d171b407aa6a88b516c213e93b7dda5c94
9+
refs/heads/incoming: de7d5589441d4f0fe8c4f083b6fa9dbfac451398
1010
refs/heads/dist-snap: 8b98e5a296d95c5e832db0756828e5bec31c6f50
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/rust.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,10 @@ vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
16711671
A [_vector_](#vector-types) _expression_ is written by enclosing zero or
16721672
more comma-separated expressions of uniform type in square brackets.
16731673

1674+
In the `[expr ',' ".." expr]` form, the expression after the `".."`
1675+
must be a constant expression that can be evaluated at compile time, such
1676+
as a [literal](#literals) or a [static item](#static-items).
1677+
16741678
~~~~
16751679
[1, 2, 3, 4];
16761680
["a", "b", "c", "d"];
@@ -2156,6 +2160,19 @@ do f |j| {
21562160
}
21572161
~~~~
21582162

2163+
In this example, both calls to the (binary) function `k` are equivalent:
2164+
2165+
~~~~
2166+
# fn k(x:int, f: &fn(int)) { }
2167+
# fn l(i: int) { }
2168+
2169+
k(3, |j| l(j));
2170+
2171+
do k(3) |j| {
2172+
l(j);
2173+
}
2174+
~~~~
2175+
21592176

21602177
### For expressions
21612178

@@ -2184,7 +2201,7 @@ and early boolean-valued returns from the `block` function,
21842201
such that the meaning of `break` and `loop` is preserved in a primitive loop
21852202
when rewritten as a `for` loop controlled by a higher order function.
21862203

2187-
An example a for loop:
2204+
An example of a for loop over the contents of a vector:
21882205

21892206
~~~~
21902207
# type foo = int;
@@ -2198,6 +2215,14 @@ for v.each |e| {
21982215
}
21992216
~~~~
22002217

2218+
An example of a for loop over a series of integers:
2219+
2220+
~~~~
2221+
# fn bar(b:uint) { }
2222+
for uint::range(0, 256) |i| {
2223+
bar(i);
2224+
}
2225+
~~~~
22012226

22022227
### If expressions
22032228

@@ -2474,6 +2499,7 @@ fail_unless!(b != "world");
24742499

24752500
The vector type constructor represents a homogeneous array of values of a given type.
24762501
A vector has a fixed size.
2502+
(Operations like `vec::push` operate solely on owned vectors.)
24772503
A vector type can be annotated with a _definite_ size,
24782504
written with a trailing asterisk and integer literal, such as `[int * 10]`.
24792505
Such a definite-sized vector type is a first-class type, since its size is known statically.
@@ -2484,6 +2510,10 @@ such as `&[T]`, `@[T]` or `~[T]`.
24842510
The kind of a vector type depends on the kind of its element type,
24852511
as with other simple structural types.
24862512

2513+
Expressions producing vectors of definite size cannot be evaluated in a
2514+
context expecting a vector of indefinite size; one must copy the
2515+
definite-sized vector contents into a distinct vector of indefinite size.
2516+
24872517
An example of a vector type and its use:
24882518

24892519
~~~~

branches/incoming/src/compiletest/header.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ fn parse_check_line(line: ~str) -> Option<~str> {
142142
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
143143
do parse_name_value_directive(line, ~"exec-env").map |nv| {
144144
// nv is either FOO or FOO=BAR
145-
let mut strs = ~[];
146-
for str::each_splitn_char(*nv, '=', 1u) |s| { strs.push(s.to_owned()); }
145+
let strs = str::splitn_char(*nv, '=', 1u);
147146
match strs.len() {
148147
1u => (strs[0], ~""),
149148
2u => (strs[0], strs[1]),

branches/incoming/src/compiletest/runtest.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
267267
// check if each line in props.check_lines appears in the
268268
// output (in order)
269269
let mut i = 0u;
270-
for str::each_line(ProcRes.stdout) |line| {
270+
for str::lines_each(ProcRes.stdout) |line| {
271271
if props.check_lines[i].trim() == line.trim() {
272272
i += 1u;
273273
}
@@ -297,7 +297,7 @@ fn check_error_patterns(props: TestProps,
297297
let mut next_err_idx = 0u;
298298
let mut next_err_pat = props.error_patterns[next_err_idx];
299299
let mut done = false;
300-
for str::each_line(ProcRes.stderr) |line| {
300+
for str::lines_each(ProcRes.stderr) |line| {
301301
if str::contains(line, next_err_pat) {
302302
debug!("found error pattern %s", next_err_pat);
303303
next_err_idx += 1u;
@@ -347,7 +347,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
347347
// filename:line1:col1: line2:col2: *warning:* msg
348348
// where line1:col1: is the starting point, line2:col2:
349349
// is the ending point, and * represents ANSI color codes.
350-
for str::each_line(ProcRes.stderr) |line| {
350+
for str::lines_each(ProcRes.stderr) |line| {
351351
let mut was_expected = false;
352352
for vec::eachi(expected_errors) |i, ee| {
353353
if !found_flags[i] {
@@ -596,12 +596,8 @@ fn split_maybe_args(argstr: Option<~str>) -> ~[~str] {
596596
}
597597

598598
match argstr {
599-
Some(s) => {
600-
let mut ss = ~[];
601-
for str::each_split_char(s, ' ') |s| { ss.push(s.to_owned()) }
602-
rm_whitespace(ss)
603-
}
604-
None => ~[]
599+
Some(s) => rm_whitespace(str::split_char(s, ' ')),
600+
None => ~[]
605601
}
606602
}
607603

branches/incoming/src/libcore/iter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ pub fn build_sized_opt<A,B: Buildable<A>>(size: Option<uint>,
284284

285285
// Functions that combine iteration and building
286286

287-
/// Applies a function to each element of an iterable and returns the results.
287+
/// Applies a function to each element of an iterable and returns the results
288+
/// in a sequence built via `BU`. See also `map_to_vec`.
288289
#[inline(always)]
289290
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: &fn(&T) -> U)
290291
-> BU {

branches/incoming/src/libcore/num/strconv.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ impl_NumStrConv_Integer!(u16)
130130
impl_NumStrConv_Integer!(u32)
131131
impl_NumStrConv_Integer!(u64)
132132

133-
134-
// Special value strings as [u8] consts.
135-
static inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8];
136-
static positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8, 'n' as u8, 'f' as u8];
137-
static negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8, 'n' as u8, 'f' as u8];
138-
static nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8];
139-
140133
/**
141134
* Converts a number to its string representation as a byte vector.
142135
* This is meant to be a common base implementation for all numeric string
@@ -486,15 +479,15 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
486479
}
487480

488481
if special {
489-
if buf == inf_buf || buf == positive_inf_buf {
482+
if buf == str::inf_buf || buf == str::positive_inf_buf {
490483
return NumStrConv::inf();
491-
} else if buf == negative_inf_buf {
484+
} else if buf == str::negative_inf_buf {
492485
if negative {
493486
return NumStrConv::neg_inf();
494487
} else {
495488
return None;
496489
}
497-
} else if buf == nan_buf {
490+
} else if buf == str::nan_buf {
498491
return NumStrConv::NaN();
499492
}
500493
}

branches/incoming/src/libcore/os.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ pub fn env() -> ~[(~str,~str)] {
218218
fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] {
219219
let mut pairs = ~[];
220220
for input.each |p| {
221-
let mut vs = ~[];
222-
for str::each_splitn_char(*p, '=', 1) |s| { vs.push(s.to_owned()) }
221+
let vs = str::splitn_char(*p, '=', 1);
223222
debug!("splitting: len: %u",
224223
vs.len());
225224
fail_unless!(vs.len() == 2);

branches/incoming/src/libcore/path.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ impl ToStr for PosixPath {
381381
impl GenericPath for PosixPath {
382382

383383
fn from_str(s: &str) -> PosixPath {
384-
let mut components = ~[];
385-
for str::each_split_nonempty(s, |c| c == '/') |s| { components.push(s.to_owned()) }
384+
let mut components = str::split_nonempty(s, |c| c == '/');
386385
let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
387386
return PosixPath { is_absolute: is_absolute,
388387
components: components }
@@ -505,10 +504,9 @@ impl GenericPath for PosixPath {
505504
fn push_many(&self, cs: &[~str]) -> PosixPath {
506505
let mut v = copy self.components;
507506
for cs.each |e| {
508-
let mut ss = ~[];
509-
for str::each_split_nonempty(*e, |c| windows::is_sep(c as u8)) |s| {
510-
ss.push(s.to_owned())
511-
}
507+
let mut ss = str::split_nonempty(
508+
*e,
509+
|c| windows::is_sep(c as u8));
512510
unsafe { v.push_all_move(ss); }
513511
}
514512
PosixPath { is_absolute: self.is_absolute,
@@ -517,10 +515,7 @@ impl GenericPath for PosixPath {
517515

518516
fn push(&self, s: &str) -> PosixPath {
519517
let mut v = copy self.components;
520-
let mut ss = ~[];
521-
for str::each_split_nonempty(s, |c| windows::is_sep(c as u8)) |s| {
522-
ss.push(s.to_owned())
523-
}
518+
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
524519
unsafe { v.push_all_move(ss); }
525520
PosixPath { components: v, ..copy *self }
526521
}
@@ -595,10 +590,8 @@ impl GenericPath for WindowsPath {
595590
}
596591
}
597592

598-
let mut components = ~[];
599-
for str::each_split_nonempty(rest, |c| windows::is_sep(c as u8)) |s| {
600-
components.push(s.to_owned())
601-
}
593+
let mut components =
594+
str::split_nonempty(rest, |c| windows::is_sep(c as u8));
602595
let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
603596
return WindowsPath { host: host,
604597
device: device,
@@ -766,10 +759,9 @@ impl GenericPath for WindowsPath {
766759
fn push_many(&self, cs: &[~str]) -> WindowsPath {
767760
let mut v = copy self.components;
768761
for cs.each |e| {
769-
let mut ss = ~[];
770-
for str::each_split_nonempty(*e, |c| windows::is_sep(c as u8)) |s| {
771-
ss.push(s.to_owned())
772-
}
762+
let mut ss = str::split_nonempty(
763+
*e,
764+
|c| windows::is_sep(c as u8));
773765
unsafe { v.push_all_move(ss); }
774766
}
775767
// tedious, but as-is, we can't use ..self
@@ -783,10 +775,7 @@ impl GenericPath for WindowsPath {
783775

784776
fn push(&self, s: &str) -> WindowsPath {
785777
let mut v = copy self.components;
786-
let mut ss = ~[];
787-
for str::each_split_nonempty(s, |c| windows::is_sep(c as u8)) |s| {
788-
ss.push(s.to_owned())
789-
}
778+
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
790779
unsafe { v.push_all_move(ss); }
791780
return WindowsPath { components: v, ..copy *self }
792781
}

branches/incoming/src/libcore/rand.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ impl RngUtil for @Rng {
327327
*/
328328
fn gen_char_from(&self, chars: &str) -> char {
329329
fail_unless!(!chars.is_empty());
330-
let mut cs = ~[];
331-
for str::each_char(chars) |c| { cs.push(c) }
332-
self.choose(cs)
330+
self.choose(str::chars(chars))
333331
}
334332

335333
/// Return a random bool

0 commit comments

Comments
 (0)