Skip to content

Commit f5bee7e

Browse files
committed
---
yaml --- r: 179689 b: refs/heads/auto c: 7fcc330 h: refs/heads/master i: 179687: f304d27 v: v3
1 parent 94d4b49 commit f5bee7e

File tree

483 files changed

+7905
-3737
lines changed

Some content is hidden

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

483 files changed

+7905
-3737
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: d3c787a94f2b66f337334e71634b1c80a359f0bd
13+
refs/heads/auto: 7fcc330ea3a5cbe9b861edf05b74d332b53a64b0
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/configure

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,7 @@ probe CFG_GRUN grun
653653
probe CFG_FLEX flex
654654
probe CFG_BISON bison
655655
probe CFG_PANDOC pandoc
656-
probe CFG_PDFLATEX pdflatex
657656
probe CFG_XELATEX xelatex
658-
probe CFG_LUALATEX lualatex
659657
probe CFG_GDB gdb
660658
probe CFG_LLDB lldb
661659

branches/auto/mk/docs.mk

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,16 @@ else
8585
HTML_DEPS :=
8686
endif
8787

88-
# Check for the various external utilities for the EPUB/PDF docs:
89-
90-
ifeq ($(CFG_LUALATEX),)
91-
$(info cfg: no lualatex found, deferring to xelatex)
92-
ifeq ($(CFG_XELATEX),)
93-
$(info cfg: no xelatex found, deferring to pdflatex)
94-
ifeq ($(CFG_PDFLATEX),)
95-
$(info cfg: no pdflatex found, disabling LaTeX docs)
96-
NO_PDF_DOCS = 1
97-
else
98-
CFG_LATEX := $(CFG_PDFLATEX)
99-
endif
100-
else
88+
# Check for xelatex
89+
90+
ifeq ($(CFG_XELATEX),)
10191
CFG_LATEX := $(CFG_XELATEX)
10292
XELATEX = 1
103-
endif
104-
else
105-
CFG_LATEX := $(CFG_LUALATEX)
93+
else
94+
$(info cfg: no xelatex found, disabling LaTeX docs)
95+
NO_PDF_DOCS = 1
10696
endif
10797

108-
10998
ifeq ($(CFG_PANDOC),)
11099
$(info cfg: no pandoc found, omitting PDF and EPUB docs)
111100
ONLY_HTML_DOCS = 1

branches/auto/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/auto/src/compiletest/compiletest.rs

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

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

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

branches/auto/src/doc/grammar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ token : simple_token | ident | literal | symbol | whitespace token ;
157157

158158
| | | | | |
159159
|----------|----------|----------|----------|--------|
160-
| abstract | alignof | as | be | box |
160+
| abstract | alignof | as | become | box |
161161
| break | const | continue | crate | do |
162162
| else | enum | extern | false | final |
163163
| fn | for | if | impl | in |

branches/auto/src/doc/reference.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ grammar as double-quoted strings. Other tokens have exact rules given.
189189

190190
| | | | | |
191191
|----------|----------|----------|----------|---------|
192-
| abstract | alignof | as | be | box |
192+
| abstract | alignof | as | become | box |
193193
| break | const | continue | crate | do |
194194
| else | enum | extern | false | final |
195195
| fn | for | if | impl | in |
@@ -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_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 |
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 |
264264

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

@@ -1813,7 +1813,6 @@ 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)]
18171816
# fn main() {}
18181817
// Declare a private struct
18191818
struct Foo;
@@ -2015,6 +2014,11 @@ type int8_t = i8;
20152014
- `no_start` - disable linking to the `native` crate, which specifies the
20162015
"start" language item.
20172016
- `no_std` - disable linking to the `std` crate.
2017+
- `plugin` — load a list of named crates as compiler plugins, e.g.
2018+
`#![plugin(foo, bar)]`. Optional arguments for each plugin,
2019+
i.e. `#![plugin(foo(... args ...))]`, are provided to the plugin's
2020+
registrar function. The `plugin` feature gate is required to use
2021+
this attribute.
20182022

20192023
### Module-only attributes
20202024

@@ -2083,7 +2087,7 @@ On `struct`s:
20832087
remove any padding between fields (note that this is very fragile and may
20842088
break platforms which require aligned access).
20852089

2086-
### Macro- and plugin-related attributes
2090+
### Macro-related attributes
20872091

20882092
- `macro_use` on a `mod` — macros defined in this module will be visible in the
20892093
module's parent, after this module has been included.
@@ -2098,13 +2102,8 @@ On `struct`s:
20982102

20992103
- `macro_export` - export a macro for cross-crate usage.
21002104

2101-
- `plugin` on an `extern crate` — load this crate as a [compiler
2102-
plugin][plugin]. The `plugin` feature gate is required. Any arguments to
2103-
the attribute, e.g. `#[plugin=...]` or `#[plugin(...)]`, are provided to the
2104-
plugin.
2105-
2106-
- `no_link` on an `extern crate` — even if we load this crate for macros or
2107-
compiler plugins, don't link it into the output.
2105+
- `no_link` on an `extern crate` — even if we load this crate for macros, don't
2106+
link it into the output.
21082107

