Skip to content

Commit a7f85f1

Browse files
committed
---
yaml --- r: 187359 b: refs/heads/try c: b711b6a h: refs/heads/master i: 187357: 62a6561 187355: d6c3215 187351: a95df7f 187343: 2c5664c 187327: 2fb0c5b v: v3
1 parent 6e996c3 commit a7f85f1

File tree

177 files changed

+2439
-1850
lines changed

Some content is hidden

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

177 files changed

+2439
-1850
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b4c965ee803a4521d8b4575f634e036f93e408f3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 3a96d6a9818fe2affc98a187fb1065120458cee9
5-
refs/heads/try: 23f5a8f82de85a82a8551b51c2526e34d229ba10
5+
refs/heads/try: b711b6a5b2bc52ca27d75d5031239dbac92e42e2
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/doc/reference.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ fn needs_foo_or_bar() {
21652165
21662166
// This function is only included when compiling for a unixish OS with a 32-bit
21672167
// architecture
2168-
#[cfg(all(unix, target_word_size = "32"))]
2168+
#[cfg(all(unix, target_pointer_width = "32"))]
21692169
fn on_32bit_unix() {
21702170
// ...
21712171
}
@@ -2193,9 +2193,9 @@ The following configurations must be defined by the implementation:
21932193
* `target_os = "..."`. Operating system of the target, examples include
21942194
`"win32"`, `"macos"`, `"linux"`, `"android"`, `"freebsd"`, `"dragonfly"`,
21952195
`"bitrig"` or `"openbsd"`.
2196-
* `target_word_size = "..."`. Target word size in bits. This is set to `"32"`
2197-
for targets with 32-bit pointers, and likewise set to `"64"` for 64-bit
2198-
pointers.
2196+
* `target_pointer_width = "..."`. Target pointer width in bits. This is set
2197+
to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for
2198+
64-bit pointers.
21992199
* `unix`. See `target_family`.
22002200
* `windows`. See `target_family`.
22012201

branches/try/src/doc/rust.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
/* General structure */
5757

5858
body {
59+
background-color: white;
5960
margin: 0 auto;
6061
padding: 0 15px;
6162
font-family: "Source Serif Pro", Georgia, Times, "Times New Roman", serif;

branches/try/src/doc/trpl/error-handling.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,78 @@ let input = io::stdin().read_line()
223223
.ok()
224224
.expect("Failed to read line");
225225
```
226+
226227
`ok()` converts the `IoResult` into an `Option`, and `expect()` does the same
227228
thing as `unwrap()`, but takes a message. This message is passed along to the
228229
underlying `panic!`, providing a better error message if the code errors.
230+
231+
# Using `try!`
232+
233+
When writing code that calls many functions that return the `Result` type, the
234+
error handling can be tedious. The `try!` macro hides some of the boilerplate
235+
of propagating errors up the call stack.
236+
237+
It replaces this:
238+
239+
```rust
240+
use std::fs::File;
241+
use std::io;
242+
use std::io::prelude::*;
243+
244+
struct Info {
245+
name: String,
246+
age: i32,
247+
rating: i32,
248+
}
249+
250+
fn write_info(info: &Info) -> io::Result<()> {
251+
let mut file = File::open("my_best_friends.txt").unwrap();
252+
253+
if let Err(e) = writeln!(&mut file, "name: {}", info.name) {
254+
return Err(e)
255+
}
256+
if let Err(e) = writeln!(&mut file, "age: {}", info.age) {
257+
return Err(e)
258+
}
259+
if let Err(e) = writeln!(&mut file, "rating: {}", info.rating) {
260+
return Err(e)
261+
}
262+
263+
return Ok(());
264+
}
265+
```
266+
267+
With this:
268+
269+
```rust
270+
use std::fs::File;
271+
use std::io;
272+
use std::io::prelude::*;
273+
274+
struct Info {
275+
name: String,
276+
age: i32,
277+
rating: i32,
278+
}
279+
280+
fn write_info(info: &Info) -> io::Result<()> {
281+
let mut file = try!(File::open("my_best_friends.txt"));
282+
283+
try!(writeln!(&mut file, "name: {}", info.name));
284+
try!(writeln!(&mut file, "age: {}", info.age));
285+
try!(writeln!(&mut file, "rating: {}", info.rating));
286+
287+
return Ok(());
288+
}
289+
```
290+
291+
Wrapping an expression in `try!` will result in the unwrapped success (`Ok`)
292+
value, unless the result is `Err`, in which case `Err` is returned early from
293+
the enclosing function.
294+
295+
It's worth noting that you can only use `try!` from a function that returns a
296+
`Result`, which means that you cannot use `try!` inside of `main()`, because
297+
`main()` doesn't return anything.
298+
299+
`try!` makes use of [`FromError`](../std/error/#the-fromerror-trait) to determine
300+
what to return in the error case.

branches/try/src/doc/trpl/macros.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ macro_rules! vec {
7373
};
7474
}
7575
# fn main() {
76-
# assert_eq!(&[1,2,3], &vec![1,2,3]);
76+
# assert_eq!([1,2,3], vec![1,2,3]);
7777
# }
7878
```
7979

branches/try/src/doc/trpl/pointers.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -361,16 +361,16 @@ duration a *lifetime*. Let's try a more complex example:
361361

362362
```{rust}
363363
fn main() {
364-
let x = &mut 5;
364+
let mut x = 5;
365365
366-
if *x < 10 {
366+
if x < 10 {
367367
let y = &x;
368368
369369
println!("Oh no: {}", y);
370370
return;
371371
}
372372
373-
*x -= 1;
373+
x -= 1;
374374
375375
println!("Oh no: {}", x);
376376
}
@@ -382,17 +382,18 @@ mutated, and therefore, lets us pass. This wouldn't work:
382382

383383
```{rust,ignore}
384384
fn main() {
385-
let x = &mut 5;
385+
let mut x = 5;
386386
387-
if *x < 10 {
387+
if x < 10 {
388388
let y = &x;
389-
*x -= 1;
389+
390+
x -= 1;
390391
391392
println!("Oh no: {}", y);
392393
return;
393394
}
394395
395-
*x -= 1;
396+
x -= 1;
396397
397398
println!("Oh no: {}", x);
398399
}
@@ -401,12 +402,12 @@ fn main() {
401402
It gives this error:
402403

403404
```text
404-
test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed
405-
test.rs:5 *x -= 1;
406-
^~
407-
test.rs:4:16: 4:18 note: borrow of `*x` occurs here
408-
test.rs:4 let y = &x;
409-
^~
405+
test.rs:7:9: 7:15 error: cannot assign to `x` because it is borrowed
406+
test.rs:7 x -= 1;
407+
^~~~~~
408+
test.rs:5:18: 5:19 note: borrow of `x` occurs here
409+
test.rs:5 let y = &x;
410+
^
410411
```
411412

412413
As you might guess, this kind of analysis is complex for a human, and therefore

branches/try/src/doc/trpl/static-and-dynamic-dispatch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ dynamic dispatch is sometimes more efficient.
9393

9494
However, the common case is that it is more efficient to use static dispatch,
9595
and one can always have a thin statically-dispatched wrapper function that does
96-
a dynamic, but not vice versa, meaning static calls are more flexible. The
97-
standard library tries to be statically dispatched where possible for this
96+
a dynamic dispatch, but not vice versa, meaning static calls are more flexible.
97+
The standard library tries to be statically dispatched where possible for this
9898
reason.
9999

100100
## Dynamic dispatch

branches/try/src/libcollections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<T: Ord> BinaryHeap<T> {
480480
/// heap.push(3);
481481
///
482482
/// let vec = heap.into_sorted_vec();
483-
/// assert_eq!(vec, vec![1, 2, 3, 4, 5, 6, 7]);
483+
/// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);
484484
/// ```
485485
pub fn into_sorted_vec(mut self) -> Vec<T> {
486486
let mut end = self.len();

branches/try/src/libcollections/bit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,13 @@ impl BitVec {
640640
/// let mut bv = BitVec::from_elem(3, true);
641641
/// bv.set(1, false);
642642
///
643-
/// assert_eq!(bv.to_bytes(), vec!(0b10100000));
643+
/// assert_eq!(bv.to_bytes(), [0b10100000]);
644644
///
645645
/// let mut bv = BitVec::from_elem(9, false);
646646
/// bv.set(2, true);
647647
/// bv.set(8, true);
648648
///
649-
/// assert_eq!(bv.to_bytes(), vec!(0b00100000, 0b10000000));
649+
/// assert_eq!(bv.to_bytes(), [0b00100000, 0b10000000]);
650650
/// ```
651651
pub fn to_bytes(&self) -> Vec<u8> {
652652
fn bit(bit_vec: &BitVec, byte: usize, bit: usize) -> u8 {
@@ -806,7 +806,7 @@ impl BitVec {
806806
/// let mut bv = BitVec::from_bytes(&[0b01001011]);
807807
/// bv.grow(2, true);
808808
/// assert_eq!(bv.len(), 10);
809-
/// assert_eq!(bv.to_bytes(), vec!(0b01001011, 0b11000000));
809+
/// assert_eq!(bv.to_bytes(), [0b01001011, 0b11000000]);
810810
/// ```
811811
pub fn grow(&mut self, n: usize, value: bool) {
812812
// Note: we just bulk set all the bits in the last word in this fn in multiple places
@@ -2285,12 +2285,12 @@ mod tests {
22852285
fn test_to_bytes() {
22862286
let mut bv = BitVec::from_elem(3, true);
22872287
bv.set(1, false);
2288-
assert_eq!(bv.to_bytes(), vec!(0b10100000));
2288+
assert_eq!(bv.to_bytes(), [0b10100000]);
22892289

22902290
let mut bv = BitVec::from_elem(9, false);
22912291
bv.set(2, true);
22922292
bv.set(8, true);
2293-
assert_eq!(bv.to_bytes(), vec!(0b00100000, 0b10000000));
2293+
assert_eq!(bv.to_bytes(), [0b00100000, 0b10000000]);
22942294
}
22952295

22962296
#[test]
@@ -2675,7 +2675,7 @@ mod bit_set_test {
26752675
let bit_vec: BitSet = usizes.into_iter().collect();
26762676

26772677
let idxs: Vec<_> = bit_vec.iter().collect();
2678-
assert_eq!(idxs, vec![0, 2, 3]);
2678+
assert_eq!(idxs, [0, 2, 3]);
26792679

26802680
let long: BitSet = (0..10000).filter(|&n| n % 2 == 0).collect();
26812681
let real: Vec<_> = range_step(0, 10000, 2).collect();

branches/try/src/libcollections/borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<T> ToOwned for T where T: Clone {
132132
/// ```rust
133133
/// use std::borrow::Cow;
134134
///
135-
/// fn abs_all(input: &mut Cow<[int]>) {
135+
/// fn abs_all(input: &mut Cow<[i32]>) {
136136
/// for i in 0..input.len() {
137137
/// let v = input[i];
138138
/// if v < 0 {

branches/try/src/libcollections/btree/map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
347347
let result = stack.with(move |pusher, node| {
348348
// Same basic logic as found in `find`, but with PartialSearchStack mediating the
349349
// actual nodes for us
350-
return match Node::search(node, &key) {
350+
match Node::search(node, &key) {
351351
Found(mut handle) => {
352352
// Perfect match, swap the values and return the old one
353353
mem::swap(handle.val_mut(), &mut value);
@@ -372,7 +372,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
372372
}
373373
});
374374
match result {
375-
Finished(ret) => { return ret; },
375+
Finished(ret) => return ret,
376376
Continue((new_stack, renewed_key, renewed_val)) => {
377377
stack = new_stack;
378378
key = renewed_key;
@@ -439,7 +439,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
439439
let mut stack = stack::PartialSearchStack::new(self);
440440
loop {
441441
let result = stack.with(move |pusher, node| {
442-
return match Node::search(node, key) {
442+
match Node::search(node, key) {
443443
Found(handle) => {
444444
// Perfect match. Terminate the stack here, and remove the entry
445445
Finished(Some(pusher.seal(handle).remove()))
@@ -1281,7 +1281,7 @@ impl<K, V> BTreeMap<K, V> {
12811281
/// a.insert(2, "b");
12821282
///
12831283
/// let keys: Vec<usize> = a.keys().cloned().collect();
1284-
/// assert_eq!(keys, vec![1,2,]);
1284+
/// assert_eq!(keys, [1, 2]);
12851285
/// ```
12861286
#[stable(feature = "rust1", since = "1.0.0")]
12871287
pub fn keys<'a>(&'a self) -> Keys<'a, K, V> {
@@ -1303,7 +1303,7 @@ impl<K, V> BTreeMap<K, V> {
13031303
/// a.insert(2, "b");
13041304
///
13051305
/// let values: Vec<&str> = a.values().cloned().collect();
1306-
/// assert_eq!(values, vec!["a","b"]);
1306+
/// assert_eq!(values, ["a", "b"]);
13071307
/// ```
13081308
#[stable(feature = "rust1", since = "1.0.0")]
13091309
pub fn values<'a>(&'a self) -> Values<'a, K, V> {
@@ -1560,7 +1560,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
15601560
let mut stack = stack::PartialSearchStack::new(self);
15611561
loop {
15621562
let result = stack.with(move |pusher, node| {
1563-
return match Node::search(node, &key) {
1563+
match Node::search(node, &key) {
15641564
Found(handle) => {
15651565
// Perfect match
15661566
Finished(Occupied(OccupiedEntry {

0 commit comments

Comments
 (0)