rollup merge of #19614: steveklabnik/gh19599

Fixes #19599
This commit is contained in:
Alex Crichton 2014-12-09 09:25:04 -08:00
commit fb587f1f9b
10 changed files with 75 additions and 75 deletions

View File

@ -452,7 +452,7 @@ fn main() {
Rust will give us a compile-time error: Rust will give us a compile-time error:
```{notrust,ignore} ```{ignore}
Compiling phrases v0.0.1 (file:///home/you/projects/phrases) Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
/home/you/projects/phrases/src/main.rs:4:5: 4:40 error: a value named `hello` has already been imported in this module /home/you/projects/phrases/src/main.rs:4:5: 4:40 error: a value named `hello` has already been imported in this module
/home/you/projects/phrases/src/main.rs:4 use phrases::japanese::greetings::hello; /home/you/projects/phrases/src/main.rs:4 use phrases::japanese::greetings::hello;

View File

@ -76,7 +76,7 @@ fn main() {
This will give us an error: This will give us an error:
```{notrust,ignore} ```{ignore}
error: non-exhaustive patterns: `_` not covered [E0004] error: non-exhaustive patterns: `_` not covered [E0004]
``` ```
@ -189,7 +189,7 @@ panic!("boom");
gives gives
```{notrust,ignore} ```{ignore}
task '<main>' panicked at 'boom', hello.rs:2 task '<main>' panicked at 'boom', hello.rs:2
``` ```

View File

@ -130,7 +130,7 @@ fn add_one(mut num: Box<int>) {
This does not compile, and gives us an error: This does not compile, and gives us an error:
```{notrust,ignore} ```{ignore}
error: use of moved value: `x` error: use of moved value: `x`
println!("{}", x); println!("{}", x);
^ ^
@ -406,7 +406,7 @@ fn main() {
We try to make four `Wheel`s, each with a `Car` that it's attached to. But the We try to make four `Wheel`s, each with a `Car` that it's attached to. But the
compiler knows that on the second iteration of the loop, there's a problem: compiler knows that on the second iteration of the loop, there's a problem:
```{notrust,ignore} ```{ignore}
error: use of moved value: `car` error: use of moved value: `car`
Wheel { size: 360, owner: car }; Wheel { size: 360, owner: car };
^~~ ^~~

View File

@ -84,7 +84,7 @@ println!("{}", x + z);
This gives us an error: This gives us an error:
```{notrust,ignore} ```{ignore}
hello.rs:6:24: 6:25 error: mismatched types: expected `int` but found `&int` (expected int but found &-ptr) hello.rs:6:24: 6:25 error: mismatched types: expected `int` but found `&int` (expected int but found &-ptr)
hello.rs:6 println!("{}", x + z); hello.rs:6 println!("{}", x + z);
^ ^
@ -132,7 +132,7 @@ Pointers are useful in languages that are pass-by-value, rather than
pass-by-reference. Basically, languages can make two choices (this is made pass-by-reference. Basically, languages can make two choices (this is made
up syntax, it's not Rust): up syntax, it's not Rust):
```{notrust,ignore} ```{ignore}
func foo(x) { func foo(x) {
x = 5 x = 5
} }
@ -152,7 +152,7 @@ and therefore, can change its value. At the comment, `i` will be `5`.
So what do pointers have to do with this? Well, since pointers point to a So what do pointers have to do with this? Well, since pointers point to a
location in memory... location in memory...
```{notrust,ignore} ```{ignore}
func foo(&int x) { func foo(&int x) {
*x = 5 *x = 5
} }
@ -179,7 +179,7 @@ but here are problems with pointers in other languages:
Uninitialized pointers can cause a problem. For example, what does this program Uninitialized pointers can cause a problem. For example, what does this program
do? do?
```{notrust,ignore} ```{ignore}
&int x; &int x;
*x = 5; // whoops! *x = 5; // whoops!
``` ```
@ -191,7 +191,7 @@ knows. This might be harmless, and it might be catastrophic.
When you combine pointers and functions, it's easy to accidentally invalidate When you combine pointers and functions, it's easy to accidentally invalidate
the memory the pointer is pointing to. For example: the memory the pointer is pointing to. For example:
```{notrust,ignore} ```{ignore}
func make_pointer(): &int { func make_pointer(): &int {
x = 5; x = 5;
@ -213,7 +213,7 @@ As one last example of a big problem with pointers, **aliasing** can be an
issue. Two pointers are said to alias when they point at the same location issue. Two pointers are said to alias when they point at the same location
in memory. Like this: in memory. Like this:
```{notrust,ignore} ```{ignore}
func mutate(&int i, int j) { func mutate(&int i, int j) {
*i = j; *i = j;
} }
@ -398,7 +398,7 @@ fn main() {
It gives this error: It gives this error:
```{notrust,ignore} ```{ignore}
test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed test.rs:5:8: 5:10 error: cannot assign to `*x` because it is borrowed
test.rs:5 *x -= 1; test.rs:5 *x -= 1;
^~ ^~
@ -522,7 +522,7 @@ boxes, though. As a rough approximation, you can treat this Rust code:
As being similar to this C code: As being similar to this C code:
```{notrust,ignore} ```{ignore}
{ {
int *x; int *x;
x = (int *)malloc(sizeof(int)); x = (int *)malloc(sizeof(int));
@ -626,7 +626,7 @@ fn main() {
This prints: This prints:
```{notrust,ignore} ```{ignore}
Cons(1, box Cons(2, box Cons(3, box Nil))) Cons(1, box Cons(2, box Cons(3, box Nil)))
``` ```

View File

@ -181,7 +181,7 @@ for l in s.graphemes(true) {
This prints: This prints:
```{notrust,ignore} ```{text}
n͈̰̎ n͈̰̎
i̙̮͚̦ i̙̮͚̦
@ -207,7 +207,7 @@ for l in s.chars() {
This prints: This prints:
```{notrust,ignore} ```{text}
u u
͔ ͔
n n
@ -252,7 +252,7 @@ for l in s.bytes() {
This will print: This will print:
```{notrust,ignore} ```{text}
117 117
205 205
148 148

View File

@ -355,7 +355,7 @@ just `cargo build` and it'll work the right way.
You'll also notice that Cargo has created a new file: `Cargo.lock`. You'll also notice that Cargo has created a new file: `Cargo.lock`.
```{ignore,notrust} ```{ignore}
[root] [root]
name = "hello_world" name = "hello_world"
version = "0.0.1" version = "0.0.1"
@ -426,7 +426,7 @@ x = 10i;
It will give you this error: It will give you this error:
```{ignore,notrust} ```{ignore}
error: re-assignment of immutable variable `x` error: re-assignment of immutable variable `x`
x = 10i; x = 10i;
^~~~~~~ ^~~~~~~
@ -486,7 +486,7 @@ fn main() {
You can use `cargo build` on the command line to build it. You'll get a warning, You can use `cargo build` on the command line to build it. You'll get a warning,
but it will still print "Hello, world!": but it will still print "Hello, world!":
```{ignore,notrust} ```{ignore}
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world) Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default src/main.rs:2:9: 2:10 warning: unused variable: `x`, #[warn(unused_variable)] on by default
src/main.rs:2 let x: int; src/main.rs:2 let x: int;
@ -664,7 +664,7 @@ let y: int = if x == 5i { 10i; } else { 15i; };
Note the semicolons after the 10 and 15. Rust will give us the following error: Note the semicolons after the 10 and 15. Rust will give us the following error:
```{ignore,notrust} ```{ignore}
error: mismatched types: expected `int` but found `()` (expected int but found ()) error: mismatched types: expected `int` but found `()` (expected int but found ())
``` ```
@ -747,7 +747,7 @@ fn print_number(x, y) {
You get this error: You get this error:
```{ignore,notrust} ```{ignore}
hello.rs:5:18: 5:19 error: expected `:` but found `,` hello.rs:5:18: 5:19 error: expected `:` but found `,`
hello.rs:5 fn print_number(x, y) { hello.rs:5 fn print_number(x, y) {
``` ```
@ -779,7 +779,7 @@ fn add_one(x: int) -> int {
We would get an error: We would get an error:
```{ignore,notrust} ```{ignore}
error: not all control paths return a value error: not all control paths return a value
fn add_one(x: int) -> int { fn add_one(x: int) -> int {
x + 1; x + 1;
@ -1197,7 +1197,7 @@ So what's the big advantage here? Well, there are a few. First of all, `match`
enforces 'exhaustiveness checking.' Do you see that last arm, the one with the enforces 'exhaustiveness checking.' Do you see that last arm, the one with the
underscore (`_`)? If we remove that arm, Rust will give us an error: underscore (`_`)? If we remove that arm, Rust will give us an error:
```{ignore,notrust} ```{ignore}
error: non-exhaustive patterns: `_` not covered error: non-exhaustive patterns: `_` not covered
``` ```
@ -1344,7 +1344,7 @@ for x in range(0i, 10i) {
In slightly more abstract terms, In slightly more abstract terms,
```{ignore,notrust} ```{ignore}
for var in expression { for var in expression {
code code
} }
@ -1849,7 +1849,7 @@ Before we move on, let me show you one more Cargo command: `run`. `cargo run`
is kind of like `cargo build`, but it also then runs the produced executable. is kind of like `cargo build`, but it also then runs the produced executable.
Try it out: Try it out:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -1947,7 +1947,7 @@ for this example, it is not important.
Let's try to compile this using `cargo build`: Let's try to compile this using `cargo build`:
```{notrust,no_run} ```{no_run}
$ cargo build $ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:7:26: 7:34 error: the type of this value must be known in this context src/main.rs:7:26: 7:34 error: the type of this value must be known in this context
@ -1995,7 +1995,7 @@ fn main() {
Try running our new program a few times: Try running our new program a few times:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -2048,7 +2048,7 @@ fn main() {
And trying it out: And trying it out:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -2103,7 +2103,7 @@ fn cmp(a: int, b: int) -> Ordering {
If we try to compile, we'll get some errors: If we try to compile, we'll get some errors:
```{notrust,ignore} ```{ignore}
$ cargo build $ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:20:15: 20:20 error: mismatched types: expected `int` but found `collections::string::String` (expected int but found struct collections::string::String) src/main.rs:20:15: 20:20 error: mismatched types: expected `int` but found `collections::string::String` (expected int but found struct collections::string::String)
@ -2157,7 +2157,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
And try compiling again: And try compiling again:
```{notrust,ignore} ```{ignore}
$ cargo build $ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:20:15: 20:20 error: mismatched types: expected `uint` but found `collections::string::String` (expected uint but found struct collections::string::String) src/main.rs:20:15: 20:20 error: mismatched types: expected `uint` but found `collections::string::String` (expected uint but found struct collections::string::String)
@ -2170,7 +2170,7 @@ This error is similar to the last one: we expected to get a `uint`, but we got
a `String` instead! That's because our `input` variable is coming from the a `String` instead! That's because our `input` variable is coming from the
standard input, and you can guess anything. Try it: standard input, and you can guess anything. Try it:
```{notrust,ignore} ```{ignore}
$ ./target/guessing_game $ ./target/guessing_game
Guess the number! Guess the number!
The secret number is: 73 The secret number is: 73
@ -2254,7 +2254,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
Let's try it out! Let's try it out!
```{notrust,ignore} ```{ignore}
$ cargo build $ cargo build
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
src/main.rs:22:15: 22:24 error: mismatched types: expected `uint` but found `core::option::Option<uint>` (expected uint but found enum core::option::Option) src/main.rs:22:15: 22:24 error: mismatched types: expected `uint` but found `core::option::Option<uint>` (expected uint but found enum core::option::Option)
@ -2313,7 +2313,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
We use a `match` to either give us the `uint` inside of the `Option`, or we We use a `match` to either give us the `uint` inside of the `Option`, or we
print an error message and return. Let's give this a shot: print an error message and return. Let's give this a shot:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -2378,7 +2378,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
Let's try it! Let's try it!
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -2455,7 +2455,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
And try it out. But wait, didn't we just add an infinite loop? Yup. Remember And try it out. But wait, didn't we just add an infinite loop? Yup. Remember
that `return`? If we give a non-number answer, we'll `return` and quit. Observe: that `return`? If we give a non-number answer, we'll `return` and quit. Observe:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -2587,7 +2587,7 @@ fn cmp(a: uint, b: uint) -> Ordering {
Now we should be good! Let's try: Now we should be good! Let's try:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game) Compiling guessing_game v0.0.1 (file:///home/you/projects/guessing_game)
Running `target/guessing_game` Running `target/guessing_game`
@ -2703,7 +2703,7 @@ $ cd modules
Let's double check our work by compiling: Let's double check our work by compiling:
```{bash,notrust} ```{bash}
$ cargo run $ cargo run
Compiling modules v0.0.1 (file:///home/you/projects/modules) Compiling modules v0.0.1 (file:///home/you/projects/modules)
Running `target/modules` Running `target/modules`
@ -2765,7 +2765,7 @@ mod hello {
It gives an error: It gives an error:
```{notrust,ignore} ```{ignore}
Compiling modules v0.0.1 (file:///home/you/projects/modules) Compiling modules v0.0.1 (file:///home/you/projects/modules)
src/main.rs:2:5: 2:23 error: function `print_hello` is private src/main.rs:2:5: 2:23 error: function `print_hello` is private
src/main.rs:2 hello::print_hello(); src/main.rs:2 hello::print_hello();
@ -2789,7 +2789,7 @@ mod hello {
Usage of the `pub` keyword is sometimes called 'exporting', because Usage of the `pub` keyword is sometimes called 'exporting', because
we're making the function available for other modules. This will work: we're making the function available for other modules. This will work:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling modules v0.0.1 (file:///home/you/projects/modules) Compiling modules v0.0.1 (file:///home/you/projects/modules)
Running `target/modules` Running `target/modules`
@ -2923,7 +2923,7 @@ $ cd testing
And try it out: And try it out:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running `target/testing` Running `target/testing`
@ -2955,7 +2955,7 @@ you give them descriptive names. You'll see why in a moment. We then use a
macro, `assert!`, to assert that something is true. In this case, we're giving macro, `assert!`, to assert that something is true. In this case, we're giving
it `false`, so this test should fail. Let's try it! it `false`, so this test should fail. Let's try it!
```{notrust,ignore} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default /home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default
@ -2984,7 +2984,7 @@ task '<main>' failed at 'Some tests failed', /home/you/src/rust/src/libtest/lib.
Lots of output! Let's break this down: Lots of output! Let's break this down:
```{notrust,ignore} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
``` ```
@ -2992,7 +2992,7 @@ $ cargo test
You can run all of your tests with `cargo test`. This runs both your tests in You can run all of your tests with `cargo test`. This runs both your tests in
`tests`, as well as the tests you put inside of your crate. `tests`, as well as the tests you put inside of your crate.
```{notrust,ignore} ```{ignore}
/home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default /home/you/projects/testing/src/main.rs:1:1: 3:2 warning: function is never used: `main`, #[warn(dead_code)] on by default
/home/you/projects/testing/src/main.rs:1 fn main() { /home/you/projects/testing/src/main.rs:1 fn main() {
/home/you/projects/testing/src/main.rs:2 println!("Hello, world!") /home/you/projects/testing/src/main.rs:2 println!("Hello, world!")
@ -3006,7 +3006,7 @@ case, Rust is warning us that we've written some code that's never used: our
We'll turn this lint off for just this function soon. For now, just ignore this We'll turn this lint off for just this function soon. For now, just ignore this
output. output.
```{notrust,ignore} ```{ignore}
Running target/lib-654ce120f310a3a5 Running target/lib-654ce120f310a3a5
running 1 test running 1 test
@ -3018,7 +3018,7 @@ with good names? This is why. Here, it says 'test foo' because we called our
test 'foo.' If we had given it a good name, it'd be more clear which test test 'foo.' If we had given it a good name, it'd be more clear which test
failed, especially as we accumulate more tests. failed, especially as we accumulate more tests.
```{notrust,ignore} ```{ignore}
failures: failures:
---- foo stdout ---- ---- foo stdout ----
@ -3049,7 +3049,7 @@ fn foo() {
And then try to run our tests again: And then try to run our tests again:
```{notrust,ignore} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5 Running target/lib-654ce120f310a3a5
@ -3089,7 +3089,7 @@ include `main` when it's _not_ true. So we use `not` to negate things:
With this attribute we won't get the warning (even With this attribute we won't get the warning (even
though `src/main.rs` gets recompiled this time): though `src/main.rs` gets recompiled this time):
```{notrust,ignore} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5 Running target/lib-654ce120f310a3a5
@ -3120,7 +3120,7 @@ fn math_checks_out() {
And try to run the test: And try to run the test:
```{notrust,ignore} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
/home/you/projects/testing/tests/lib.rs:3:18: 3:38 error: unresolved name `add_three_times_four`. /home/you/projects/testing/tests/lib.rs:3:18: 3:38 error: unresolved name `add_three_times_four`.
@ -3180,7 +3180,7 @@ fn math_checks_out() {
Let's give it a run: Let's give it a run:
```{ignore,notrust} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5 Running target/lib-654ce120f310a3a5
@ -3229,7 +3229,7 @@ fn times_four(x: int) -> int { x * 4 }
If you run `cargo test`, you should get the same output: If you run `cargo test`, you should get the same output:
```{ignore,notrust} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5 Running target/lib-654ce120f310a3a5
@ -3283,7 +3283,7 @@ fn test_add_three() {
We'd get this error: We'd get this error:
```{notrust,ignore} ```{ignore}
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
/home/you/projects/testing/tests/lib.rs:3:5: 3:24 error: function `add_three` is private /home/you/projects/testing/tests/lib.rs:3:5: 3:24 error: function `add_three` is private
/home/you/projects/testing/tests/lib.rs:3 use testing::add_three; /home/you/projects/testing/tests/lib.rs:3 use testing::add_three;
@ -3325,7 +3325,7 @@ mod test {
Let's give it a shot: Let's give it a shot:
```{ignore,notrust} ```{ignore}
$ cargo test $ cargo test
Compiling testing v0.0.1 (file:///home/you/projects/testing) Compiling testing v0.0.1 (file:///home/you/projects/testing)
Running target/lib-654ce120f310a3a5 Running target/lib-654ce120f310a3a5
@ -3455,7 +3455,7 @@ let y = &mut x;
Rust will complain: Rust will complain:
```{ignore,notrust} ```{ignore}
error: cannot borrow immutable local variable `x` as mutable error: cannot borrow immutable local variable `x` as mutable
let y = &mut x; let y = &mut x;
^ ^
@ -3482,7 +3482,7 @@ let z = &mut x;
It gives us this error: It gives us this error:
```{notrust,ignore} ```{ignore}
error: cannot borrow `x` as mutable more than once at a time error: cannot borrow `x` as mutable more than once at a time
let z = &mut x; let z = &mut x;
^ ^
@ -3628,7 +3628,7 @@ let z = &mut x;
The error: The error:
```{notrust,ignore} ```{ignore}
error: cannot borrow `x` as mutable more than once at a time error: cannot borrow `x` as mutable more than once at a time
let z = &mut x; let z = &mut x;
^ ^
@ -3646,7 +3646,7 @@ note: previous borrow ends here
This error comes in three parts. Let's go over each in turn. This error comes in three parts. Let's go over each in turn.
```{notrust,ignore} ```{ignore}
error: cannot borrow `x` as mutable more than once at a time error: cannot borrow `x` as mutable more than once at a time
let z = &mut x; let z = &mut x;
^ ^
@ -3655,7 +3655,7 @@ error: cannot borrow `x` as mutable more than once at a time
This error states the restriction: you cannot lend out something mutable more This error states the restriction: you cannot lend out something mutable more
than once at the same time. The borrow checker knows the rules! than once at the same time. The borrow checker knows the rules!
```{notrust,ignore} ```{ignore}
note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends note: previous borrow of `x` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `x` until the borrow ends
let y = &mut x; let y = &mut x;
^ ^
@ -3667,7 +3667,7 @@ the first mutable borrow occurred. The error showed us the second. So now we
see both parts of the problem. It also alludes to rule #3, by reminding us that see both parts of the problem. It also alludes to rule #3, by reminding us that
we can't change `x` until the borrow is over. we can't change `x` until the borrow is over.
```{notrust,ignore} ```{ignore}
note: previous borrow ends here note: previous borrow ends here
fn main() { fn main() {
let mut x = 5i; let mut x = 5i;
@ -3770,7 +3770,7 @@ let y = &mut x;
This gives us this error: This gives us this error:
```{notrust,ignore} ```{ignore}
error: cannot use `*x` because it was mutably borrowed error: cannot use `*x` because it was mutably borrowed
*x; *x;
^~ ^~
@ -4595,7 +4595,7 @@ element reference has the closure it's been given as an argument called on it.
So this would give us the numbers from `2-100`. Well, almost! If you So this would give us the numbers from `2-100`. Well, almost! If you
compile the example, you'll get a warning: compile the example, you'll get a warning:
```{notrust,ignore} ```{ignore}
warning: unused result which must be used: iterator adaptors are lazy and warning: unused result which must be used: iterator adaptors are lazy and
do nothing unless consumed, #[warn(unused_must_use)] on by default do nothing unless consumed, #[warn(unused_must_use)] on by default
range(1i, 100i).map(|x| x + 1i); range(1i, 100i).map(|x| x + 1i);
@ -4625,7 +4625,7 @@ for i in std::iter::count(1i, 5i).take(5) {
This will print This will print
```{notrust,ignore} ```{ignore}
1 1
6 6
11 11
@ -4838,7 +4838,7 @@ We can then use `T` inside the rest of the signature: `x` has type `T`, and half
of the `Result` has type `T`. However, if we try to compile that example, we'll get of the `Result` has type `T`. However, if we try to compile that example, we'll get
an error: an error:
```{notrust,ignore} ```{ignore}
error: binary operation `==` cannot be applied to type `T` error: binary operation `==` cannot be applied to type `T`
``` ```
@ -4894,7 +4894,7 @@ we use `impl Trait for Item`, rather than just `impl Item`.
So what's the big deal? Remember the error we were getting with our generic So what's the big deal? Remember the error we were getting with our generic
`inverse` function? `inverse` function?
```{notrust,ignore} ```{ignore}
error: binary operation `==` cannot be applied to type `T` error: binary operation `==` cannot be applied to type `T`
``` ```
@ -4909,7 +4909,7 @@ fn print_area<T>(shape: T) {
Rust complains: Rust complains:
```{notrust,ignore} ```{ignore}
error: type `T` does not implement any method in scope named `area` error: type `T` does not implement any method in scope named `area`
``` ```
@ -4985,7 +4985,7 @@ fn main() {
This program outputs: This program outputs:
```{notrust,ignore} ```{ignore}
This shape has an area of 3.141593 This shape has an area of 3.141593
This shape has an area of 1 This shape has an area of 1
``` ```
@ -4999,7 +4999,7 @@ print_area(5i);
We get a compile-time error: We get a compile-time error:
```{notrust,ignore} ```{ignore}
error: failed to find an implementation of trait main::HasArea for int error: failed to find an implementation of trait main::HasArea for int
``` ```
@ -5066,7 +5066,7 @@ fn main() {
Now that we've moved the structs and traits into their own module, we get an Now that we've moved the structs and traits into their own module, we get an
error: error:
```{notrust,ignore} ```{ignore}
error: type `shapes::Circle` does not implement any method in scope named `area` error: type `shapes::Circle` does not implement any method in scope named `area`
``` ```

View File

@ -313,7 +313,7 @@ print `"Hello"`, or does Rust crash?
Neither. It refuses to compile: Neither. It refuses to compile:
```{notrust,ignore} ```{ignore}
$ cargo run $ cargo run
Compiling hello_world v0.0.1 (file:///Users/you/src/hello_world) Compiling hello_world v0.0.1 (file:///Users/you/src/hello_world)
main.rs:8:5: 8:6 error: cannot borrow `v` as mutable because it is also borrowed as immutable main.rs:8:5: 8:6 error: cannot borrow `v` as mutable because it is also borrowed as immutable
@ -428,7 +428,7 @@ fn main() {
It gives us this error: It gives us this error:
```{notrust,ignore} ```{ignore}
6:71 error: capture of moved value: `numbers` 6:71 error: capture of moved value: `numbers`
for j in range(0, 3) { numbers[j] += 1 } for j in range(0, 3) { numbers[j] += 1 }
^~~~~~~ ^~~~~~~

View File

@ -117,7 +117,7 @@ impl ChaChaRng {
/// security proof for a more involved example of this. /// security proof for a more involved example of this.
/// ///
/// The modified word layout is: /// The modified word layout is:
/// ```notrust /// ```ignore
/// constant constant constant constant /// constant constant constant constant
/// key key key key /// key key key key
/// key key key key /// key key key key

View File

@ -120,7 +120,7 @@
//! //!
//! The compiler accepts a flag of this form a number of times: //! The compiler accepts a flag of this form a number of times:
//! //!
//! ```notrust //! ```ignore
//! --extern crate-name=path/to/the/crate.rlib //! --extern crate-name=path/to/the/crate.rlib
//! ``` //! ```
//! //!
@ -152,7 +152,7 @@
//! //!
//! and the compiler would be invoked as: //! and the compiler would be invoked as:
//! //!
//! ```notrust //! ```ignore
//! rustc a.rs --extern b1=path/to/libb1.rlib --extern b2=path/to/libb2.rlib //! rustc a.rs --extern b1=path/to/libb1.rlib --extern b2=path/to/libb2.rlib
//! ``` //! ```
//! //!
@ -178,7 +178,7 @@
//! dependencies, not the upstream transitive dependencies. Consider this //! dependencies, not the upstream transitive dependencies. Consider this
//! dependency graph: //! dependency graph:
//! //!
//! ```notrust //! ```ignore
//! A.1 A.2 //! A.1 A.2
//! | | //! | |
//! | | //! | |

View File

@ -80,7 +80,7 @@
//! circle, both centered at the origin. Since the area of a unit circle is π, //! circle, both centered at the origin. Since the area of a unit circle is π,
//! we have: //! we have:
//! //!
//! ```notrust //! ```text
//! (area of unit circle) / (area of square) = π / 4 //! (area of unit circle) / (area of square) = π / 4
//! ``` //! ```
//! //!