Skip to content

Commit d3294b9

Browse files
committed
---
yaml --- r: 186351 b: refs/heads/try c: 576ba8f h: refs/heads/master i: 186349: c036c14 186347: 28af67e 186343: f870e93 186335: 4c1cb5d v: v3
1 parent f72bbaf commit d3294b9

File tree

251 files changed

+2982
-3294
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

+2982
-3294
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: 8661b3dc0fbb9e21b94266ba62e23cebb8f0603f
5+
refs/heads/try: 576ba8fe57fff2808b58e5fbd36b246c746e4df6
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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@
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
6562
#
6663
# Then mix in some of these environment variables to harness the
6764
# ultimate power of The Rust Build System.

branches/try/mk/main.mk

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

75-
CFG_INFO := $(info cfg: version $(CFG_VERSION))
7675

7776
######################################################################
7877
# More configuration
@@ -180,7 +179,6 @@ endif
180179

181180
ifndef CFG_DISABLE_VALGRIND_RPASS
182181
$(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
183-
$(info cfg: valgrind-rpass command set to $(CFG_VALGRIND))
184182
CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
185183
else
186184
CFG_VALGRIND_RPASS :=

branches/try/mk/tests.mk

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

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

168167
# As above but don't bother running tidy.
169168
check-notidy: cleantmptestlogs cleantestlibs all check-stage2
@@ -236,24 +235,57 @@ cleantestlibs:
236235
######################################################################
237236

238237
ifdef CFG_NOTIDY
239-
.PHONY: tidy
240238
tidy:
241239
else
242240

243-
# Run the tidy script in multiple parts to avoid huge 'echo' commands
244-
.PHONY: tidy
245-
tidy: tidy-basic tidy-binaries tidy-errors tidy-features
246-
247-
endif
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))
248261

249-
.PHONY: tidy-basic
250-
tidy-basic:
262+
# Run the tidy script in multiple parts to avoid huge 'echo' commands
263+
tidy:
251264
@$(call E, check: formatting)
252-
$(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
253-
254-
.PHONY: tidy-binaries
255-
tidy-binaries:
256-
@$(call E, check: binaries)
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
257289
$(Q)find $(S)src -type f -perm +a+x \
258290
-not -name '*.rs' -and -not -name '*.py' \
259291
-and -not -name '*.sh' \
@@ -268,18 +300,13 @@ tidy-binaries:
268300
| grep '^$(S)src/libbacktrace' -v \
269301
| grep '^$(S)src/rust-installer' -v \
270302
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
271-
272-
.PHONY: tidy-errors
273-
tidy-errors:
274-
@$(call E, check: extended errors)
275303
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
276-
277-
.PHONY: tidy-features
278-
tidy-features:
279-
@$(call E, check: feature sanity)
280304
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
281305

282306

307+
endif
308+
309+
283310
######################################################################
284311
# Sets of tests
285312
######################################################################
@@ -612,6 +639,7 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
612639

613640
ifdef CFG_VALGRIND_RPASS
614641
ifdef GOOD_VALGRIND_$(2)
642+
$(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS))
615643
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
616644
endif
617645
endif

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/crates-and-modules.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,10 +551,6 @@ 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-
558554
Also, note that we `pub use`d before we declared our `mod`s. Rust requires that
559555
`use` declarations go first.
560556

0 commit comments

Comments
 (0)