Skip to content

Commit

Permalink
Auto merge of #37514 - GuillaumeGomez:rollup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

- Successful merges: #36849, #37059, #37296, #37316, #37484, #37485, #37495
- Failed merges:
  • Loading branch information
bors authored Nov 2, 2016
2 parents 7c69b0d + f5c192a commit 3fba503
Show file tree
Hide file tree
Showing 15 changed files with 251 additions and 249 deletions.
6 changes: 2 additions & 4 deletions src/doc/book/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,11 @@ fn factory() -> Box<Fn(i32) -> i32> {
Box::new(|x| x + num)
}
# fn main() {
let f = factory();
let answer = f(1);
assert_eq!(6, answer);
# }
```

There’s just one last problem:
Expand All @@ -540,12 +539,11 @@ fn factory() -> Box<Fn(i32) -> i32> {

Box::new(move |x| x + num)
}
fn main() {

let f = factory();

let answer = f(1);
assert_eq!(6, answer);
}
```

By making the inner closure a `move Fn`, we create a new stack frame for our
Expand Down
1 change: 0 additions & 1 deletion src/doc/book/guessing-game.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ numbers. A bare number like above is actually shorthand for `^0.3.0`,
meaning "anything compatible with 0.3.0".
If we wanted to use only `0.3.0` exactly, we could say `rand="=0.3.0"`
(note the two equal signs).
And if we wanted to use the latest version we could use `rand="*"`.
We could also use a range of versions.
[Cargo’s documentation][cargodoc] contains more details.

Expand Down
74 changes: 39 additions & 35 deletions src/doc/book/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Cargo will automatically generate a simple test when you make a new project.
Here's the contents of `src/lib.rs`:

```rust
# fn main() {}
#[test]
fn it_works() {
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
}
}
```

Expand All @@ -36,11 +38,11 @@ currently has no body. That's good enough to pass! We can run the tests with

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test it_works ... ok
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

Expand All @@ -56,7 +58,7 @@ for the test we wrote, and another for documentation tests. We'll talk about
those later. For now, see this line:

```text
test it_works ... ok
test tests::it_works ... ok
```

Note the `it_works`. This comes from the name of our function:
Expand Down Expand Up @@ -89,31 +91,30 @@ run our tests again:

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test it_works ... FAILED
test tests::it_works ... FAILED

failures:

---- it_works stdout ----
thread 'it_works' panicked at 'assertion failed: false', /home/steve/tmp/adder/src/lib.rs:3

---- test::it_works stdout ----
thread 'tests::it_works' panicked at 'assertion failed: false', src/lib.rs:5


failures:
it_works
tests::it_works

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

thread 'main' panicked at 'Some tests failed', /home/steve/src/rust/src/libtest/lib.rs:247
error: test failed
```

Rust indicates that our test failed:

```text
test it_works ... FAILED
test tests::it_works ... FAILED
```

And that's reflected in the summary line:
Expand Down Expand Up @@ -159,11 +160,11 @@ This test will now succeed if we `panic!` and fail if we complete. Let's try it:

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test it_works ... ok
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

Expand Down Expand Up @@ -191,11 +192,11 @@ passes:

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test it_works ... ok
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

Expand Down Expand Up @@ -262,8 +263,8 @@ not:

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 2 tests
test expensive_test ... ignored
Expand All @@ -282,7 +283,7 @@ The expensive tests can be run explicitly using `cargo test -- --ignored`:

```bash
$ cargo test -- --ignored
Running target/adder-91b3e234d4ed382a
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test expensive_test ... ok
Expand All @@ -302,8 +303,11 @@ which is why the command is `cargo test -- --ignored`.
# The `tests` module

There is one way in which our existing example is not idiomatic: it's
missing the `tests` module. The idiomatic way of writing our example
looks like this:
missing the `tests` module. You might have noticed this test module was
present in the code that was initially generated with `cargo new` but
was missing from our last example. Let's explain what this does.

The idiomatic way of writing our example looks like this:

