Skip to content

Commit cf325c6

Browse files
committed
---
yaml --- r: 271789 b: refs/heads/auto c: 5695aea h: refs/heads/master i: 271787: 8d29d59
1 parent 982988f commit cf325c6

File tree

294 files changed

+2210
-1941
lines changed

Some content is hidden

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

294 files changed

+2210
-1941
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 2eb84299ca0a23d48ab5f7e489d72708d99b1a1e
11+
refs/heads/auto: 5695aea473477919916116a678da93217b76496a
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ Some common make targets are:
132132
- `make check-stage1-std NO_REBUILD=1` - test the standard library without
133133
rebuilding the entire compiler
134134
- `make check TESTNAME=<substring-of-test-name>` - Run a matching set of tests.
135-
- `TESTNAME` should be a substring of the tests to match against e.g. it could
136-
be the fully qualified test name, or just a part of it.
135+
- `TESTNAME` should be a substring of the tests to match against e.g. it could
136+
be the fully qualified test name, or just a part of it.
137137
`TESTNAME=collections::hash::map::test_map::test_capacity_not_less_than_len`
138138
or `TESTNAME=test_capacity_not_less_than_len`.
139139
- `make check-stage1-rpass TESTNAME=<substring-of-test-name>` - Run a single

branches/auto/mk/crates.mk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TARGET_CRATES := libc std term \
5757
RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \
5858
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
5959
rustc_data_structures rustc_front rustc_platform_intrinsics \
60-
rustc_plugin rustc_metadata rustc_passes
60+
rustc_plugin rustc_metadata rustc_passes rustc_save_analysis
6161
HOST_CRATES := syntax syntax_ext $(RUSTC_CRATES) rustdoc fmt_macros \
6262
flate arena graphviz rbml log serialize
6363
TOOLS := compiletest rustdoc rustc rustbook error_index_generator
@@ -102,7 +102,7 @@ DEPS_rustc_data_structures := std log serialize
102102
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
103103
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
104104
rustc_trans rustc_privacy rustc_lint rustc_front rustc_plugin \
105-
rustc_metadata syntax_ext rustc_passes
105+
rustc_metadata syntax_ext rustc_passes rustc_save_analysis
106106
DEPS_rustc_front := std syntax log serialize
107107
DEPS_rustc_lint := rustc log syntax
108108
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
@@ -116,13 +116,14 @@ DEPS_rustc_privacy := rustc rustc_front log syntax
116116
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back rustc_mir \
117117
log syntax serialize rustc_llvm rustc_front rustc_platform_intrinsics \
118118
rustc_const_eval
119+
DEPS_rustc_save_analysis := rustc log syntax rustc_front
119120
DEPS_rustc_typeck := rustc syntax rustc_front rustc_platform_intrinsics rustc_const_eval
120121

121122
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
122123
test rustc_lint rustc_front
123124

124125

125-
TOOL_DEPS_compiletest := test getopts
126+
TOOL_DEPS_compiletest := test getopts log
126127
TOOL_DEPS_rustdoc := rustdoc
127128
TOOL_DEPS_rustc := rustc_driver
128129
TOOL_DEPS_rustbook := std rustdoc

branches/auto/mk/main.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ endif
493493
LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3) := \
494494
$$(CURDIR)/$$(HLIB$(1)_H_$(3)):$$(CFG_LLVM_INST_DIR_$(3))/lib
495495
LD_LIBRARY_PATH_ENV_TARGETDIR$(1)_T_$(2)_H_$(3) := \
496-
$$(CURDIR)/$$(TLIB1_T_$(2)_H_$(CFG_BUILD))
496+
$$(CURDIR)/$$(TLIB$(1)_T_$(2)_H_$(CFG_BUILD))
497497

498498
HOST_RPATH_VAR$(1)_T_$(2)_H_$(3) := \
499499
$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))=$$(LD_LIBRARY_PATH_ENV_HOSTDIR$(1)_T_$(2)_H_$(3)):$$$$$$(LD_LIBRARY_PATH_ENV_NAME$(1)_T_$(2)_H_$(3))

branches/auto/src/bootstrap/build/native.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ pub fn llvm(build: &Build, target: &str) {
3939

4040
let _ = fs::remove_dir_all(&dst.join("build"));
4141
t!(fs::create_dir_all(&dst.join("build")));
42-
let mut assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};
43-
44-
// Disable LLVM assertions on ARM compilers until #32360 is fixed
45-
if target.contains("arm") && target.contains("gnu") {
46-
assertions = "OFF";
47-
}
42+
let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};
4843

