Skip to content

Commit afd6428

Browse files
committed
---
yaml --- r: 183293 b: refs/heads/beta c: 01db9a4 h: refs/heads/master i: 183291: 63ac461 v: v3
1 parent a596f27 commit afd6428

File tree

419 files changed

+3188
-4299
lines changed

Some content is hidden

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

419 files changed

+3188
-4299
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: d4a66e9b098e3c322161f0397e932cf6d3c1b15c
34+
refs/heads/beta: 01db9a46af72383811f39091be70e9721aaa159a
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: eb836bf767aa1d8d4cba488a9091cde3c0ab4b2f

branches/beta/mk/tests.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ RPASS_FULL_RS := $(wildcard $(S)src/test/run-pass-fulldeps/*.rs)
452452
CFAIL_FULL_RS := $(wildcard $(S)src/test/compile-fail-fulldeps/*.rs)
453453
RFAIL_RS := $(wildcard $(S)src/test/run-fail/*.rs)
454454
CFAIL_RS := $(wildcard $(S)src/test/compile-fail/*.rs)
455+
PFAIL_RS := $(wildcard $(S)src/test/parse-fail/*.rs)
455456
BENCH_RS := $(wildcard $(S)src/test/bench/*.rs)
456457
PRETTY_RS := $(wildcard $(S)src/test/pretty/*.rs)
457458
DEBUGINFO_GDB_RS := $(wildcard $(S)src/test/debuginfo/*.rs)
@@ -468,7 +469,7 @@ RPASS_VALGRIND_TESTS := $(RPASS_VALGRIND_RS)
468469
RPASS_FULL_TESTS := $(RPASS_FULL_RS)
469470
CFAIL_FULL_TESTS := $(CFAIL_FULL_RS)
470471
RFAIL_TESTS := $(RFAIL_RS)
471-
CFAIL_TESTS := $(CFAIL_RS)
472+
CFAIL_TESTS := $(CFAIL_RS) $(PFAIL_RS)
472473
BENCH_TESTS := $(BENCH_RS)
473474
PERF_TESTS := $(PERF_RS)
474475
PRETTY_TESTS := $(PRETTY_RS)

branches/beta/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/beta/src/doc/reference.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ cases mentioned in [Number literals](#number-literals) below.
256256

257257
| [Number literals](#number-literals)`*` | Example | Exponentiation | Suffixes |
258258
|----------------------------------------|---------|----------------|----------|
259-
| Decimal integer | `98_222` | `N/A` | Integer suffixes |
260-
| Hex integer | `0xff` | `N/A` | Integer suffixes |
261-
| Octal integer | `0o77` | `N/A` | Integer suffixes |
262-
| Binary integer | `0b1111_0000` | `N/A` | Integer suffixes |
263-
| Floating-point | `123.0E+77` | `Optional` | Floating-point suffixes |
259+
| Decimal integer | `98_222is` | `N/A` | Integer suffixes |
260+
| Hex integer | `0xffis` | `N/A` | Integer suffixes |
261+
| Octal integer | `0o77is` | `N/A` | Integer suffixes |
262+
| Binary integer | `0b1111_0000is` | `N/A` | Integer suffixes |
263+
| Floating-point | `123.0E+77f64` | `Optional` | Floating-point suffixes |
264264

265265
`*` All number literals allow `_` as a visual separator: `1_234.0E+18f64`
266266

@@ -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;
@@ -2467,12 +2468,6 @@ The currently implemented features of the reference compiler are:
24672468

24682469
* `associated_types` - Allows type aliases in traits. Experimental.
24692470

2470-
* `no_std` - Allows the `#![no_std]` crate attribute, which disables the implicit
2471-
`extern crate std`. This typically requires use of the unstable APIs
2472-
behind the libstd "facade", such as libcore and libcollections. It
2473-
may also cause problems when using syntax extensions, including
2474-
`#[derive]`.
2475-
24762471
If a feature is promoted to a language feature, then all existing programs will
24772472
start to receive compilation warnings about #[feature] directives which enabled
24782473
the new feature (because the directive is no longer necessary). However, if a

branches/beta/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/beta/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
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
@import url("//static.rust-lang.org/doc/master/rust.css");
3+
4+
body {
5+
max-width:none;
6+
}
7+
8+
#toc {
9+
position: absolute;
10+
left: 0px;
11+
top: 0px;
12+
bottom: 0px;
13+
width: 250px;
14+
overflow-y: auto;
15+
border-right: 1px solid rgba(0, 0, 0, 0.07);
16+
padding: 10px 10px;
17+
font-size: 16px;
18+
background: none repeat scroll 0% 0% #FFF;
19+
box-sizing: border-box;
20+
}
21+
22+
#page-wrapper {
23+
position: absolute;
24+
overflow-y: auto;
25+
left: 260px;
26+
right: 0px;
27+
top: 0px;
28+
bottom: 0px;
29+
box-sizing: border-box;
30+
background: none repeat scroll 0% 0% #FFF;
31+
}
32+
33+
#page {
34+
margin-left: auto;
35+
margin-right:auto;
36+
width: 750px;
37+
}
38+
39+
.chapter {
40+
list-style: none outside none;
41+
padding-left: 0px;
42+
line-height: 30px;
43+
}
44+
45+
.section {
46+
list-style: none outside none;
47+
padding-left: 20px;
48+
line-height: 30px;
49+
}
50+
51+
.section li {
52+
text-overflow: ellipsis;
53+
overflow: hidden;
54+
white-space: nowrap;
55+
}
56+
57+
.chapter li a {
58+
color: #000000;
59+
}

0 commit comments

Comments
 (0)