Skip to content

Rollup of 20 pull requests #22703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ef1308c
Handle RUST_TEST_NOCAPTURE in compiletest and set add if to run env
fhahn Feb 15, 2015
2b7f7f2
Replace `exchange_malloc`/`exchange_free` demo with something unrelat…
pnkfelix Feb 17, 2015
55f625a
os.getcwd renamed to env::current_dir
tshepang Feb 18, 2015
2f735f5
unused imports
tshepang Feb 18, 2015
ac3a390
rustbook: no-longer-used feature gate
tshepang Feb 18, 2015
bb22c10
borrowck/README.md: Remove most references to &const
kmcallister Feb 19, 2015
0c1fc1c
borrowck/README.md: Clarify MUTABILITY and ALIASABLE
kmcallister Feb 19, 2015
160cf96
borrowck/README.md: Remove SCOPE (mostly unused)
kmcallister Feb 19, 2015
ac6cab0
borrowck/README.md: Fix display of code on GitHub
kmcallister Feb 19, 2015
f051e13
Fix references to doc.rs throughout the code
kmcallister Feb 19, 2015
1597f91
borrowck/README.md: Normalize types in examples
kmcallister Feb 19, 2015
96be553
book: Minor clarifications about strings
brson Feb 20, 2015
fcc21b3
docs: Explain static dispatch advantage more clearly
brson Feb 20, 2015
eceab29
Fix typo
bombless Feb 20, 2015
b4dc9fd
Remove last traces of BitV and BitVSet from documentation
fhartwig Feb 21, 2015
aa6604a
Fix small typo in reference to code of conduct
tigarmo Feb 22, 2015
c2a2b10
shift int/uint tests around to avoid code repetition
glacjay Feb 22, 2015
928341e
Include tuple indexing in the Reference.
achernya Feb 22, 2015
24fa6be
Miscellaneous README changes
iKevinY Feb 21, 2015
c5a3cbb
Fix typos in CStr docs
shepmaster Feb 22, 2015
a499148
Fix another occurrence of #22243
untitaker Feb 22, 2015
d7c02c3
Link from literals to their representation
steveklabnik Feb 13, 2015
27f3571
Improve documentation for libcollections/str
steveklabnik Feb 18, 2015
6f9b91d
save-analysis: handle type defs in struct patterns
nrc Feb 19, 2015
6154c88
Update intro.md to fix thread spawning example Closes #22419
diamondman Feb 13, 2015
04b0a3a
save-analysis: fix impls on primitive types
nrc Feb 22, 2015
72eaf2c
Switch to &vector notation in the iterators chapter.
jxcl Feb 21, 2015
9f2b067
Fixed erroneous statements in iterators.md.
jxcl Feb 23, 2015
f71ca70
Rollup merge of #22270 - steveklabnik:gh22152, r=huonw
bombless Feb 23, 2015
fb17900
Rollup merge of #22371 - fhahn:issue-17829-compiletest-nocapture, r=M…
bombless Feb 23, 2015
bf2c75a
Rollup merge of #22499 - pnkfelix:purge-demo-of-exchange-malloc-and-f…
bombless Feb 23, 2015
198db70
Rollup merge of #22505 - tshepang:current_dir, r=steveklabnik
bombless Feb 23, 2015
4384418
Rollup merge of #22513 - steveklabnik:doc_str, r=brson
bombless Feb 23, 2015
93b6541
Rollup merge of #22514 - diamondman:intro_doc_threading, r=steveklabnik
bombless Feb 23, 2015
53e8232
Rollup merge of #22556 - brson:str, r=steveklabnik
bombless Feb 23, 2015
5c4e0c6
Rollup merge of #22559 - kmcallister:borrowck-readme, r=nikomatsakis
bombless Feb 23, 2015
8febe56
Rollup merge of #22593 - brson:spatch, r=steveklabnik
bombless Feb 23, 2015
310833c
Rollup merge of #22601 - bombless:patch-1, r=Manishearth
bombless Feb 23, 2015
cac3007
Rollup merge of #22612 - jxcl:iter-replace, r=steveklabnik
bombless Feb 23, 2015
2ae7e29
Rollup merge of #22613 - nick29581:fix-save-alias, r=huonw
bombless Feb 23, 2015
030b188
Rollup merge of #22643 - fhartwig:bitvec-doc-fix, r=alexcrichton
bombless Feb 23, 2015
f8dc117
Rollup merge of #22652 - tigarmo:patch-1, r=Manishearth
bombless Feb 23, 2015
375c75c
Rollup merge of #22658 - glacjay:issue-22535, r=Gankro
bombless Feb 23, 2015
8d1753b
Rollup merge of #22660 - achernya:tuple-reference, r=alexcrichton
bombless Feb 23, 2015
54b80ec
Rollup merge of #22662 - iKevinY:readme-changes, r=steveklabnik
bombless Feb 23, 2015
9135cb0
Rollup merge of #22670 - shepmaster:c_str_typos, r=Manishearth
bombless Feb 23, 2015
b8cfe57
Rollup merge of #22674 - untitaker:issue22243, r=alexcrichton
bombless Feb 23, 2015
cf05774
Rollup merge of #22691 - nick29581:fix-save-impl, r=huonw
bombless Feb 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 42 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ Read ["Installing Rust"] from [The Book].
## Building from Source