```rust,ignore
# fn main() {}
Expand Down Expand Up @@ -356,8 +360,8 @@ Note the different `use` line. Now we run our tests:
```bash
$ cargo test
Updating registry `https://github.com/rust-lang/crates.io-index`
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test tests::it_works ... ok
Expand Down Expand Up @@ -404,15 +408,15 @@ Let's run them:

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/you/projects/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0 (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

Running target/lib-c18e7d3494509e74
Running target/debug/integration_test-68064b69521c828a

running 1 test
test it_works ... ok
Expand Down Expand Up @@ -490,15 +494,15 @@ Let's run the tests again:

```bash
$ cargo test
Compiling adder v0.0.1 (file:///home/steve/tmp/adder)
Running target/adder-91b3e234d4ed382a
Compiling adder v0.1.0. (file:///home/you/projects/adder)
Running target/debug/deps/adder-91b3e234d4ed382a

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured

Running target/lib-c18e7d3494509e74
Running target/debug/integration_test-68064b69521c828a

running 1 test
test it_works ... ok
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub trait AsMut<T: ?Sized> {
///
/// # Generic Impls
///
/// - `[From<T>][From] for U` implies `Into<U> for T`
/// - [`From<T>`][From]` for U` implies `Into<U> for T`
/// - [`into()`] is reflexive, which means that `Into<T> for T` is implemented
///
/// [`TryInto`]: trait.TryInto.html
Expand Down Expand Up @@ -178,14 +178,14 @@ pub trait Into<T>: Sized {
/// ```
/// # Generic impls
///
/// - `From<T> for U` implies `[Into<U>] for T`
/// - `From<T> for U` implies [`Into<U>`]` for T`
/// - [`from()`] is reflexive, which means that `From<T> for T` is implemented
///
/// [`TryFrom`]: trait.TryFrom.html
/// [`Option<T>`]: ../../std/option/enum.Option.html
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
/// [`String`]: ../../std/string/struct.String.html
/// [Into<U>]: trait.Into.html
/// [`Into<U>`]: trait.Into.html
/// [`from()`]: trait.From.html#tymethod.from
#[stable(feature = "rust1", since = "1.0.0")]
pub trait From<T>: Sized {
Expand Down
7 changes: 4 additions & 3 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ macro_rules! panic {
/// Unsafe code relies on `assert!` to enforce run-time invariants that, if
/// violated could lead to unsafety.
///
/// Other use-cases of `assert!` include
/// [testing](https://doc.rust-lang.org/book/testing.html) and enforcing
/// run-time invariants in safe code (whose violation cannot result in unsafety).
/// Other use-cases of `assert!` include [testing] and enforcing run-time
/// invariants in safe code (whose violation cannot result in unsafety).
///
/// This macro has a second version, where a custom panic message can be provided.
///
/// [testing]: ../book/testing.html
///
/// # Examples
///
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ pub trait Unsize<T: ?Sized> {
/// compile-time error. Specifically, with structs you'll get [E0204] and with enums you'll get
/// [E0205].
///
/// [E0204]: https://doc.rust-lang.org/error-index.html#E0204
/// [E0205]: https://doc.rust-lang.org/error-index.html#E0205
/// [E0204]: ../../error-index.html#E0204
/// [E0205]: ../../error-index.html#E0205
///
/// ## When *should* my type be `Copy`?
///
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ pub trait Drop {
/// After this function is over, the memory of `self` will be deallocated.
///
/// This function cannot be called explicitly. This is compiler error
/// [0040]. However, the [`std::mem::drop`] function in the prelude can be
/// [E0040]. However, the [`std::mem::drop`] function in the prelude can be
/// used to call the argument's `Drop` implementation.
///
/// [0040]: https://doc.rust-lang.org/error-index.html#E0040
/// [`std::mem::drop`]: https://doc.rust-lang.org/std/mem/fn.drop.html
/// [E0040]: ../../error-index.html#E0040
/// [`std::mem::drop`]: ../../std/mem/fn.drop.html
///
/// # Panics
///
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl Utf8Error {
/// verified.
///
/// It is the maximum index such that `from_utf8(input[..index])`
/// would return `Some(_)`.
/// would return `Ok(_)`.
///
/// # Examples
///
Expand Down
6 changes: 0 additions & 6 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ pub enum TypeOrigin {
// Computing common supertype of an if expression with no else counter-part
IfExpressionWithNoElse(Span),

// Computing common supertype in a range expression
RangeExpression(Span),

// `where a == b`
EquatePredicate(Span),

Expand Down Expand Up @@ -231,7 +228,6 @@ impl TypeOrigin {
},
&TypeOrigin::IfExpression(_) => "if and else have incompatible types",
&TypeOrigin::IfExpressionWithNoElse(_) => "if may be missing an else clause",
&TypeOrigin::RangeExpression(_) => "start and end of range have incompatible types",
&TypeOrigin::EquatePredicate(_) => "equality predicate not satisfied",
&TypeOrigin::MainFunctionType(_) => "main function has wrong type",
&TypeOrigin::StartFunctionType(_) => "start function has wrong type",
Expand All @@ -251,7 +247,6 @@ impl TypeOrigin {
&TypeOrigin::MatchExpressionArm(..) => "match arms have compatible types",
&TypeOrigin::IfExpression(_) => "if and else have compatible types",
&TypeOrigin::IfExpressionWithNoElse(_) => "if missing an else returns ()",
&TypeOrigin::RangeExpression(_) => "start and end of range have compatible types",
&TypeOrigin::EquatePredicate(_) => "equality where clause is satisfied",
&TypeOrigin::MainFunctionType(_) => "`main` function has the correct type",
&TypeOrigin::StartFunctionType(_) => "`start` function has the correct type",
Expand Down Expand Up @@ -1755,7 +1750,6 @@ impl TypeOrigin {
TypeOrigin::MatchExpressionArm(match_span, ..) => match_span,
TypeOrigin::IfExpression(span) => span,
TypeOrigin::IfExpressionWithNoElse(span) => span,
TypeOrigin::RangeExpression(span) => span,
TypeOrigin::EquatePredicate(span) => span,
TypeOrigin::MainFunctionType(span) => span,
TypeOrigin::StartFunctionType(span) => span,
Expand Down
Loading

0 comments on commit 3fba503

Please sign in to comment.