4944
// http://llvm.org/docs/CMake.html
5045
let mut cfg = cmake::Config::new(build.src.join("src/llvm"));

branches/auto/src/bootstrap/mk/Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ standalone-docs:
3838
$(Q)$(BOOTSTRAP) --step doc-standalone
3939
check:
4040
$(Q)$(BOOTSTRAP) --step check
41-
cargotest:
42-
$(Q)$(BOOTSTRAP) --step cargotest
41+
check-cargotest:
42+
$(Q)$(BOOTSTRAP) --step check-cargotest
4343
dist:
4444
$(Q)$(BOOTSTRAP) --step dist
4545

branches/auto/src/compiletest/runtest.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,11 @@ fn run_debuginfo_lldb_test(config: &Config, props: &TestProps, testpaths: &TestP
727727
script_str.push_str("type category enable Rust\n");
728728

729729
// Set breakpoints on every line that contains the string "#break"
730+
let source_file_name = testpaths.file.file_name().unwrap().to_string_lossy();
730731
for line in &breakpoint_lines {
731-
script_str.push_str(&format!("breakpoint set --line {}\n", line));
732+
script_str.push_str(&format!("breakpoint set --file '{}' --line {}\n",
733+
source_file_name,
734+
line));
732735
}
733736

734737
// Append the other commands

branches/auto/src/doc/book/casting-between-types.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ function result.
1717
The most common case of coercion is removing mutability from a reference:
1818

1919
* `&mut T` to `&T`
20-
20+
2121
An analogous conversion is to remove mutability from a
2222
[raw pointer](raw-pointers.md):
2323

2424
* `*mut T` to `*const T`
25-
25+
2626
References can also be coerced to raw pointers:
2727

2828
* `&T` to `*const T`
@@ -32,7 +32,7 @@ References can also be coerced to raw pointers:
3232
Custom coercions may be defined using [`Deref`](deref-coercions.md).
3333

3434
Coercion is transitive.
35-
35+
3636
# `as`
3737

3838
The `as` keyword does safe casting:
@@ -64,7 +64,7 @@ A cast `e as U` is also valid in any of the following cases:
6464
and `U` is an integer type; *enum-cast*
6565
* `e` has type `bool` or `char` and `U` is an integer type; *prim-int-cast*
6666
* `e` has type `u8` and `U` is `char`; *u8-char-cast*
67-
67+
6868
For example
6969

7070
```rust
@@ -98,9 +98,9 @@ The semantics of numeric casts are:
9898

9999
[float-int]: https://github.com/rust-lang/rust/issues/10184
100100
[float-float]: https://github.com/rust-lang/rust/issues/15536
101-
101+
102102
## Pointer casts
103-
103+
104104
Perhaps surprisingly, it is safe to cast [raw pointers](raw-pointers.md) to and
105105
from integers, and to cast between pointers to different types subject to
106106
some constraints. It is only unsafe to dereference the pointer:
@@ -114,7 +114,7 @@ let b = a as u32;
114114

115115
* `e` has type `*T`, `U` has type `*U_0`, and either `U_0: Sized` or
116116
`unsize_kind(T) == unsize_kind(U_0)`; a *ptr-ptr-cast*
117-
117+
118118
* `e` has type `*T` and `U` is a numeric type, while `T: Sized`; *ptr-addr-cast*
119119

120120
* `e` is an integer and `U` is `*U_0`, while `U_0: Sized`; *addr-ptr-cast*

branches/auto/src/doc/book/closures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,5 +502,5 @@ assert_eq!(6, answer);
502502
```
503503

504504
By making the inner closure a `move Fn`, we create a new stack frame for our
505-
closure. By `Box`ing it up, we’ve given it a known size, and allowing it to
505+
closure. By `Box`ing it up, we’ve given it a known size, allowing it to
506506
escape our stack frame.

branches/auto/src/doc/book/concurrency.md

Lines changed: 124 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,54 @@ fn main() {
9494
}
9595
```
9696

97+
As closures can capture variables from their environment, we can also try to
98+
bring some data into the other thread:
99+
100+
```rust,ignore
101+
use std::thread;
102+
103+
fn main() {
104+
let x = 1;
105+
thread::spawn(|| {
106+
println!("x is {}", x);
107+
});
108+
}
109+
```
110+
111+
However, this gives us an error:
112+
113+
```text
114+
5:19: 7:6 error: closure may outlive the current function, but it
115+
borrows `x`, which is owned by the current function
116+
...
117+
5:19: 7:6 help: to force the closure to take ownership of `x` (and any other referenced variables),
118+
use the `move` keyword, as shown:
119+
thread::spawn(move || {
120+
println!("x is {}", x);
121+
});
122+
```
123+
124+
This is because by default closures capture variables by reference, and thus the
125+
closure only captures a _reference to `x`_. This is a problem, because the
126+
thread may outlive the scope of `x`, leading to a dangling pointer.
127+
128+
To fix this, we use a `move` closure as mentioned in the error message. `move`
129+
closures are explained in depth [here](closures.html#move-closures); basically
130+
they move variables from their environment into themselves. This means that `x`
131+
is now owned by the closure, and cannot be used in `main()` after the call to
132+
`spawn()`.
133+
134+
```rust
135+
use std::thread;
136+
137+
fn main() {
138+
let x = 1;
139+
thread::spawn(move || {
140+
println!("x is {}", x);
141+
});
142+
}
143+
```
144+
97145
Many languages have the ability to execute threads, but it's wildly unsafe.
98146
There are entire books about how to prevent errors that occur from shared
99147
mutable state. Rust helps out with its type system here as well, by preventing
@@ -145,23 +193,64 @@ This gives us an error:
145193
```
146194

147195
Rust knows this wouldn't be safe! If we had a reference to `data` in each
148-
thread, and the thread takes ownership of the reference, we'd have three
149-
owners!
196+
thread, and the thread takes ownership of the reference, we'd have three owners!
197+
`data` gets moved out of `main` in the first call to `spawn()`, so subsequent
198+
calls in the loop cannot use this variable.
199+
200+
So, we need some type that lets us have more than one owning reference to a
201+
value. Usually, we'd use `Rc<T>` for this, which is a reference counted type
202+
that provides shared ownership. It has some runtime bookkeeping that keeps track
203+
of the number of references to it, hence the "reference count" part of its name.
204+
205+
Calling `clone()` on an `Rc<T>` will return a new owned reference and bump the
206+
internal reference count. We create one of these for each thread:
150207

151-
So, we need some type that lets us have more than one reference to a value and
152-
that we can share between threads, that is it must implement `Sync`.
153208

154-
We'll use `Arc<T>`, Rust's standard atomic reference count type, which
155-
wraps a value up with some extra runtime bookkeeping which allows us to
156-
share the ownership of the value between multiple references at the same time.
209+
```ignore
210+
use std::thread;
211+
use std::time::Duration;
212+
use std::rc::Rc;
157213
158-
The bookkeeping consists of a count of how many of these references exist to
159-
the value, hence the reference count part of the name.
214+
fn main() {
215+
let mut data = Rc::new(vec![1, 2, 3]);
216+
217+
for i in 0..3 {
218+
// create a new owned reference
219+
let data_ref = data.clone();
220+
221+
// use it in a thread
222+
thread::spawn(move || {
223+
data_ref[i] += 1;
224+
});
225+
}
226+
227+
thread::sleep(Duration::from_millis(50));
228+
}
229+
```
230+
231+
This won't work, however, and will give us the error:
232+
233+
```text
234+
13:9: 13:22 error: the trait `core::marker::Send` is not
235+
implemented for the type `alloc::rc::Rc<collections::vec::Vec<i32>>`
236+
...
237+
13:9: 13:22 note: `alloc::rc::Rc<collections::vec::Vec<i32>>`
238+
cannot be sent between threads safely
239+
```
240+
241+
As the error message mentions, `Rc` cannot be sent between threads safely. This
242+
is because the internal reference count is not maintained in a thread safe
243+
matter and can have a data race.
244+
245+
To solve this, we'll use `Arc<T>`, Rust's standard atomic reference count type.
160246

161247
The Atomic part means `Arc<T>` can safely be accessed from multiple threads.
162248
To do this the compiler guarantees that mutations of the internal count use
163249
indivisible operations which can't have data races.
164250

251+
In essence, `Arc<T>` is a type that lets us share ownership of data _across
252+
threads_.
253+
165254

166255
```ignore
167256
use std::thread;
@@ -182,7 +271,7 @@ fn main() {
182271
}
183272
```
184273

185-
We now call `clone()` on our `Arc<T>`, which increases the internal count.
274+
Similarly to last time, we use `clone()` to create a new owned handle.
186275
This handle is then moved into the new thread.
187276

188277
And... still gives us an error.
@@ -193,14 +282,21 @@ And... still gives us an error.
193282
^~~~
194283
```
195284

196-
`Arc<T>` assumes one more property about its contents to ensure that it is safe
197-
to share across threads: it assumes its contents are `Sync`. This is true for
198-
our value if it's immutable, but we want to be able to mutate it, so we need
199-
something else to persuade the borrow checker we know what we're doing.
285+
`Arc<T>` by default has immutable contents. It allows the _sharing_ of data
286+
between threads, but shared mutable data is unsafe and when threads are
287+
involved can cause data races!
288+
200289

201-
It looks like we need some type that allows us to safely mutate a shared value,
202-
for example a type that can ensure only one thread at a time is able to
203-
mutate the value inside it at any one time.
290+
Usually when we wish to make something in an immutable position mutable, we use
291+
`Cell<T>` or `RefCell<T>` which allow safe mutation via runtime checks or
292+
otherwise (see also: [Choosing Your Guarantees](choosing-your-guarantees.html)).
293+
However, similar to `Rc`, these are not thread safe. If we try using these, we
294+
will get an error about these types not being `Sync`, and the code will fail to
295+
compile.
296+
297+
It looks like we need some type that allows us to safely mutate a shared value
298+
across threads, for example a type that can ensure only one thread at a time is
299+
able to mutate the value inside it at any one time.
204300

205301
For that, we can use the `Mutex<T>` type!
206302

@@ -229,7 +325,17 @@ fn main() {
229325
Note that the value of `i` is bound (copied) to the closure and not shared
230326
among the threads.
231327

232-
Also note that [`lock`](../std/sync/struct.Mutex.html#method.lock) method of
328+
We're "locking" the mutex here. A mutex (short for "mutual exclusion"), as
329+
mentioned, only allows one thread at a time to access a value. When we wish to
330+
access the value, we use `lock()` on it. This will "lock" the mutex, and no
331+
other thread will be able to lock it (and hence, do anything with the value)
332+
until we're done with it. If a thread attempts to lock a mutex which is already
333+
locked, it will wait until the other thread releases the lock.
334+
335+
The lock "release" here is implicit; when the result of the lock (in this case,
336+
`data`) goes out of scope, the lock is automatically released.
337+
338+
Note that [`lock`](../std/sync/struct.Mutex.html#method.lock) method of
233339
[`Mutex`](../std/sync/struct.Mutex.html) has this signature:
234340

235341
```ignore

branches/auto/src/doc/book/const-and-static.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ a [`Drop`][drop] implementation.
7272
# Initializing
7373

7474
Both `const` and `static` have requirements for giving them a value. They must
75-
be given a value that’s a constant expression. In other words, you cannot use
75+
be given a value that’s a constant expression. In other words, you cannot use
7676
the result of a function call or anything similarly complex or at runtime.
7777

7878
# Which construct should I use?

branches/auto/src/doc/book/match.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ patterns][patterns] that covers all the patterns that are possible here.
2828

2929
[patterns]: patterns.html
3030

31-
One of the many advantages of `match` is it enforces ‘exhaustiveness checking’.
32-
For example if we remove the last arm with the underscore `_`, the compiler will
31+
One of the many advantages of `match` is it enforces ‘exhaustiveness checking’.
32+
For example if we remove the last arm with the underscore `_`, the compiler will
3333
give us an error:
3434

3535
```text
@@ -58,7 +58,7 @@ let number = match x {
5858
};
5959
```
6060

61-
Sometimes it’s a nice way of converting something from one type to another; in
61+
Sometimes it’s a nice way of converting something from one type to another; in
6262
this example the integers are converted to `String`.
6363

6464
# Matching on enums
@@ -90,7 +90,7 @@ fn process_message(msg: Message) {
9090

9191
Again, the Rust compiler checks exhaustiveness, so it demands that you
9292
have a match arm for every variant of the enum. If you leave one off, it
93-
will give you a compile-time error unless you use `_` or provide all possible
93+
will give you a compile-time error unless you use `_` or provide all possible
9494
arms.
9595

9696
Unlike the previous uses of `match`, you can’t use the normal `if`

0 commit comments

Comments
 (0)