1. Make sure you have installed the dependencies:
* `g++` 4.7 or `clang++` 3.x
* `python` 2.6 or later (but not 3.x)
* GNU `make` 3.81 or later
* `curl`
* `git`

* `g++` 4.7 or `clang++` 3.x
* `python` 2.6 or later (but not 3.x)
* GNU `make` 3.81 or later
* `curl`
* `git`

2. Clone the [source] with `git`:

$ git clone https://github.com/rust-lang/rust.git
$ cd rust
```sh
$ git clone https://github.com/rust-lang/rust.git
$ cd rust
```

[source]: https://github.com/rust-lang/rust

3. Build and install:

$ ./configure
$ make && make install
```sh
$ ./configure
$ make && make install
```

> ***Note:*** You may need to use `sudo make install` if you do not normally have
> permission to modify the destination directory. The install locations can
> be adjusted by passing a `--prefix` argument to `configure`. Various other
> options are also supported, pass `--help` for more information on them.
> ***Note:*** You may need to use `sudo make install` if you do not
> normally have permission to modify the destination directory. The
> install locations can be adjusted by passing a `--prefix` argument
> to `configure`. Various other options are also supported – pass
> `--help` for more information on them.

When complete, `make install` will place several programs into
`/usr/local/bin`: `rustc`, the Rust compiler, and `rustdoc`, the
Expand All @@ -47,27 +53,30 @@ Read ["Installing Rust"] from [The Book].

### Building on Windows