21092108
See the [macros section of the
21102109
book](book/macros.html#scoping-and-macro-import/export) for more information on
@@ -2468,6 +2467,12 @@ The currently implemented features of the reference compiler are:
24682467

24692468
* `associated_types` - Allows type aliases in traits. Experimental.
24702469

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+
24712476
If a feature is promoted to a language feature, then all existing programs will
24722477
start to receive compilation warnings about #[feature] directives which enabled
24732478
the new feature (because the directive is no longer necessary). However, if a

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

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

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

220274
```{rust}
221275
enum Ordering {
@@ -225,14 +279,9 @@ enum Ordering {
225279
}
226280
```
227281

228-
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
229-
time.
230-
231-
Because `Ordering` is provided by the standard library, we can use the `use`
232-
keyword to use it in our code. We'll learn more about `use` later, but it's
233-
used to bring names into scope.
234-
235-
Here's an example of how to use `Ordering`:
282+
Because we did not define `Ordering`, we must import it (from the std
283+
library) with the `use` keyword. Here's an example of how `Ordering` is
284+
used:
236285

237286
```{rust}
238287
use std::cmp::Ordering;
@@ -259,11 +308,10 @@ fn main() {
259308
}
260309
```
261310

262-
There's a symbol here we haven't seen before: the double colon (`::`).
263-
This is used to indicate a namespace. In this case, `Ordering` lives in
264-
the `cmp` submodule of the `std` module. We'll talk more about modules
265-
later in the guide. For now, all you need to know is that you can `use`
266-
things from the standard library if you need them.
311+
The `::` symbol is used to indicate a namespace. In this case, `Ordering` lives
312+
in the `cmp` submodule of the `std` module. We'll talk more about modules later
313+
in the guide. For now, all you need to know is that you can `use` things from
314+
the standard library if you need them.
267315

268316
Okay, let's talk about the actual code in the example. `cmp` is a function that
269317
compares two things, and returns an `Ordering`. We return either
@@ -273,95 +321,44 @@ the two values are less, greater, or equal. Note that each variant of the
273321
`Greater`.
274322

275323
The `ordering` variable has the type `Ordering`, and so contains one of the
276-
three values. We can then do a bunch of `if`/`else` comparisons to check which
277-
one it is. However, repeated `if`/`else` comparisons get quite tedious. Rust
278-
has a feature that not only makes them nicer to read, but also makes sure that
279-
you never miss a case. Before we get to that, though, let's talk about another
280-
kind of enum: one with values.
324+
three values. We then do a bunch of `if`/`else` comparisons to check which
325+
one it is.
281326

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

284330
```{rust}
285-
enum OptionalInt {
286-
Value(i32),
287-
Missing,
288-
}
289-
```
290-
291-
This enum represents an `i32` that we may or may not have. In the `Missing`
292-
case, we have no value, but in the `Value` case, we do. This enum is specific
293-
to `i32`s, though. We can make it usable by any type, but we haven't quite
294-
gotten there yet!
295-
296-
You can also have any number of values in an enum:
331+
use std::cmp::Ordering::{self, Equal, Less, Greater};
297332
298-
```{rust}
299-
enum OptionalColor {
300-
Color(i32, i32, i32),
301-
Missing,
302-
}
303-
```
304-
305-
And you can also have something like this:
306-
307-
```{rust}
308-
enum StringResult {
309-
StringOK(String),
310-
ErrorReason(String),
333+
fn cmp(a: i32, b: i32) -> Ordering {
334+
if a < b { Less }
335+
else if a > b { Greater }
336+
else { Equal }
311337
}
312-
```
313-
Where a `StringResult` is either a `StringResult::StringOK`, with the result of
314-
a computation, or a `StringResult::ErrorReason` with a `String` explaining
315-
what caused the computation to fail. These kinds of `enum`s are actually very
316-
useful and are even part of the standard library.
317338
318-
Here is an example of using our `StringResult`:
339+
fn main() {
340+
let x = 5;
341+
let y = 10;
319342
320-
```rust
321-
enum StringResult {
322-
StringOK(String),
323-
ErrorReason(String),
324-
}
343+
let ordering = cmp(x, y); // ordering: Ordering
325344
326-
fn respond(greeting: &str) -> StringResult {
327-
if greeting == "Hello" {
328-
StringResult::StringOK("Good morning!".to_string())
329-
} else {
330-
StringResult::ErrorReason("I didn't understand you!".to_string())
331-
}
345+
if ordering == Less { println!("less"); }
346+
else if ordering == Greater { println!("greater"); }
347+
else if ordering == Equal { println!("equal"); }
332348
}
333349
```
334350

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

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

341-
enum StringResult {
342-
StringOK(String),
343-
ErrorReason(String),
344-
}
345-
346-
# fn main() {}
347-
348-
fn respond(greeting: &str) -> StringResult {
349-
if greeting == "Hello" {
350-
StringOK("Good morning!".to_string())
351-
} else {
352-
ErrorReason("I didn't understand you!".to_string())
353-
}
354-
}
355-
```
356361

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

0 commit comments

Comments
 (0)