diff --git a/src/doc/reference.md b/src/doc/reference.md index 284fcf6aed0c2..70e3145903fbf 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1452,7 +1452,7 @@ fn draw_twice(surface: Surface, sh: T) { } ``` -Traits also define an [trait object](#trait-objects) with the same +Traits also define a [trait object](#trait-objects) with the same name as the trait. Values of this type are created by coercing from a pointer of some specific type to a pointer of trait type. For example, `&T` could be coerced to `&Shape` if `T: Shape` holds (and similarly diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md index 8dd5a3650ef52..518e65f35c008 100644 --- a/src/doc/trpl/error-handling.md +++ b/src/doc/trpl/error-handling.md @@ -208,8 +208,8 @@ Because these kinds of situations are relatively rare, use panics sparingly. In certain circumstances, even though a function may fail, we may want to treat it as a panic instead. For example, `io::stdin().read_line(&mut buffer)` returns -a `Result`, when there is an error reading the line. This allows us to -handle and possibly recover from error. +a `Result`, which can indicate an error if one occurs when reading the line. +This allows us to handle and possibly recover from errors. If we don't want to handle this error, and would rather just abort the program, we can use the `unwrap()` method: diff --git a/src/doc/trpl/testing.md b/src/doc/trpl/testing.md index cbf33febf876f..78803afd5c1ad 100644 --- a/src/doc/trpl/testing.md +++ b/src/doc/trpl/testing.md @@ -219,6 +219,66 @@ fn it_works() { This is a very common use of `assert_eq!`: call some function with some known arguments and compare it to the expected output. +# The `ignore` attribute + +Sometimes a few specific tests can be very time-consuming to execute. These +can be disabled by default by using the `ignore` attribute: + +```rust +#[test] +fn it_works() { + assert_eq!(4, add_two(2)); +} + +#[test] +#[ignore] +fn expensive_test() { + // code that takes an hour to run +} +``` + +Now we run our tests and see that `it_works` is run, but `expensive_test` is +not: + +```bash +$ cargo test + Compiling adder v0.0.1 (file:///home/you/projects/adder) + Running target/adder-91b3e234d4ed382a + +running 2 tests +test expensive_test ... ignored +test it_works ... ok + +test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured +``` + +The expensive tests can be run explicitly using `cargo test -- --ignored`: + +```bash +$ cargo test -- --ignored + Running target/adder-91b3e234d4ed382a + +running 1 test +test expensive_test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + + Doc-tests adder + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured +``` + +The `--ignored` argument is an argument to the test binary, and not to cargo, +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 diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index baa9750d311aa..5f907c6cbeee8 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -731,9 +731,14 @@ type X = u32; // ok! "##, E0133: r##" -Using unsafe functionality, such as dereferencing raw pointers and calling -functions via FFI or marked as unsafe, is potentially dangerous and disallowed -by safety checks. These safety checks can be relaxed for a section of the code +Using unsafe functionality, is potentially dangerous and disallowed +by safety checks. Examples: + +- Dereferencing raw pointers +- Calling functions via FFI +- Calling functions marked unsafe + +These safety checks can be relaxed for a section of the code by wrapping the unsafe instructions with an `unsafe` block. For instance: ``` @@ -831,9 +836,7 @@ is a size mismatch in one of the impls. It is also possible to manually transmute: ``` -let result: SomeType = mem::uninitialized(); -unsafe { copy_nonoverlapping(&v, &result) }; -result // `v` transmuted to type `SomeType` +ptr::read(&v as *const _ as *const SomeType) // `v` transmuted to `SomeType` ``` "##,