To easily build on windows we can use [MSYS2](http://msys2.github.io/):
[MSYS2](http://msys2.github.io/) can be used to easily build Rust on Windows:

1. Grab the latest MSYS2 installer and go through the installer.
2. Now from the MSYS2 terminal we want to install the mingw64 toolchain and the other
tools we need.

```bash
# choose one based on platform
$ pacman -S mingw-w64-i686-toolchain
$ pacman -S mingw-w64-x86_64-toolchain
2. From the MSYS2 terminal, install the `mingw64` toolchain and other required
tools.

```sh
# Choose one based on platform:
$ pacman -S mingw-w64-i686-toolchain
$ pacman -S mingw-w64-x86_64-toolchain

$ pacman -S base-devel
```

$ pacman -S base-devel
```
3. Run `mingw32_shell.bat` or `mingw64_shell.bat` from wherever you installed
MYSY2 (i.e. `C:\msys`), depending on whether you want 32-bit or 64-bit Rust.

3. With that now start `mingw32_shell.bat` or `mingw64_shell.bat`
from where you installed MSYS2 (i.e. `C:\msys`). Which one you
choose depends on if you want 32 or 64 bit Rust.
4. From there just navigate to where you have Rust's source code, configure and build it:
4. Navigate to Rust's source code, configure and build it:

$ ./configure
$ make && make install
```sh
$ ./configure
$ make && make install
```

## Notes

Expand All @@ -92,15 +101,15 @@ There is more advice about hacking on Rust in [CONTRIBUTING.md].

[CONTRIBUTING.md]: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md

## Getting help
## Getting Help

The Rust community congregates in a few places:

* [StackOverflow] - Direct questions about using the language here.
* [users.rust-lang.org] - General discussion, broader questions.
* [Stack Overflow] - Direct questions about using the language.
* [users.rust-lang.org] - General discussion and broader questions.
* [/r/rust] - News and general discussion.

[StackOverflow]: http://stackoverflow.com/questions/tagged/rust
[Stack Overflow]: http://stackoverflow.com/questions/tagged/rust
[/r/rust]: http://reddit.com/r/rust
[users.rust-lang.org]: http://users.rust-lang.org/

Expand All @@ -111,7 +120,7 @@ To contribute to Rust, please see [CONTRIBUTING.md](CONTRIBUTING.md).
Rust has an [IRC] culture and most real-time collaboration happens in a
variety of channels on Mozilla's IRC network, irc.mozilla.org. The
most popular channel is [#rust], a venue for general discussion about
Rust, and a good place to ask for help,
Rust, and a good place to ask for help.

[IRC]: https://en.wikipedia.org/wiki/Internet_Relay_Chat
[#rust]: irc://irc.mozilla.org/rust
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
logfile: config.logfile.clone(),
run_tests: true,
run_benchmarks: true,
nocapture: false,
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
color: test::AutoColor,
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::env;

use common::Config;
use common;
use util;
Expand Down Expand Up @@ -125,6 +127,16 @@ pub fn load_props(testfile: &Path) -> TestProps {
true
});

for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_TASKS"] {
match env::var(key) {
Ok(val) =>
if exec_env.iter().find(|&&(ref x, _)| *x == key.to_string()).is_none() {
exec_env.push((key.to_string(), val))
},
Err(..) => {}
}
}

TestProps {
error_patterns: error_patterns,
compile_flags: compile_flags,
Expand Down
64 changes: 30 additions & 34 deletions src/doc/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,39 +426,33 @@ use std::thread::Thread;
fn main() {
let mut numbers = vec![1, 2, 3];

for i in 0..3 {
Thread::spawn(move || {
let guards: Vec<_> = (0..3).map(|i| {
Thread::scoped(move || {
for j in 0..3 { numbers[j] += 1 }
});
}
}).collect();
}
```

It gives us this error:

```text
6:71 error: capture of moved value: `numbers`
for j in 0..3 { numbers[j] += 1 }
^~~~~~~
7:50 note: `numbers` moved into closure environment here
spawn(move || {
for j in 0..3 { numbers[j] += 1 }
});
6:79 error: cannot assign to immutable dereference (dereference is implicit, due to indexing)
for j in 0..3 { numbers[j] += 1 }
^~~~~~~~~~~~~~~
7:29: 9:10 error: cannot move out of captured outer variable in an `FnMut` closure
7 Thread::scoped(move || {
8 for j in 0..3 { numbers[j] += 1 }
9 });
```

It mentions that "numbers moved into closure environment". Because we
declared the closure as a moving closure, and it referred to
`numbers`, the closure will try to take ownership of the vector. But
the closure itself is created in a loop, and hence we will actually
create three closures, one for every iteration of the loop. This means
that all three of those closures would try to own `numbers`, which is
impossible -- `numbers` must have just one owner. Rust detects this
and gives us the error: we claim that `numbers` has ownership, but our
code tries to make three owners. This may cause a safety problem, so
Rust disallows it.
It mentions that "captured outer variable in an `FnMut` closure".
Because we declared the closure as a moving closure, and it referred
to `numbers`, the closure will try to take ownership of the
vector. But the closure itself is created in a loop, and hence we will
actually create three closures, one for every iteration of the
loop. This means that all three of those closures would try to own
`numbers`, which is impossible -- `numbers` must have just one
owner. Rust detects this and gives us the error: we claim that
`numbers` has ownership, but our code tries to make three owners. This
may cause a safety problem, so Rust disallows it.

What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
*Arc* stands for "atomically reference counted". In other words, an Arc will
Expand All @@ -480,14 +474,14 @@ use std::sync::{Arc,Mutex};
fn main() {
let numbers = Arc::new(Mutex::new(vec![1, 2, 3]));

for i in 0..3 {
let guards: Vec<_> = (0..3).map(|i| {
let number = numbers.clone();
Thread::spawn(move || {
Thread::scoped(move || {
let mut array = number.lock().unwrap();
array[i] += 1;
println!("numbers[{}] is {}", i, array[i]);
});
}
}).collect();
}
```

Expand Down Expand Up @@ -516,8 +510,10 @@ numbers[1] is 3
numbers[0] is 2
```

Each time, we get a slightly different output, because each thread works in a
different order. You may not get the same output as this sample, even.
Each time, we can get a slithtly different output because the threads
are not quaranteed to run in any set order. If you get the same order
every time it is because each of these threads are very small and
complete too fast for their indeterminate behavior to surface.

The important part here is that the Rust compiler was able to use ownership to
give us assurance _at compile time_ that we weren't doing something incorrect
Expand All @@ -539,13 +535,13 @@ safety check that makes this an error about moved values:
use std::thread::Thread;

fn main() {
let vec = vec![1, 2, 3];

for i in 0..3 {
Thread::spawn(move || {
println!("{}", vec[i]);
let numbers = vec![1, 2, 3];
let guards: Vec<_> = (0..3).map(|i| {
Thread::scoped(move || {
println!("{}", numbers[i]);
});
}
}).collect();
}
```

Expand Down
7 changes: 6 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ This last example is different because it is not possible to use the suffix
syntax with a floating point literal ending in a period. `2.f64` would attempt
to call a method named `f64` on `2`.

The representation semantics of floating-point numbers are described in
["Machine Types"](#machine-types).

#### Boolean literals

The two values of the boolean type are written `true` and `false`.
Expand Down Expand Up @@ -3554,7 +3557,8 @@ Tuple types and values are denoted by listing the types or values of their
elements, respectively, in a parenthesized, comma-separated list.

Because tuple elements don't have a name, they can only be accessed by
pattern-matching.
pattern-matching or by using `N` directly as a field to access the
`N`th element.

An example of a tuple type and its use:

Expand All @@ -3563,6 +3567,7 @@ type Pair<'a> = (i32, &'a str);
let p: Pair<'static> = (10, "hello");
let (a, b) = p;
assert!(b != "world");
assert!(p.0 == 10);
```

### Array, and Slice types
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/crates-and-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Rust has two distinct terms that relate to the module system: *crate* and
*module*. A crate is synonymous with a *library* or *package* in other
languages. Hence "Cargo" as the name of Rust's package management tool: you
ship your crates to others with Cargo. Crates can produce an executable or a
shared library, depending on the project.
library, depending on the project.

Each crate has an implicit *root module* that contains the code for that crate.
You can then define a tree of sub-modules under that root module. Modules allow
Expand Down
26 changes: 13 additions & 13 deletions src/doc/trpl/iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ for i in 0..nums.len() {
}
```

This is strictly worse than using an actual iterator. The `.iter()` method on
vectors returns an iterator which iterates through a reference to each element
of the vector in turn. So write this:
This is strictly worse than using an actual iterator. You can iterate over vectors
directly, so write this:

```rust
let nums = vec![1, 2, 3];

for num in nums.iter() {
for num in &nums {
println!("{}", num);
}
```
Expand All @@ -86,16 +85,17 @@ see it. This code works fine too:
```rust
let nums = vec![1, 2, 3];

for num in nums.iter() {
for num in &nums {
println!("{}", *num);
}
```

Now we're explicitly dereferencing `num`. Why does `iter()` give us references?
Well, if it gave us the data itself, we would have to be its owner, which would
involve making a copy of the data and giving us the copy. With references,
we're just borrowing a reference to the data, and so it's just passing
a reference, without needing to do the copy.
Now we're explicitly dereferencing `num`. Why does `&nums` give us
references? Firstly, because we explicitly asked it to with
`&`. Secondly, if it gave us the data itself, we would have to be its
owner, which would involve making a copy of the data and giving us the
copy. With references, we're just borrowing a reference to the data,
and so it's just passing a reference, without needing to do the move.

So, now that we've established that ranges are often not what you want, let's
talk about what you do want instead.
Expand Down Expand Up @@ -230,9 +230,9 @@ let nums = (1..100).collect::<Vec<i32>>();
Now, `collect()` will require that the range gives it some numbers, and so
it will do the work of generating the sequence.

Ranges are one of two basic iterators that you'll see. The other is `iter()`,
which you've used before. `iter()` can turn a vector into a simple iterator
that gives you each element in turn:
Ranges are one of two basic iterators that you'll see. The other is `iter()`.
`iter()` can turn a vector into a simple iterator that gives you each element
in turn:

```rust
let nums = [1, 2, 3];
Expand Down
9 changes: 5 additions & 4 deletions src/doc/trpl/more-strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ string literal or a `String`.

# String

A `String` is a heap-allocated string. This string is growable, and is also
guaranteed to be UTF-8.
A `String` is a heap-allocated string. This string is growable, and is
also guaranteed to be UTF-8. `String`s are commonly created by
converting from a string slice using the `to_string` method.

```
let mut s = "Hello".to_string();
Expand All @@ -49,7 +50,7 @@ s.push_str(", world.");
println!("{}", s);
```

You can coerce a `String` into a `&str` by dereferencing it:
A reference to a `String` will automatically coerce to a string slice:

```
fn takes_slice(slice: &str) {
Expand All @@ -58,7 +59,7 @@ fn takes_slice(slice: &str) {

fn main() {
let s = "Hello".to_string();
takes_slice(&*s);
takes_slice(&s);
}
```

Expand Down
Loading