Skip to content

Commit ed81038

Browse files
committed
Auto merge of #23654 - alexcrichton:rollup, r=alexcrichton
2 parents 28a0b25 + d252d0a commit ed81038

File tree

1,977 files changed

+7606
-1894
lines changed

Some content is hidden

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

1,977 files changed

+7606
-1894
lines changed

configure

+12-3
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,19 @@ esac
479479
# Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
480480
if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
481481
then
482-
file -L "$SHELL" | grep -q "x86[_-]64"
483-
if [ $? != 0 ]; then
484-
CFG_CPUTYPE=i686
482+
# $SHELL does not exist in standard 'sh', so probably only exists
483+
# if configure is running in an interactive bash shell. /usr/bin/env
484+
# exists *everywhere*.
485+
BIN_TO_PROBE="$SHELL"
486+
if [ -z "$BIN_TO_PROBE" -a -e "/usr/bin/env" ]; then
487+
BIN_TO_PROBE="/usr/bin/env"
485488
fi
489+
if [ -n "$BIN_TO_PROBE" ]; then
490+
file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64"
491+
if [ $? != 0 ]; then
492+
CFG_CPUTYPE=i686
493+
fi
494+
fi
486495
fi
487496

488497

src/compiletest/compiletest.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#![feature(std_misc)]
2121
#![feature(test)]
2222
#![feature(path_ext)]
23+
#![feature(convert)]
24+
#![feature(str_char)]
2325

2426
#![deny(warnings)]
2527

@@ -115,7 +117,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
115117

116118
fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf {
117119
match m.opt_str(nm) {
118-
Some(s) => PathBuf::new(&s),
120+
Some(s) => PathBuf::from(&s),
119121
None => panic!("no option (=path) found for {}", nm),
120122
}
121123
}
@@ -130,18 +132,18 @@ pub fn parse_config(args: Vec<String> ) -> Config {
130132
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
131133
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
132134
rustc_path: opt_path(matches, "rustc-path"),
133-
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::new(&s)),
135+
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::from(&s)),
134136
valgrind_path: matches.opt_str("valgrind-path"),
135137
force_valgrind: matches.opt_present("force-valgrind"),
136-
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::new(&s)),
138+
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::from(&s)),
137139
src_base: opt_path(matches, "src-base"),
138140
build_base: opt_path(matches, "build-base"),
139141
aux_base: opt_path(matches, "aux-base"),
140142
stage_id: matches.opt_str("stage-id").unwrap(),
141143
mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"),
142144
run_ignored: matches.opt_present("ignored"),
143145
filter: filter,
144-
logfile: matches.opt_str("logfile").map(|s| PathBuf::new(&s)),
146+
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
145147
runtool: matches.opt_str("runtool"),
146148
host_rustcflags: matches.opt_str("host-rustcflags"),
147149
target_rustcflags: matches.opt_str("target-rustcflags"),

src/compiletest/header.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub struct TestProps {
4040
pub check_stdout: bool,
4141
// Don't force a --crate-type=dylib flag on the command line
4242
pub no_prefer_dynamic: bool,
43-
// Don't run --pretty expanded when running pretty printing tests
44-
pub no_pretty_expanded: bool,
43+
// Run --pretty expanded when running pretty printing tests
44+
pub pretty_expanded: bool,
4545
// Which pretty mode are we testing with, default to 'normal'
4646
pub pretty_mode: String,
4747
// Only compare pretty output and don't try compiling
@@ -62,7 +62,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
6262
let mut force_host = false;
6363
let mut check_stdout = false;
6464
let mut no_prefer_dynamic = false;
65-
let mut no_pretty_expanded = false;
65+
let mut pretty_expanded = false;
6666
let mut pretty_mode = None;
6767
let mut pretty_compare_only = false;
6868
let mut forbid_output = Vec::new();
@@ -96,8 +96,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
9696
no_prefer_dynamic = parse_no_prefer_dynamic(ln);
9797
}
9898

