Skip to content

Commit 081ba06

Browse files
committed
---
yaml --- r: 186355 b: refs/heads/try c: 61626b3 h: refs/heads/master i: 186353: 6f64d1e 186351: d3294b9 v: v3
1 parent c0e973b commit 081ba06

File tree

251 files changed

+3361
-2915
lines changed

Some content is hidden

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

251 files changed

+3361
-2915
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: b445bf2bd1139236fd815bf93610ddaf17726111
5+
refs/heads/try: 61626b306314768b273892e3a547b896ef7a4dfd
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/Makefile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
# * check-stage$(stage)-$(crate) - Test a crate in a specific stage
6060
# * check-stage$(stage)-{rpass,rfail,cfail,rmake,...} - Run tests in src/test/
6161
# * check-stage1-T-$(target)-H-$(host) - Run cross-compiled-tests
62+
# * tidy-basic - show file / line stats
63+
# * tidy-errors - show the highest rustc error code
64+
# * tidy-features - show the status of language and lib features
6265
#
6366
# Then mix in some of these environment variables to harness the
6467
# ultimate power of The Rust Build System.

branches/try/mk/main.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ endif
7272
# numbers and dots here
7373
CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
7474

75+
CFG_INFO := $(info cfg: version $(CFG_VERSION))
7576

7677
######################################################################
7778
# More configuration
@@ -179,6 +180,7 @@ endif
179180

