Skip to content

Commit 56730c0

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into remove-str-trailing-nulls
2 parents 03cc757 + 936f70b commit 56730c0

File tree

159 files changed

+3789
-896
lines changed

Some content is hidden

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

159 files changed

+3789
-896
lines changed

doc/tutorial-ffi.md

+42
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,48 @@ unsafe fn kaboom(ptr: *int) -> int { *ptr }
228228

229229
This function can only be called from an `unsafe` block or another `unsafe` function.
230230

231+
# Accessing foreign globals
232+
233+
Foreign APIs often export a global variable which could do something like track
234+
global state. In order to access these variables, you declare them in `extern`
235+
blocks with the `static` keyword:
236+
237+
~~~{.xfail-test}
238+
use std::libc;
239+
240+
#[link_args = "-lreadline"]
241+
extern {
242+
static rl_readline_version: libc::c_int;
243+
}
244+
245+
fn main() {
246+
println(fmt!("You have readline version %d installed.",
247+
rl_readline_version as int));
248+
}
249+
~~~
250+
251+
Alternatively, you may need to alter global state provided by a foreign
252+
interface. To do this, statics can be declared with `mut` so rust can mutate
253+
them.
254+
255+
~~~{.xfail-test}
256+
use std::libc;
257+
use std::ptr;
258+
259+
#[link_args = "-lreadline"]
260+
extern {
261+
static mut rl_prompt: *libc::c_char;
262+
}
263+
264+
fn main() {
265+
do "[my-awesome-shell] $".as_c_str |buf| {
266+
unsafe { rl_prompt = buf; }
267+
// get a line, process it
268+
unsafe { rl_prompt = ptr::null(); }
269+
}
270+
}
271+
~~~
272+
231273
# Foreign calling conventions
232274

233275
Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when

doc/tutorial-tasks.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ there is no way to "catch" the exception.
424424
All tasks are, by default, _linked_ to each other. That means that the fates
425425
of all tasks are intertwined: if one fails, so do all the others.
426426

427-
~~~
427+
~~~{.xfail-test .linked-failure}
428428
# use std::task::spawn;
429429
# use std::task;
430430
# fn do_some_work() { loop { task::yield() } }
@@ -447,7 +447,7 @@ pattern-match on a result to check whether it's an `Ok` result with an `int`
447447
field (representing a successful result) or an `Err` result (representing
448448
termination with an error).
449449

450-
~~~
450+
~~~{.xfail-test .linked-failure}
451451
# use std::task;
452452
# fn some_condition() -> bool { false }
453453
# fn calculate_result() -> int { 0 }
@@ -490,9 +490,10 @@ proceed). Hence, you will need different _linked failure modes_.
490490
By default, task failure is _bidirectionally linked_, which means that if
491491
either task fails, it kills the other one.
492492

