Skip to content

Commit f870e93

Browse files
committed
---
yaml --- r: 186343 b: refs/heads/try c: 48b6aef h: refs/heads/master i: 186341: 07894ec 186339: a74d28a 186335: 4c1cb5d v: v3
1 parent 0851026 commit f870e93

File tree

184 files changed

+2552
-2578
lines changed

Some content is hidden

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

184 files changed

+2552
-2578
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: a08504bb35f5cb36b702750ba105063d1e2972ff
5+
refs/heads/try: 48b6aef6605794a9da0d9254960a91bbea0a0737
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/compiletest/compiletest.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
118118
}
119119

120120
fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
121-
match m.opt_str(nm) {
122-
Some(s) => Path::new(s),
123-
None => panic!("no option (=path) found for {}", nm),
124-
}
121+
Path::new(m.opt_str(nm).unwrap())
125122
}
126123

127124
let filter = if !matches.free.is_empty() {

branches/try/src/doc/reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,7 @@ default visibility with the `priv` keyword. When an item is declared as `pub`,
18131813
it can be thought of as being accessible to the outside world. For example:
18141814

18151815
```
1816+
# #![allow(missing_copy_implementations)]
18161817
# fn main() {}
18171818
// Declare a private struct
18181819
struct Foo;

branches/try/src/doc/trpl/compound-data-types.md

Lines changed: 93 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -200,62 +200,8 @@ destructuring `let`, as we discussed previously in 'tuples.' In this case, the
200200
## Enums
201201

202202
Finally, Rust has a "sum type", an *enum*. Enums are an incredibly useful
203-
feature of Rust, and are used throughout the standard library. An `enum` is
204-
a type which ties a set of alternates to a specific name. For example, below
205-
we define `Character` to be either a `Digit` or something else. These
206-
can be used via their fully scoped names: `Character::Other` (more about `::`
207-
below).
208-
209-
```rust
210-
enum Character {
211-
Digit(i32),
212-
Other,
213-
}
214-
```
215-
216-
An `enum` variant can be defined as most normal types. Below are some example
217-
types have been listed which also would be allowed in an `enum`.
218-
219-
```rust
220-
struct Empty;
221-
struct Color(i32, i32, i32);
222-
struct Length(i32);
223-
struct Status { Health: i32, Mana: i32, Attack: i32, Defense: i32 }
224-
struct HeightDatabase(Vec<i32>);
225-
```
226-
227-
So you see that depending on the sub-datastructure, the `enum` variant, same as
228-
a struct, may or may not hold data. That is, in `Character`, `Digit` is a name
229-
tied to an `i32` where `Other` is just a name. However, the fact that they are
230-
distinct makes this very useful.
231-
232-
As with structures, enums don't by default have access to operators such as
233-
compare ( `==` and `!=`), binary operations (`*` and `+`), and order
234-
(`<` and `>=`). As such, using the previous `Character` type, the
235-
following code is invalid:
236-
237-
```{rust,ignore}
238-
// These assignments both succeed
239-
let ten = Character::Digit(10);
240-
let four = Character::Digit(4);
241-
242-
// Error: `*` is not implemented for type `Character`
243-
let forty = ten * four;
244-
245-
// Error: `<=` is not implemented for type `Character`
246-
let four_is_smaller = four <= ten;
247-
248-
// Error: `==` is not implemented for type `Character`
249-
let four_equals_ten = four == ten;
250-
```
251-
252-
This may seem rather limiting, particularly equality being invalid; in
253-
many cases however, it's unnecessary. Rust provides the [`match`][match]
254-
keyword, which will be examined in more detail in the next section, which
255-
often allows better and easier branch control than a series of `if`/`else`
256-
statements would. However, for our [game][game] we need the comparisons
257-
to work so we will utilize the `Ordering` `enum` provided by the standard
258-
library which supports such comparisons. It has this form:
203+
feature of Rust, and are used throughout the standard library. This is an enum
204+
that is provided by the Rust standard library:
259205

260206
```{rust}
261207
enum Ordering {
@@ -265,9 +211,14 @@ enum Ordering {
265211
}
266212
```
267213

268-
Because we did not define `Ordering`, we must import it (from the std
269-
library) with the `use` keyword. Here's an example of how `Ordering` is
270-
used:
214+
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
215+
time.
216+
217+
Because `Ordering` is provided by the standard library, we can use the `use`
218+
keyword to use it in our code. We'll learn more about `use` later, but it's
219+
used to bring names into scope.
220+
221+
Here's an example of how to use `Ordering`:
271222

272223
```{rust}
273224
use std::cmp::Ordering;
@@ -294,10 +245,11 @@ fn main() {
294245
}
295246
```
296247

297-
The `::` symbol is used to indicate a namespace. In this case, `Ordering` lives
298-
in the `cmp` submodule of the `std` module. We'll talk more about modules later
299-
in the guide. For now, all you need to know is that you can `use` things from
300-
the standard library if you need them.
248+
There's a symbol here we haven't seen before: the double colon (`::`).
249+
This is used to indicate a namespace. In this case, `Ordering` lives in
250+
the `cmp` submodule of the `std` module. We'll talk more about modules
251+
later in the guide. For now, all you need to know is that you can `use`
252+
things from the standard library if you need them.
301253

302254
Okay, let's talk about the actual code in the example. `cmp` is a function that
303255
compares two things, and returns an `Ordering`. We return either
@@ -307,44 +259,95 @@ the two values are less, greater, or equal. Note that each variant of the
307259
`Greater`.
308260

309261
The `ordering` variable has the type `Ordering`, and so contains one of the
310-
three values. We then do a bunch of `if`/`else` comparisons to check which
311-
one it is.
262+
three values. We can then do a bunch of `if`/`else` comparisons to check which
263+
one it is. However, repeated `if`/`else` comparisons get quite tedious. Rust
264+
has a feature that not only makes them nicer to read, but also makes sure that
265+
you never miss a case. Before we get to that, though, let's talk about another
266+
kind of enum: one with values.
312267

313-
This `Ordering::Greater` notation is too long. Lets use `use` to import can
314-
the `enum` variants instead. This will avoid full scoping:
268+
This enum has two variants, one of which has a value:
315269

316270
```{rust}
317-
use std::cmp::Ordering::{self, Equal, Less, Greater};
271+
enum OptionalInt {
272+
Value(i32),
273+
Missing,
274+
}
275+
```
318276

319-
fn cmp(a: i32, b: i32) -> Ordering {
320-
if a < b { Less }
321-
else if a > b { Greater }
322-
else { Equal }
277+
This enum represents an `i32` that we may or may not have. In the `Missing`
278+
case, we have no value, but in the `Value` case, we do. This enum is specific
279+
to `i32`s, though. We can make it usable by any type, but we haven't quite
280+
gotten there yet!
281+
282+
You can also have any number of values in an enum:
283+
284+
```{rust}
285+
enum OptionalColor {
286+
Color(i32, i32, i32),
287+
Missing,
323288
}
289+
```
324290

325-
fn main() {
326-
let x = 5;
327-
let y = 10;
291+
And you can also have something like this:
328292

329-
let ordering = cmp(x, y); // ordering: Ordering
293+
```{rust}
294+
enum StringResult {
295+
StringOK(String),
296+
ErrorReason(String),
297+
}
298+
```
299+
Where a `StringResult` is either a `StringResult::StringOK`, with the result of
300+
a computation, or a `StringResult::ErrorReason` with a `String` explaining
301+
what caused the computation to fail. These kinds of `enum`s are actually very
302+
useful and are even part of the standard library.
303+
304+
Here is an example of using our `StringResult`:
330305

331-
if ordering == Less { println!("less"); }
332-
else if ordering == Greater { println!("greater"); }
333-
else if ordering == Equal { println!("equal"); }
306+
```rust
307+
enum StringResult {
308+
StringOK(String),
309+
ErrorReason(String),
310+
}
311+
312+
fn respond(greeting: &str) -> StringResult {
313+
if greeting == "Hello" {
314+
StringResult::StringOK("Good morning!".to_string())
315+
} else {
316+
StringResult::ErrorReason("I didn't understand you!".to_string())
317+
}
334318
}
335319
```
336320

337-
Importing variants is convenient and compact, but can also cause name conflicts,
338-
so do this with caution. It's considered good style to rarely import variants
339-
for this reason.
321+
That's a lot of typing! We can use the `use` keyword to make it shorter:
340322

341-
As you can see, `enum`s are quite a powerful tool for data representation, and are
342-
even more useful when they're [generic][generics] across types. Before we
343-
get to generics, though, let's talk about how to use them with pattern matching, a
344-
tool that will let us deconstruct this sum type (the type theory term for enums)
345-
in a very elegant way and avoid all these messy `if`/`else`s.
323+
```rust
324+
use StringResult::StringOK;
325+
use StringResult::ErrorReason;
346326

327+
enum StringResult {
328+
StringOK(String),
329+
ErrorReason(String),
330+
}
331+
332+
# fn main() {}
333+
334+
fn respond(greeting: &str) -> StringResult {
335+
if greeting == "Hello" {
336+
StringOK("Good morning!".to_string())
337+
} else {
338+
ErrorReason("I didn't understand you!".to_string())
339+
}
340+
}
341+
```
347342

348-
[match]: ./match.html
349-
[game]: ./guessing-game.html#comparing-guesses
350-
[generics]: ./generics.html
343+
`use` declarations must come before anything else, which looks a little strange in this example,
344+
since we `use` the variants before we define them. Anyway, in the body of `respond`, we can just
345+
say `StringOK` now, rather than the full `StringResult::StringOK`. Importing variants can be
346+
convenient, but can also cause name conflicts, so do this with caution. It's considered good style
347+
to rarely import variants for this reason.
348+
349+
As you can see, `enum`s with values are quite a powerful tool for data representation,
350+
and can be even more useful when they're generic across types. Before we get to generics,
351+
though, let's talk about how to use them with pattern matching, a tool that will
352+
let us deconstruct this sum type (the type theory term for enums) in a very elegant
353+
way and avoid all these messy `if`/`else`s.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fn print<'a>(s: &'a str); // expanded
523523
fn debug(lvl: u32, s: &str); // elided
524524
fn debug<'a>(lvl: u32, s: &'a str); // expanded
525525
526-
// In the preceding example, `lvl` doesn't need a lifetime because it's not a
526+
// In the preceeding example, `lvl` doesn't need a lifetime because it's not a
527527
// reference (`&`). Only things relating to references (such as a `struct`
528528
// which contains a reference) need lifetimes.
529529

branches/try/src/etc/featureck.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@
194194
if not name in joint_features:
195195
print "error: feature '" + name + "' is both a lang and lib feature but not whitelisted"
196196
errors = True
197-
lang_status = language_feature_stats[name][3]
197+
lang_status = lang_feature_stats[name][3]
198198
lib_status = lib_feature_stats[name][3]
199-
lang_stable_since = language_feature_stats[name][4]
199+
lang_stable_since = lang_feature_stats[name][4]
200200
lib_stable_since = lib_feature_stats[name][4]
201201

202202
if lang_status != lib_status and lib_status != "deprecated":

branches/try/src/grammar/parser-lalr.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ maybe_stmts
11951195
//
11961196
// There are also two other expr subtypes: first, nonparen_expr
11971197
// disallows exprs surrounded by parens (including tuple expressions),
1198-
// this is necessary for BOX (place) expressions, so a parens expr
1198+
// this is neccesary for BOX (place) expressions, so a parens expr
11991199
// following the BOX is always parsed as the place. There is also
12001200
// expr_norange used in index_expr, which disallows '..' in
12011201
// expressions as that has special meaning inside of brackets.

branches/try/src/liballoc/arc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ impl<T: Sync + Send> Drop for Arc<T> {
311311
///
312312
/// // stuff
313313
///
314-
/// drop(five); // explicit drop
314+
/// drop(five); // explict drop
315315
/// }
316316
/// {
317317
/// let five = Arc::new(5);
@@ -441,7 +441,7 @@ impl<T: Sync + Send> Drop for Weak<T> {
441441
///
442442
/// // stuff
443443
///
444-
/// drop(weak_five); // explicit drop
444+
/// drop(weak_five); // explict drop
445445
/// }
446446
/// {
447447
/// let five = Arc::new(5);

branches/try/src/liballoc/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@
7373
#![feature(unboxed_closures)]
7474
#![feature(core)]
7575
#![feature(hash)]
76-
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
77-
feature(libc))]
78-
76+
#![feature(libc)]
7977

8078
#[macro_use]
8179
extern crate core;

branches/try/src/liballoc/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<T> Drop for Rc<T> {
383383
///
384384
/// // stuff
385385
///
386-
/// drop(five); // explicit drop
386+
/// drop(five); // explict drop
387387
/// }
388388
/// {
389389
/// let five = Rc::new(5);
@@ -688,7 +688,7 @@ impl<T> Drop for Weak<T> {
688688
///
689689
/// // stuff
690690
///
691-
/// drop(weak_five); // explicit drop
691+
/// drop(weak_five); // explict drop
692692
/// }
693693
/// {
694694
/// let five = Rc::new(5);

0 commit comments

Comments
 (0)