99-
if !no_pretty_expanded {
100-
no_pretty_expanded = parse_no_pretty_expanded(ln);
99+
if !pretty_expanded {
100+
pretty_expanded = parse_pretty_expanded(ln);
101101
}
102102

103103
if pretty_mode.is_none() {
@@ -152,7 +152,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
152152
force_host: force_host,
153153
check_stdout: check_stdout,
154154
no_prefer_dynamic: no_prefer_dynamic,
155-
no_pretty_expanded: no_pretty_expanded,
155+
pretty_expanded: pretty_expanded,
156156
pretty_mode: pretty_mode.unwrap_or("normal".to_string()),
157157
pretty_compare_only: pretty_compare_only,
158158
forbid_output: forbid_output,
@@ -295,8 +295,8 @@ fn parse_no_prefer_dynamic(line: &str) -> bool {
295295
parse_name_directive(line, "no-prefer-dynamic")
296296
}
297297

298-
fn parse_no_pretty_expanded(line: &str) -> bool {
299-
parse_name_directive(line, "no-pretty-expanded")
298+
fn parse_pretty_expanded(line: &str) -> bool {
299+
parse_name_directive(line, "pretty-expanded")
300300
}
301301

302302
fn parse_pretty_mode(line: &str) -> Option<String> {
@@ -328,10 +328,10 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
328328

329329
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
330330
match parse_name_value_directive(line, "pp-exact") {
331-
Some(s) => Some(PathBuf::new(&s)),
331+
Some(s) => Some(PathBuf::from(&s)),
332332
None => {
333333
if parse_name_directive(line, "pp-exact") {
334-
testfile.file_name().map(|s| PathBuf::new(s))
334+
testfile.file_name().map(|s| PathBuf::from(s))
335335
} else {
336336
None
337337
}
@@ -340,7 +340,8 @@ fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
340340
}
341341

342342
fn parse_name_directive(line: &str, directive: &str) -> bool {
343-
line.contains(directive)
343+
// This 'no-' rule is a quick hack to allow pretty-expanded and no-pretty-expanded to coexist
344+
line.contains(directive) && !line.contains(&("no-".to_string() + directive))
344345
}
345346

346347
pub fn parse_name_value_directive(line: &str, directive: &str)

src/compiletest/runtest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
245245
if !proc_res.status.success() {
246246
fatal_proc_rec("pretty-printed source does not typecheck", &proc_res);
247247
}
248-
if props.no_pretty_expanded { return }
248+
if !props.pretty_expanded { return }
249249

250250
// additionally, run `--pretty expanded` and try to build it.
251251
let proc_res = print_source(config, props, testfile, srcs[round].clone(), "expanded");
@@ -1440,7 +1440,7 @@ fn aux_output_dir_name(config: &Config, testfile: &Path) -> PathBuf {
14401440
}
14411441

14421442
fn output_testname(testfile: &Path) -> PathBuf {
1443-
PathBuf::new(testfile.file_stem().unwrap())
1443+
PathBuf::from(testfile.file_stem().unwrap())
14441444
}
14451445

14461446
fn output_base_name(config: &Config, testfile: &Path) -> PathBuf {

src/doc/intro.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,16 @@ It gives us this error:
446446
error: aborting due to previous error
447447
```
448448
449-
It mentions that "captured outer variable in an `FnMut` closure".
450-
Because we declared the closure as a moving closure, and it referred
451-
to `numbers`, the closure will try to take ownership of the
452-
vector. But the closure itself is created in a loop, and hence we will
453-
actually create three closures, one for every iteration of the
454-
loop. This means that all three of those closures would try to own
455-
`numbers`, which is impossible -- `numbers` must have just one
456-
owner. Rust detects this and gives us the error: we claim that
457-
`numbers` has ownership, but our code tries to make three owners. This
458-
may cause a safety problem, so Rust disallows it.
449+
This is a little confusing because there are two closures here: the one passed
450+
to `map`, and the one passed to `thread::scoped`. In this case, the closure for
451+
`thread::scoped` is attempting to reference `numbers`, a `Vec<i32>`. This
452+
closure is a `FnOnce` closure, as that’s what `thread::scoped` takes as an
453+
argument. `FnOnce` closures take ownership of their environment. That’s fine,
454+
but there’s one detail: because of `map`, we’re going to make three of these
455+
closures. And since all three try to take ownership of `numbers`, that would be
456+
a problem. That’s what it means by ‘cannot move out of captured outer
457+
variable’: our `thread::scoped` closure wants to take ownership, and it can’t,
458+
because the closure for `map` won’t let it.
459459
460460
What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
461461
*Arc* stands for "atomically reference counted". In other words, an Arc will

src/doc/reference.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ may optionally begin with any number of `attributes` that apply to the
816816
containing module. Attributes on the anonymous crate module define important
817817
metadata that influences the behavior of the compiler.
818818

819-
```{.rust}
820-
# #![allow(unused_attribute)]
819+
```no_run
821820
// Crate name
822821
#![crate_name = "projx"]
823822
@@ -1020,6 +1019,7 @@ Use declarations support a number of convenient shortcuts:
10201019
An example of `use` declarations:
10211020

10221021
```
1022+
# #![feature(core)]
10231023
use std::iter::range_step;
10241024
use std::option::Option::{Some, None};
10251025
use std::collections::hash_map::{self, HashMap};
@@ -1080,6 +1080,7 @@ declarations.
10801080
An example of what will and will not work for `use` items:
10811081

10821082
```
1083+
# #![feature(core)]
10831084
# #![allow(unused_imports)]
10841085
use foo::core::iter; // good: foo is at the root of the crate
10851086
use foo::baz::foobaz; // good: foo is at the root of the crate
@@ -1781,6 +1782,7 @@ functions, with the exception that they may not have a body and are instead
17811782
terminated by a semicolon.
17821783

17831784
```
1785+
# #![feature(libc)]
17841786
extern crate libc;
17851787
use libc::{c_char, FILE};
17861788

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

+36-33
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ This pattern is very powerful, and we'll see it repeated more later.
4747

4848
There are also a few things you can do with a tuple as a whole, without
4949
destructuring. You can assign one tuple into another, if they have the same
50-
contained types and arity. Tuples have the same arity when they have the same
50+
contained types and [arity]. Tuples have the same arity when they have the same
5151
length.
5252

5353
```rust
@@ -196,8 +196,9 @@ Now, we have actual names, rather than positions. Good names are important,
196196
and with a struct, we have actual names.
197197

198198
There _is_ one case when a tuple struct is very useful, though, and that's a
199-
tuple struct with only one element. We call this a *newtype*, because it lets
200-
you create a new type that's similar to another one:
199+
tuple struct with only one element. We call this the *newtype* pattern, because
200+
it allows you to create a new type, distinct from that of its contained value
201+
and expressing its own semantic meaning:
201202

202203
```{rust}
203204
struct Inches(i32);
@@ -216,7 +217,7 @@ destructuring `let`, as we discussed previously in 'tuples.' In this case, the
216217

217218
Finally, Rust has a "sum type", an *enum*. Enums are an incredibly useful
218219
feature of Rust, and are used throughout the standard library. An `enum` is
219-
a type which ties a set of alternates to a specific name. For example, below
220+
a type which relates a set of alternates to a specific name. For example, below
220221
we define `Character` to be either a `Digit` or something else. These
221222
can be used via their fully scoped names: `Character::Other` (more about `::`
222223
below).
@@ -228,8 +229,8 @@ enum Character {
228229
}
229230
```
230231

231-
An `enum` variant can be defined as most normal types. Below are some example
232-
types which also would be allowed in an `enum`.
232+
Most normal types are allowed as the variant components of an `enum`. Here are
233+
some examples:
233234

234235
```rust
235236
struct Empty;
@@ -239,15 +240,15 @@ struct Status { Health: i32, Mana: i32, Attack: i32, Defense: i32 }
239240
struct HeightDatabase(Vec<i32>);
240241
```
241242

242-
So you see that depending on the sub-datastructure, the `enum` variant, same as
243-
a struct, may or may not hold data. That is, in `Character`, `Digit` is a name
244-
tied to an `i32` where `Other` is just a name. However, the fact that they are
245-
distinct makes this very useful.
243+
You see that, depending on its type, an `enum` variant may or may not hold data.
244+
In `Character`, for instance, `Digit` gives a meaningful name for an `i32`
245+
value, where `Other` is only a name. However, the fact that they represent
246+
distinct categories of `Character` is a very useful property.
246247

247-
As with structures, enums don't by default have access to operators such as
248-
compare ( `==` and `!=`), binary operations (`*` and `+`), and order
249-
(`<` and `>=`). As such, using the previous `Character` type, the
250-
following code is invalid:
248+
As with structures, the variants of an enum by default are not comparable with
249+
equality operators (`==`, `!=`), have no ordering (`<`, `>=`, etc.), and do not
250+
support other binary operations such as `*` and `+`. As such, the following code
251+
is invalid for the example `Character` type:
251252

252253
```{rust,ignore}
253254
// These assignments both succeed
@@ -265,9 +266,10 @@ let four_equals_ten = four == ten;
265266
```
266267

267268
This may seem rather limiting, but it's a limitation which we can overcome.
268-
There are two ways: by implementing equality ourselves, or by using the
269-
[`match`][match] keyword. We don't know enough about Rust to implement equality
270-
yet, but we can use the `Ordering` enum from the standard library, which does:
269+
There are two ways: by implementing equality ourselves, or by pattern matching
270+
variants with [`match`][match] expressions, which you'll learn in the next
271+
chapter. We don't know enough about Rust to implement equality yet, but we can
272+
use the `Ordering` enum from the standard library, which does:
271273

272274
```
273275
enum Ordering {
@@ -277,9 +279,8 @@ enum Ordering {
277279
}
278280
```
279281

280-
Because we did not define `Ordering`, we must import it (from the std
281-
library) with the `use` keyword. Here's an example of how `Ordering` is
282-
used:
282+
Because `Ordering` has already been defined for us, we will import it with the
283+
`use` keyword. Here's an example of how it is used:
283284

284285
```{rust}
285286
use std::cmp::Ordering;
@@ -313,17 +314,17 @@ the standard library if you need them.
313314

314315
Okay, let's talk about the actual code in the example. `cmp` is a function that
315316
compares two things, and returns an `Ordering`. We return either
316-
`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on if
317-
the two values are less, greater, or equal. Note that each variant of the
318-
`enum` is namespaced under the `enum` itself: it's `Ordering::Greater` not
319-
`Greater`.
317+
`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on
318+
whether the first value is less than, greater than, or equal to the second. Note
319+
that each variant of the `enum` is namespaced under the `enum` itself: it's
320+
`Ordering::Greater`, not `Greater`.
320321

321322
The `ordering` variable has the type `Ordering`, and so contains one of the
322323
three values. We then do a bunch of `if`/`else` comparisons to check which
323324
one it is.
324325

325-
This `Ordering::Greater` notation is too long. Let's use `use` to import the
326-
`enum` variants instead. This will avoid full scoping:
326+
This `Ordering::Greater` notation is too long. Let's use another form of `use`
327+
to import the `enum` variants instead. This will avoid full scoping:
327328

328329
```{rust}
329330
use std::cmp::Ordering::{self, Equal, Less, Greater};
@@ -347,16 +348,18 @@ fn main() {
347348
```
348349

349350
Importing variants is convenient and compact, but can also cause name conflicts,
350-
so do this with caution. It's considered good style to rarely import variants
351-
for this reason.
351+
so do this with caution. For this reason, it's normally considered better style
352+
to `use` an enum rather than its variants directly.
352353

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

359361

362+
[arity]: ./glossary.html#arity
360363
[match]: ./match.html
361364
[game]: ./guessing-game.html#comparing-guesses
362365
[generics]: ./generics.html

0 commit comments

Comments
 (0)