180181
ifndef CFG_DISABLE_VALGRIND_RPASS
181182
$(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
183+
$(info cfg: valgrind-rpass command set to $(CFG_VALGRIND))
182184
CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
183185
else
184186
CFG_VALGRIND_RPASS :=

branches/try/mk/tests.mk

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ $(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
162162
######################################################################
163163

164164
# The main testing target. Tests lots of stuff.
165-
check: cleantmptestlogs cleantestlibs check-notidy tidy
165+
check: cleantmptestlogs cleantestlibs all check-stage2 tidy
166+
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
166167

167168
# As above but don't bother running tidy.
168169
check-notidy: cleantmptestlogs cleantestlibs all check-stage2
@@ -235,57 +236,24 @@ cleantestlibs:
235236
######################################################################
236237

237238
ifdef CFG_NOTIDY
239+
.PHONY: tidy
238240
tidy:
239241
else
240242

241-
ALL_CS := $(wildcard $(S)src/rt/*.cpp \
242-
$(S)src/rt/*/*.cpp \
243-
$(S)src/rt/*/*/*.cpp \
244-
$(S)src/rustllvm/*.cpp)
245-
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
246-
$(wildcard $(S)src/rt/hoedown/src/*.c) \
247-
$(wildcard $(S)src/rt/hoedown/bin/*.c) \
248-
,$(ALL_CS))
249-
ALL_HS := $(wildcard $(S)src/rt/*.h \
250-
$(S)src/rt/*/*.h \
251-
$(S)src/rt/*/*/*.h \
252-
$(S)src/rustllvm/*.h)
253-
ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
254-
$(S)src/rt/valgrind/memcheck.h \
255-
$(S)src/rt/msvc/typeof.h \
256-
$(S)src/rt/msvc/stdint.h \
257-
$(S)src/rt/msvc/inttypes.h \
258-
$(wildcard $(S)src/rt/hoedown/src/*.h) \
259-
$(wildcard $(S)src/rt/hoedown/bin/*.h) \
260-
,$(ALL_HS))
261-
262243
# Run the tidy script in multiple parts to avoid huge 'echo' commands
263-
tidy:
244+
.PHONY: tidy
245+
tidy: tidy-basic tidy-binaries tidy-errors tidy-features
246+
247+
endif
248+
249+
.PHONY: tidy-basic
250+
tidy-basic:
264251
@$(call E, check: formatting)
265-
$(Q)find $(S)src -name '*.r[sc]' \
266-
-and -not -regex '^$(S)src/jemalloc.*' \
267-
-and -not -regex '^$(S)src/libuv.*' \
268-
-and -not -regex '^$(S)src/llvm.*' \
269-
-and -not -regex '^$(S)src/gyp.*' \
270-
-and -not -regex '^$(S)src/libbacktrace.*' \
271-
-print0 \
272-
| xargs -0 -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
273-
$(Q)find $(S)src/etc -name '*.py' \
274-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
275-
$(Q)find $(S)src/doc -name '*.js' \
276-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
277-
$(Q)find $(S)src/etc -name '*.sh' \
278-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
279-
$(Q)find $(S)src/etc -name '*.pl' \
280-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
281-
$(Q)find $(S)src/etc -name '*.c' \
282-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
283-
$(Q)find $(S)src/etc -name '*.h' \
284-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
285-
$(Q)echo $(ALL_CS) \
286-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
287-
$(Q)echo $(ALL_HS) \
288-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
252+
$(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
253+
254+
.PHONY: tidy-binaries
255+
tidy-binaries:
256+
@$(call E, check: binaries)
289257
$(Q)find $(S)src -type f -perm +a+x \
290258
-not -name '*.rs' -and -not -name '*.py' \
291259
-and -not -name '*.sh' \
@@ -300,11 +268,16 @@ tidy:
300268
| grep '^$(S)src/libbacktrace' -v \
301269
| grep '^$(S)src/rust-installer' -v \
302270
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
303-
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
304-
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
305271

272+
.PHONY: tidy-errors
273+
tidy-errors:
274+
@$(call E, check: extended errors)
275+
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
306276

307-
endif
277+
.PHONY: tidy-features
278+
tidy-features:
279+
@$(call E, check: feature sanity)
280+
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
308281

309282

310283
######################################################################
@@ -639,7 +612,6 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
639612

640613
ifdef CFG_VALGRIND_RPASS
641614
ifdef GOOD_VALGRIND_$(2)
642-
$(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS))
643615
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
644616
endif
645617
endif

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

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

Lines changed: 90 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,62 @@ 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. This is an enum
204-
that is provided by the Rust standard library:
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:
205259

206260
```{rust}
207261
enum Ordering {
@@ -211,14 +265,9 @@ enum Ordering {
211265
}
212266
```
213267

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`:
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:
222271

223272
```{rust}
224273
use std::cmp::Ordering;
@@ -245,11 +294,10 @@ fn main() {
245294
}
246295
```
247296

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.
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.
253301

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

261309
The `ordering` variable has the type `Ordering`, and so contains one of the
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.
310+
three values. We then do a bunch of `if`/`else` comparisons to check which
311+
one it is.
267312

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

270316
```{rust}
271-
enum OptionalInt {
272-
Value(i32),
273-
Missing,
274-
}
275-
```
276-
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:
317+
use std::cmp::Ordering::{self, Equal, Less, Greater};
283318
284-
```{rust}
285-
enum OptionalColor {
286-
Color(i32, i32, i32),
287-
Missing,
288-
}
289-
```
290-
291-
And you can also have something like this:
292-
293-
```{rust}
294-
enum StringResult {
295-
StringOK(String),
296-
ErrorReason(String),
319+
fn cmp(a: i32, b: i32) -> Ordering {
320+
if a < b { Less }
321+
else if a > b { Greater }
322+
else { Equal }
297323
}
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.
303324
304-
Here is an example of using our `StringResult`:
325+
fn main() {
326+
let x = 5;
327+
let y = 10;
305328
306-
```rust
307-
enum StringResult {
308-
StringOK(String),
309-
ErrorReason(String),
310-
}
329+
let ordering = cmp(x, y); // ordering: Ordering
311330
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-
}
331+
if ordering == Less { println!("less"); }
332+
else if ordering == Greater { println!("greater"); }
333+
else if ordering == Equal { println!("equal"); }
318334
}
319335
```
320336

321-
That's a lot of typing! We can use the `use` keyword to make it shorter:
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.
322340

323-
```rust
324-
use StringResult::StringOK;
325-
use StringResult::ErrorReason;
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.
326346

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-
```
342347

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.
348+
[match]: ./match.html
349+
[game]: ./guessing-game.html#comparing-guesses
350+
[generics]: ./generics.html

branches/try/src/doc/trpl/crates-and-modules.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ module, we now have a `phrases::japanese::hello()` function and a
551551
`phrases::japanese::farewells::goodbye()`. Our internal organization doesn't
552552
define our external interface.
553553
554+
Here we have a `pub use` for each function we want to bring into the
555+
`japanese` scope. We could alternatively use the wildcard syntax to include
556+
everything from `greetings` into the current scope: `pub use self::greetings::*`.
557+
554558
Also, note that we `pub use`d before we declared our `mod`s. Rust requires that
555559
`use` declarations go first.
556560

0 commit comments

Comments
 (0)