493-
~~~
493+
~~~{.xfail-test .linked-failure}
494494
# use std::task;
495-
# fn sleep_forever() { loop { task::yield() } }
495+
# use std::comm::oneshot;
496+
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
496497
# do task::try {
497498
do spawn {
498499
do spawn {
@@ -511,11 +512,12 @@ function `task::try`, which we saw previously, uses `spawn_supervised`
511512
internally, with additional logic to wait for the child task to finish
512513
before returning. Hence:
513514

514-
~~~
515+
~~~{.xfail-test .linked-failure}
515516
# use std::comm::{stream, Chan, Port};
517+
# use std::comm::oneshot;
516518
# use std::task::{spawn, try};
517519
# use std::task;
518-
# fn sleep_forever() { loop { task::yield() } }
520+
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
519521
# do task::try {
520522
let (receiver, sender): (Port<int>, Chan<int>) = stream();
521523
do spawn { // Bidirectionally linked
@@ -541,9 +543,10 @@ also fail.
541543
Supervised task failure propagates across multiple generations even if
542544
an intermediate generation has already exited:
543545

544-
~~~
546+
~~~{.xfail-test .linked-failure}
545547
# use std::task;
546-
# fn sleep_forever() { loop { task::yield() } }
548+
# use std::comm::oneshot;
549+
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
547550
# fn wait_for_a_while() { for _ in range(0, 1000u) { task::yield() } }
548551
# do task::try::<int> {
549552
do task::spawn_supervised {
@@ -560,7 +563,7 @@ fail!(); // Will kill grandchild even if child has already exited
560563
Finally, tasks can be configured to not propagate failure to each
561564
other at all, using `task::spawn_unlinked` for _isolated failure_.
562565

563-
~~~
566+
~~~{.xfail-test .linked-failure}
564567
# use std::task;
565568
# fn random() -> uint { 100 }
566569
# fn sleep_for(i: uint) { for _ in range(0, i) { task::yield() } }
@@ -588,7 +591,7 @@ that repeatedly receives a `uint` message, converts it to a string, and sends
588591
the string in response. The child terminates when it receives `0`.
589592
Here is the function that implements the child task:
590593

591-
~~~~
594+
~~~{.xfail-test .linked-failure}
592595
# use extra::comm::DuplexStream;
593596
# use std::uint;
594597
fn stringifier(channel: &DuplexStream<~str, uint>) {
@@ -611,7 +614,7 @@ response itself is simply the stringified version of the received value,
611614
612615
Here is the code for the parent task:
613616
614-
~~~~
617+
~~~{.xfail-test .linked-failure}
615618
# use std::task::spawn;
616619
# use std::uint;
617620
# use extra::comm::DuplexStream;

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2288,8 +2288,8 @@ pub mod farm {
22882288
}
22892289
22902290
impl Farm {
2291-
priv fn feed_chickens(&self) { ... }
2292-
priv fn feed_cows(&self) { ... }
2291+
fn feed_chickens(&self) { ... }
2292+
fn feed_cows(&self) { ... }
22932293
pub fn add_chicken(&self, c: Chicken) { ... }
22942294
}
22952295

src/compiletest/compiletest.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub fn parse_config(args: ~[~str]) -> config {
109109
compile_lib_path: getopts::opt_str(matches, "compile-lib-path"),
110110
run_lib_path: getopts::opt_str(matches, "run-lib-path"),
111111
rustc_path: opt_path(matches, "rustc-path"),
112-
clang_path: getopts::opt_maybe_str(matches, "clang-path").map(|s| Path(*s)),
113-
llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map(|s| Path(*s)),
112+
clang_path: getopts::opt_maybe_str(matches, "clang-path").map_move(|s| Path(s)),
113+
llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map_move(|s| Path(s)),
114114
src_base: opt_path(matches, "src-base"),
115115
build_base: opt_path(matches, "build-base"),
116116
aux_base: opt_path(matches, "aux-base"),
@@ -123,14 +123,14 @@ pub fn parse_config(args: ~[~str]) -> config {
123123
} else {
124124
None
125125
},
126-
logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)),
127-
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map(|s| Path(*s)),
126+
logfile: getopts::opt_maybe_str(matches, "logfile").map_move(|s| Path(s)),
127+
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map_move(|s| Path(s)),
128128
ratchet_metrics:
129-
getopts::opt_maybe_str(matches, "ratchet-metrics").map(|s| Path(*s)),
129+
getopts::opt_maybe_str(matches, "ratchet-metrics").map_move(|s| Path(s)),
130130
ratchet_noise_percent:
131131
getopts::opt_maybe_str(matches,
132-
"ratchet-noise-percent").map(|s|
133-
f64::from_str(*s).unwrap()),
132+
"ratchet-noise-percent").map_move(|s|
133+
f64::from_str(s).unwrap()),
134134
runtool: getopts::opt_maybe_str(matches, "runtool"),
135135
rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
136136
jit: getopts::opt_present(matches, "jit"),

src/compiletest/runtest.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
162162
round += 1;
163163
}
164164

165-
let mut expected =
166-
match props.pp_exact {
167-
Some(ref file) => {
165+
let mut expected = match props.pp_exact {
166+
Some(ref file) => {
168167
let filepath = testfile.dir_path().push_rel(file);
169168
io::read_whole_file_str(&filepath).unwrap()
170169
}
@@ -413,8 +412,8 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
413412
}
414413
}
415414

416-
for i in range(0u, found_flags.len()) {
417-
if !found_flags[i] {
415+
for (i, &flag) in found_flags.iter().enumerate() {
416+
if !flag {
418417
let ee = &expected_errors[i];
419418
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",
420419
ee.kind, ee.line, ee.msg), ProcRes);

src/etc/gedit/share/gtksourceview-3.0/language-specs/rust.lang

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<keyword>for</keyword>
5151
<keyword>if</keyword>
5252
<keyword>impl</keyword>
53+
<keyword>in</keyword>
5354
<keyword>let</keyword>
5455
<keyword>log</keyword>
5556
<keyword>loop</keyword>

src/libextra/arc.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ mod tests {
611611
}
612612
}
613613
}
614+
614615
#[test] #[should_fail] #[ignore(cfg(windows))]
615616
fn test_arc_condvar_poison() {
616617
unsafe {
@@ -846,22 +847,16 @@ mod tests {
846847
}
847848
assert_eq!(*state, 42);
848849
*state = 31337;
849-
// FIXME: #7372: hits type inference bug with iterators
850850
// send to other readers
851-
for i in range(0u, reader_convos.len()) {
852-
match reader_convos[i] {
853-
(ref rc, _) => rc.send(()),
854-
}
851+
for &(ref rc, _) in reader_convos.iter() {
852+
rc.send(())
855853
}
856854
}
857855
let read_mode = arc.downgrade(write_mode);
858856
do (&read_mode).read |state| {
859-
// FIXME: #7372: hits type inference bug with iterators
860857
// complete handshake with other readers
861-
for i in range(0u, reader_convos.len()) {
862-
match reader_convos[i] {
863-
(_, ref rp) => rp.recv(),
864-
}
858+
for &(_, ref rp) in reader_convos.iter() {
859+
rp.recv()
865860
}
866861
wc1.send(()); // tell writer to try again
867862
assert_eq!(*state, 31337);

src/libextra/bitv.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,24 @@ impl BigBitv {
145145
let len = b.storage.len();
146146
assert_eq!(self.storage.len(), len);
147147
let mut changed = false;
148-
for i in range(0, len) {
148+
for (i, (a, b)) in self.storage.mut_iter()
149+
.zip(b.storage.iter())
150+
.enumerate() {
149151
let mask = big_mask(nbits, i);
150-
let w0 = self.storage[i] & mask;
151-
let w1 = b.storage[i] & mask;
152+
let w0 = *a & mask;
153+
let w1 = *b & mask;
152154
let w = op(w0, w1) & mask;
153155
if w0 != w {
154156
changed = true;
155-
self.storage[i] = w;
157+
*a = w;
156158
}
157159
}
158160
changed
159161
}
160162

161163
#[inline]
162164
pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool {
163-
range(0u, self.storage.len()).advance(|i| op(&mut self.storage[i]))
165+
self.storage.mut_iter().advance(|elt| op(elt))
164166
}
165167

166168
#[inline]
@@ -205,10 +207,9 @@ impl BigBitv {
205207

206208
#[inline]
207209
pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
208-
let len = b.storage.len();
209-
for i in range(0, len) {
210+
for (i, elt) in b.storage.iter().enumerate() {
210211
let mask = big_mask(nbits, i);
211-
if mask & self.storage[i] != mask & b.storage[i] {
212+
if mask & self.storage[i] != mask & *elt {
212213
return false;
213214
}
214215
}

src/libextra/dlist.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<T> DList<T> {
164164
/// Remove the first Node and return it, or None if the list is empty
165165
#[inline]
166166
fn pop_front_node(&mut self) -> Option<~Node<T>> {
167-
do self.list_head.take().map_consume |mut front_node| {
167+
do self.list_head.take().map_move |mut front_node| {
168168
self.length -= 1;
169169
match front_node.next.take() {
170170
Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
@@ -190,7 +190,7 @@ impl<T> DList<T> {
190190
/// Remove the last Node and return it, or None if the list is empty
191191
#[inline]
192192
fn pop_back_node(&mut self) -> Option<~Node<T>> {
193-
do self.list_tail.resolve().map_consume_default(None) |tail| {
193+
do self.list_tail.resolve().map_move_default(None) |tail| {
194194
self.length -= 1;
195195
self.list_tail = tail.prev;
196196
match tail.prev.resolve() {
@@ -237,7 +237,7 @@ impl<T> Deque<T> for DList<T> {
237237
///
238238
/// O(1)
239239
fn pop_front(&mut self) -> Option<T> {
240-
self.pop_front_node().map_consume(|~Node{value, _}| value)
240+
self.pop_front_node().map_move(|~Node{value, _}| value)
241241
}
242242

243243
/// Add an element last in the list
@@ -251,7 +251,7 @@ impl<T> Deque<T> for DList<T> {
251251
///
252252
/// O(1)
253253
fn pop_back(&mut self) -> Option<T> {
254-
self.pop_back_node().map_consume(|~Node{value, _}| value)
254+
self.pop_back_node().map_move(|~Node{value, _}| value)
255255
}
256256
}
257257

@@ -267,7 +267,7 @@ impl<T> DList<T> {
267267
/// If the list is empty, do nothing.
268268
#[inline]
269269
pub fn rotate_forward(&mut self) {
270-
do self.pop_back_node().map_consume |tail| {
270+
do self.pop_back_node().map_move |tail| {
271271
self.push_front_node(tail)
272272
};
273273
}
@@ -277,7 +277,7 @@ impl<T> DList<T> {
277277
/// If the list is empty, do nothing.
278278
#[inline]
279279
pub fn rotate_backward(&mut self) {
280-
do self.pop_front_node().map_consume |head| {
280+
do self.pop_front_node().map_move |head| {
281281
self.push_back_node(head)
282282
};
283283
}
@@ -463,7 +463,7 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> {
463463
if self.nelem == 0 {
464464
return None;
465465
}
466-
do self.tail.resolve().map_consume |prev| {
466+
do self.tail.resolve().map_move |prev| {
467467
self.nelem -= 1;
468468
self.tail = prev.prev;
469469
&prev.value
@@ -477,7 +477,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
477477
if self.nelem == 0 {
478478
return None;
479479
}
480-
do self.head.resolve().map_consume |next| {
480+
do self.head.resolve().map_move |next| {
481481
self.nelem -= 1;
482482
self.head = match next.next {
483483
Some(ref mut node) => Rawlink::some(&mut **node),
@@ -499,7 +499,7 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A>
499499
if self.nelem == 0 {
500500
return None;
501501
}
502-
do self.tail.resolve().map_consume |prev| {
502+
do self.tail.resolve().map_move |prev| {
503503
self.nelem -= 1;
504504
self.tail = prev.prev;
505505
&mut prev.value
@@ -553,7 +553,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
553553
if self.nelem == 0 {
554554
return None
555555
}
556-
self.head.resolve().map_consume(|head| &mut head.value)
556+
self.head.resolve().map_move(|head| &mut head.value)
557557
}
558558
}
559559

0 commit comments

Comments
 (0)