Skip to content

Commit 5c4d621

Browse files
committed
Merge branch 'master' into issue-30961
2 parents e1efa32 + 4db1874 commit 5c4d621

File tree

185 files changed

+4610
-4904
lines changed

Some content is hidden

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

185 files changed

+4610
-4904
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ build.
105105
106106
MSVC builds of Rust additionally require an installation of Visual Studio 2013
107107
(or later) so `rustc` can use its linker. Make sure to check the “C++ tools”
108-
option. In addition, `cmake` needs to be installed to build LLVM.
108+
option.
109109
110110
With these dependencies installed, the build takes two steps:
111111
@@ -116,13 +116,25 @@ $ make && make install
116116
117117
#### MSVC with rustbuild
118118
119-
For those who don't want the hassle of MSYS or MinGW, you can invoke rustbuild
120-
directly. All you need are Python 2, CMake, and Git in your PATH (make sure you
121-
do __not__ use the ones from MSYS!). You'll also need Visual Studio 2013 or
122-
newer with the C++ tools. Then all you need to do is invoke the appropriate
123-
vcvars bat file and kick off rustbuild.
119+
The old build system, based on makefiles, is currently being rewritten into a
120+
Rust-based build system called rustbuild. This can be used to bootstrap the
121+
compiler on MSVC without needing to install MSYS or MinGW. All you need are
122+
[Python 2](https://www.python.org/downloads/),
123+
[CMake](https://cmake.org/download/), and
124+
[Git](https://git-scm.com/downloads) in your PATH (make sure you do not use the
125+
ones from MSYS if you have it installed). You'll also need Visual Studio 2013 or
126+
newer with the C++ tools. Then all you need to do is to kick off rustbuild.
124127
125-
```bat
128+
```
129+
python .\src\bootstrap\bootstrap.py
130+
```
131+
132+
Currently rustbuild only works with some known versions of Visual Studio. If you
133+
have a more recent version installed that a part of rustbuild doesn't understand
134+
then you may need to force rustbuild to use an older version. This can be done
135+
by manually calling the appropriate vcvars file before running the bootstrap.
136+
137+
```
126138
CALL "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
127139
python .\src\bootstrap\bootstrap.py
128140
```

configure

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,20 @@ valopt arm-linux-androideabi-ndk "" "arm-linux-androideabi NDK standalone path"
637637
valopt armv7-linux-androideabi-ndk "" "armv7-linux-androideabi NDK standalone path"
638638
valopt aarch64-linux-android-ndk "" "aarch64-linux-android NDK standalone path"
639639
valopt nacl-cross-path "" "NaCl SDK path (Pepper Canary is recommended). Must be absolute!"
640-
valopt release-channel "dev" "the name of the release channel to build"
641640
valopt musl-root "/usr/local" "MUSL root installation directory"
642641
valopt extra-filename "" "Additional data that is hashed and passed to the -C extra-filename flag"
643642

643+
if [ -e ${CFG_SRC_DIR}.git ]
644+
then
645+
valopt release-channel "dev" "the name of the release channel to build"
646+
else
647+
# If we have no git directory then we are probably a tarball distribution
648+
# and should default to stable channel - Issue 28322
649+
probe CFG_GIT git
650+
msg "git: no git directory. Changing default release channel to stable"
651+
valopt release-channel "stable" "the name of the release channel to build"
652+
fi
653+
644654
# Used on systems where "cc" and "ar" are unavailable
645655
valopt default-linker "cc" "the default linker"
646656
valopt default-ar "ar" "the default ar"

man/rustc.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The optional \fIKIND\fR can be one of \fIstatic\fR, \fIdylib\fR, or
4444
\fIframework\fR.
4545
If omitted, \fIdylib\fR is assumed.
4646
.TP
47-
\fB\-\-crate\-type\fR [bin|lib|rlib|dylib|staticlib]
47+
\fB\-\-crate\-type\fR [bin|lib|rlib|dylib|cdylib|staticlib]
4848
Comma separated list of types of crates for the compiler to emit.
4949
.TP
5050
\fB\-\-crate\-name\fR \fINAME\fR

src/bootstrap/doc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub fn std(build: &Build, stage: u32, target: &str, out: &Path) {
155155
/// is largely just a wrapper around `cargo doc`.
156156
pub fn test(build: &Build, stage: u32, target: &str, out: &Path) {
157157
println!("Documenting stage{} test ({})", stage, target);
158+
t!(fs::create_dir_all(out));
158159
let compiler = Compiler::new(stage, &build.config.build);
159160
let out_dir = build.stage_out(&compiler, Mode::Libtest)
160161
.join(target).join("doc");
@@ -175,11 +176,12 @@ pub fn test(build: &Build, stage: u32, target: &str, out: &Path) {
175176
/// dependencies. This is largely just a wrapper around `cargo doc`.
176177
pub fn rustc(build: &Build, stage: u32, target: &str, out: &Path) {
177178
println!("Documenting stage{} compiler ({})", stage, target);
179+
t!(fs::create_dir_all(out));
178180
let compiler = Compiler::new(stage, &build.config.build);
179181
let out_dir = build.stage_out(&compiler, Mode::Librustc)
180182
.join(target).join("doc");
181183
let rustdoc = build.rustdoc(&compiler);
182-
if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) {
184+
if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) && out_dir.exists() {
183185
t!(fs::remove_dir_all(&out_dir));
184186
}
185187
let mut cargo = build.cargo(&compiler, Mode::Librustc, target, "doc");

src/bootstrap/step.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,18 @@ impl<'a> Step<'a> {
380380
vec![self.doc_test(stage)]
381381
}
382382
Source::Doc { stage } => {
383-
vec![self.doc_book(stage), self.doc_nomicon(stage),
384-
self.doc_style(stage), self.doc_standalone(stage),
385-
self.doc_std(stage),
386-
self.doc_error_index(stage)]
383+
let mut deps = vec![
384+
self.doc_book(stage), self.doc_nomicon(stage),
385+
self.doc_style(stage), self.doc_standalone(stage),
386+
self.doc_std(stage),
387+
self.doc_error_index(stage),
388+
];
389+
390+
if build.config.compiler_docs {
391+
deps.push(self.doc_rustc(stage));
392+
}
393+
394+
deps
387395
}
388396
Source::Check { stage, compiler } => {
389397
// Check is just a pseudo step which means check all targets,

src/doc/book/closures.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ could annotate it on the function declaration:
336336

337337
```rust,ignore
338338
fn call_with_ref<'a, F>(some_closure:F) -> i32
339-
where F: Fn(&'a 32) -> i32 {
339+
where F: Fn(&'a i32) -> i32 {
340340
```
341341

342342
However this presents a problem with in our case. When you specify the explicit
@@ -350,7 +350,7 @@ of the closure we can use Higher-Ranked Trait Bounds with the `for<...>` syntax:
350350

351351
```ignore
352352
fn call_with_ref<F>(some_closure:F) -> i32
353-
where F: for<'a> Fn(&'a 32) -> i32 {
353+
where F: for<'a> Fn(&'a i32) -> i32 {
354354
```
355355

356356
This lets the Rust compiler find the minimum lifetime to invoke our closure and

src/doc/book/ffi.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,62 @@ pub fn uncompress(src: &[u8]) -> Option<Vec<u8>> {
183183
}
184184
```
185185

186-
For reference, the examples used here are also available as a [library on
187-
GitHub](https://github.com/thestinger/rust-snappy).
186+
Then, we can add some tests to show how to use them.
187+
188+
```rust
189+
# #![feature(libc)]
190+
# extern crate libc;
191+
# use libc::{c_int, size_t};
192+
# unsafe fn snappy_compress(input: *const u8,
193+
# input_length: size_t,
194+
# compressed: *mut u8,
195+
# compressed_length: *mut size_t)
196+
# -> c_int { 0 }
197+
# unsafe fn snappy_uncompress(compressed: *const u8,
198+
# compressed_length: size_t,
199+
# uncompressed: *mut u8,
200+
# uncompressed_length: *mut size_t)
201+
# -> c_int { 0 }
202+
# unsafe fn snappy_max_compressed_length(source_length: size_t) -> size_t { 0 }
203+
# unsafe fn snappy_uncompressed_length(compressed: *const u8,
204+
# compressed_length: size_t,
205+
# result: *mut size_t)
206+
# -> c_int { 0 }
207+
# unsafe fn snappy_validate_compressed_buffer(compressed: *const u8,
208+
# compressed_length: size_t)
209+
# -> c_int { 0 }
210+
# fn main() { }
211+
212+
#[cfg(test)]
213+
mod tests {
214+
use super::*;
215+
216+
#[test]
217+
fn valid() {
218+
let d = vec![0xde, 0xad, 0xd0, 0x0d];
219+
let c: &[u8] = &compress(&d);
220+
assert!(validate_compressed_buffer(c));
221+
assert!(uncompress(c) == Some(d));
222+
}
223+
224+
#[test]
225+
fn invalid() {
226+
let d = vec![0, 0, 0, 0];
227+
assert!(!validate_compressed_buffer(&d));
228+
assert!(uncompress(&d).is_none());
229+
}
230+
231+
#[test]
232+
fn empty() {
233+
let d = vec![];
234+
assert!(!validate_compressed_buffer(&d));
235+
assert!(uncompress(&d).is_none());
236+
let c = compress(&d);
237+
assert!(validate_compressed_buffer(&c));
238+
assert!(uncompress(&c) == Some(d));
239+
}
240+
}
241+
```
188242

189243
# Destructors
190244

src/doc/book/macros.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ invocation site. Code such as the following will not work:
328328

329329
```rust,ignore
330330
macro_rules! foo {
331-
() => (let x = 3);
331+
() => (let x = 3;);
332332
}
333333
334334
fn main() {
@@ -342,7 +342,7 @@ tagged with the right syntax context.
342342

343343
```rust
344344
macro_rules! foo {
345-
($v:ident) => (let $v = 3);
345+
($v:ident) => (let $v = 3;);
346346
}
347347

348348
fn main() {

src/doc/reference.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ comma:
26332633

26342634
There are several forms of struct expressions. A _struct expression_
26352635
consists of the [path](#paths) of a [struct item](#structs), followed by
2636-
a brace-enclosed list of one or more comma-separated name-value pairs,
2636+
a brace-enclosed list of zero or more comma-separated name-value pairs,
26372637
providing the field values of a new instance of the struct. A field name
26382638
can be any identifier, and is separated from its value expression by a colon.
26392639
The location denoted by a struct field is mutable if and only if the
@@ -2652,10 +2652,12 @@ The following are examples of struct expressions:
26522652

26532653
```
26542654
# struct Point { x: f64, y: f64 }
2655+
# struct NothingInMe { }
26552656
# struct TuplePoint(f64, f64);
26562657
# mod game { pub struct User<'a> { pub name: &'a str, pub age: u32, pub score: usize } }
26572658
# struct Cookie; fn some_fn<T>(t: T) {}
26582659
Point {x: 10.0, y: 20.0};
2660+
NothingInMe {};
26592661
TuplePoint(10.0, 20.0);
26602662
let u = game::User {name: "Joe", age: 35, score: 100_000};
26612663
some_fn::<Cookie>(Cookie);

src/etc/unicode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
bytes_old = 0
2929
bytes_new = 0
3030

31-
preamble = '''// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
31+
preamble = '''// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
3232
// file at the top-level directory of this distribution and at
3333
// http://rust-lang.org/COPYRIGHT.
3434
//

src/jemalloc

src/liballoc/arc.rs

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,11 @@
1212

1313
//! Threadsafe reference-counted boxes (the `Arc<T>` type).
1414
//!
15-
//! The `Arc<T>` type provides shared ownership of an immutable value.
16-
//! Destruction is deterministic, and will occur as soon as the last owner is
17-
//! gone. It is marked as `Send` because it uses atomic reference counting.
18-
//!
19-
//! If you do not need thread-safety, and just need shared ownership, consider
20-
//! the [`Rc<T>` type](../rc/struct.Rc.html). It is the same as `Arc<T>`, but
21-
//! does not use atomics, making it both thread-unsafe as well as significantly
22-
//! faster when updating the reference count.
23-
//!
24-
//! The `downgrade` method can be used to create a non-owning `Weak<T>` pointer
25-
//! to the box. A `Weak<T>` pointer can be upgraded to an `Arc<T>` pointer, but
26-
//! will return `None` if the value has already been dropped.
27-
//!
28-
//! For example, a tree with parent pointers can be represented by putting the
29-
//! nodes behind strong `Arc<T>` pointers, and then storing the parent pointers
30-
//! as `Weak<T>` pointers.
15+
//! The `Arc<T>` type provides shared ownership of an immutable value through
16+
//! atomic reference counting.
3117
//!
18+
//! `Weak<T>` is a weak reference to the `Arc<T>` box, and it is created by
19+
//! the `downgrade` method.
3220
//! # Examples
3321
//!
3422
//! Sharing some immutable data between threads:
@@ -47,27 +35,6 @@
4735
//! });
4836
//! }
4937
//! ```
50-
//!
51-
//! Sharing mutable data safely between threads with a `Mutex`:
52-
//!
53-
//! ```no_run
54-
//! use std::sync::{Arc, Mutex};
55-
//! use std::thread;
56-
//!
57-
//! let five = Arc::new(Mutex::new(5));
58-
//!
59-
//! for _ in 0..10 {
60-
//! let five = five.clone();
61-
//!
62-
//! thread::spawn(move || {
63-
//! let mut number = five.lock().unwrap();
64-
//!
65-
//! *number += 1;
66-
//!
67-
//! println!("{}", *number); // prints 6
68-
//! });
69-
//! }
70-
//! ```
7138
7239
use boxed::Box;
7340

@@ -92,15 +59,19 @@ use heap::deallocate;
9259
const MAX_REFCOUNT: usize = (isize::MAX) as usize;
9360

9461
/// An atomically reference counted wrapper for shared state.
62+
/// Destruction is deterministic, and will occur as soon as the last owner is
63+
/// gone. It is marked as `Send` because it uses atomic reference counting.
9564
///
96-
/// # Examples
65+
/// If you do not need thread-safety, and just need shared ownership, consider
66+
/// the [`Rc<T>` type](../rc/struct.Rc.html). It is the same as `Arc<T>`, but
67+
/// does not use atomics, making it both thread-unsafe as well as significantly
68+
/// faster when updating the reference count.
9769
///
98-
/// In this example, a large vector is shared between several threads.
99-
/// With simple pipes, without `Arc`, a copy would have to be made for each
100-
/// thread.
70+
/// # Examples
10171
///
102-
/// When you clone an `Arc<T>`, it will create another pointer to the data and
103-
/// increase the reference counter.
72+
/// In this example, a large vector of data will be shared by several threads. First we
73+
/// wrap it with a `Arc::new` and then clone the `Arc<T>` reference for every thread (which will
74+
/// increase the reference count atomically).
10475
///
10576
/// ```
10677
/// use std::sync::Arc;
@@ -111,6 +82,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
11182
/// let shared_numbers = Arc::new(numbers);
11283
///
11384
/// for _ in 0..10 {
85+
/// // prepare a copy of reference here and it will be moved to the thread
11486
/// let child_numbers = shared_numbers.clone();
11587
///
11688
/// thread::spawn(move || {
@@ -121,6 +93,29 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
12193
/// }
12294
/// }
12395
/// ```
96+
/// You can also share mutable data between threads safely
97+
/// by putting it inside `Mutex` and then share `Mutex` immutably
98+
/// with `Arc<T>` as shown below.
99+
///
100+
/// ```
101+
/// use std::sync::{Arc, Mutex};
102+
/// use std::thread;
103+
///
104+
/// let five = Arc::new(Mutex::new(5));
105+
///
106+
/// for _ in 0..10 {
107+
/// let five = five.clone();
108+
///
109+
/// thread::spawn(move || {
110+
/// let mut number = five.lock().unwrap();
111+
///
112+
/// *number += 1;
113+
///
114+
/// println!("{}", *number); // prints 6
115+
/// });
116+
/// }
117+
/// ```
118+
124119
#[unsafe_no_drop_flag]
125120
#[stable(feature = "rust1", since = "1.0.0")]
126121
pub struct Arc<T: ?Sized> {
@@ -139,6 +134,14 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Arc<U>> for Arc<T> {}
139134
///
140135
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be
141136
/// used to break cycles between `Arc` pointers.
137+
///
138+
/// A `Weak<T>` pointer can be upgraded to an `Arc<T>` pointer, but
139+
/// will return `None` if the value has already been dropped.
140+
///
141+
/// For example, a tree with parent pointers can be represented by putting the
142+
/// nodes behind strong `Arc<T>` pointers, and then storing the parent pointers
143+
/// as `Weak<T>` pointers.
144+
142145
#[unsafe_no_drop_flag]
143146
#[stable(feature = "arc_weak", since = "1.4.0")]
144147
pub struct Weak<T: ?Sized> {

0 commit comments

Comments
 (0)