Browse Source

update original

pull/706/head
funkill2 4 years ago
parent
commit
30a67b8e57
  1. 4
      rustbook-en/.github/workflows/main.yml
  2. 29
      rustbook-en/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
  3. 2
      rustbook-en/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt
  4. 19
      rustbook-en/listings/ch09-error-handling/listing-09-10/output.txt
  5. 5
      rustbook-en/listings/ch19-advanced-features/listing-19-20/output.txt
  6. 9
      rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt
  7. 2001
      rustbook-en/nostarch/chapter15.md
  8. 2
      rustbook-en/rust-toolchain
  9. 16
      rustbook-en/src/ch15-02-deref.md
  10. 5
      rustbook-en/src/ch15-04-rc.md
  11. 2
      rustbook-en/src/title-page.md

4
rustbook-en/.github/workflows/main.yml

@ -12,8 +12,8 @@ jobs: @@ -12,8 +12,8 @@ jobs:
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.57 -c rust-docs
rustup default 1.57
rustup toolchain install 1.58 -c rust-docs
rustup default 1.58
- name: Install mdbook
run: |
mkdir bin

29
rustbook-en/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt

@ -16,5 +16,30 @@ error[E0308]: mismatched types @@ -16,5 +16,30 @@ error[E0308]: mismatched types
= note: expected reference `&String`
found reference `&{integer}`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `guessing_game` due to previous error
error[E0283]: type annotations needed for `{integer}`
--> src/main.rs:8:44
|
8 | let secret_number = rand::thread_rng().gen_range(1..101);
| ------------- ^^^^^^^^^ cannot infer type for type `{integer}`
| |
| consider giving `secret_number` a type
|
= note: multiple `impl`s satisfying `{integer}: SampleUniform` found in the `rand` crate:
- impl SampleUniform for i128;
- impl SampleUniform for i16;
- impl SampleUniform for i32;
- impl SampleUniform for i64;
and 8 more
note: required by a bound in `gen_range`
--> /Users/carolnichols/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.3/src/rng.rs:129:12
|
129 | T: SampleUniform,
| ^^^^^^^^^^^^^ required by this bound in `gen_range`
help: consider specifying the type arguments in the function call
|
8 | let secret_number = rand::thread_rng().gen_range::<T, R>(1..101);
| ++++++++
Some errors have detailed explanations: E0283, E0308.
For more information about an error, try `rustc --explain E0283`.
error: could not compile `guessing_game` due to 2 previous errors

2
rustbook-en/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt

@ -3,6 +3,8 @@ $ cargo run @@ -3,6 +3,8 @@ $ cargo run
error[E0308]: mismatched types
--> src/main.rs:3:14
|
2 | let mut spaces = " ";
| ----- expected due to this value
3 | spaces = spaces.len();
| ^^^^^^^^^^^^ expected `&str`, found `usize`

19
rustbook-en/listings/ch09-error-handling/listing-09-10/output.txt

@ -1,16 +1,15 @@ @@ -1,16 +1,15 @@
$ cargo run
Compiling error-handling v0.1.0 (file:///projects/error-handling)
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> src/main.rs:4:36
|
3 | / fn main() {
4 | | let f = File::open("hello.txt")?;
| | ^ cannot use the `?` operator in a function that returns `()`
5 | | }
| |_- this function should return `Result` or `Option` to accept `?`
|
= help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
note: required by `from_residual`
--> src/main.rs:4:36
|
3 | / fn main() {
4 | | let f = File::open("hello.txt")?;
| | ^ cannot use the `?` operator in a function that returns `()`
5 | | }
| |_- this function should return `Result` or `Option` to accept `?`
|
= help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `error-handling` due to previous error

5
rustbook-en/listings/ch19-advanced-features/listing-19-20/output.txt

@ -7,11 +7,6 @@ error[E0283]: type annotations needed @@ -7,11 +7,6 @@ error[E0283]: type annotations needed
| ^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot satisfy `_: Animal`
note: required by `Animal::baby_name`
--> src/main.rs:2:5
|
2 | fn baby_name() -> String;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0283`.
error: could not compile `traits-example` due to previous error

9
rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt

@ -10,13 +10,14 @@ error[E0308]: mismatched types @@ -10,13 +10,14 @@ error[E0308]: mismatched types
--> src/lib.rs:72:22
|
72 | Worker { id, thread }
| ^^^^^^
| |
| expected enum `Option`, found struct `JoinHandle`
| help: try using a variant of the expected enum: `Some(thread)`
| ^^^^^^ expected enum `Option`, found struct `JoinHandle`
|
= note: expected enum `Option<JoinHandle<()>>`
found struct `JoinHandle<_>`
help: try wrapping the expression in `Some`
|
72 | Worker { id, Some(thread) }
| +++++ +
Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.

2001
rustbook-en/nostarch/chapter15.md

File diff suppressed because it is too large Load Diff

2
rustbook-en/rust-toolchain

@ -1 +1 @@ @@ -1 +1 @@
1.57
1.58

16
rustbook-en/src/ch15-02-deref.md

@ -67,7 +67,7 @@ reference; the dereference operator will work as shown in Listing 15-7: @@ -67,7 +67,7 @@ reference; the dereference operator will work as shown in Listing 15-7:
<span class="caption">Listing 15-7: Using the dereference operator on a
`Box<i32>`</span>
The only difference between Listing 15-7 and Listing 15-6 is that here we set
The main difference between Listing 15-7 and Listing 15-6 is that here we set
`y` to be an instance of a box pointing to a copied value of `x` rather than a
reference pointing to the value of `x`. In the last assertion, we can use the
dereference operator to follow the box’s pointer in the same way that we did
@ -124,7 +124,8 @@ implement the `Deref` trait. @@ -124,7 +124,8 @@ implement the `Deref` trait.
### Treating a Type Like a Reference by Implementing the `Deref` Trait
As discussed in Chapter 10, to implement a trait, we need to provide
As discussed in the [“Implementing a Trait on a Type”][impl-trait]<!-- ignore
--> section of Chapter 10, to implement a trait, we need to provide
implementations for the trait’s required methods. The `Deref` trait, provided
by the standard library, requires us to implement one method named `deref` that
borrows `self` and returns a reference to the inner data. Listing 15-10
@ -144,9 +145,11 @@ parameter, but you don’t need to worry about them for now; we’ll cover them @@ -144,9 +145,11 @@ parameter, but you don’t need to worry about them for now; we’ll cover them
more detail in Chapter 19.
We fill in the body of the `deref` method with `&self.0` so `deref` returns a
reference to the value we want to access with the `*` operator. The `main`
function in Listing 15-9 that calls `*` on the `MyBox<T>` value now compiles,
and the assertions pass!
reference to the value we want to access with the `*` operator. Recall from the
[“Using Tuple Structs without Named Fields to Create Different
Types”][tuple-structs]<!-- ignore --> section of Chapter 5 that `.0` accesses
the first value in a tuple struct. The `main` function in Listing 15-9 that
calls `*` on the `MyBox<T>` value now compiles, and the assertions pass!
Without the `Deref` trait, the compiler can only dereference `&` references.
The `deref` method gives the compiler the ability to take a value of any type
@ -285,3 +288,6 @@ initial immutable reference is the only immutable reference to that data, but @@ -285,3 +288,6 @@ initial immutable reference is the only immutable reference to that data, but
the borrowing rules don’t guarantee that. Therefore, Rust can’t make the
assumption that converting an immutable reference to a mutable reference is
possible.
[impl-trait]: ch10-02-traits.html#implementing-a-trait-on-a-type
[tuple-structs]: ch05-01-defining-structs.html#using-tuple-structs-without-named-fields-to-create-different-types

5
rustbook-en/src/ch15-04-rc.md

@ -70,9 +70,8 @@ creating `c`, we’re not allowed to because `a` has been moved. @@ -70,9 +70,8 @@ creating `c`, we’re not allowed to because `a` has been moved.
We could change the definition of `Cons` to hold references instead, but then
we would have to specify lifetime parameters. By specifying lifetime
parameters, we would be specifying that every element in the list will live at
least as long as the entire list. The borrow checker wouldn’t let us compile
`let a = Cons(10, &Nil);` for example, because the temporary `Nil` value would
be dropped before `a` could take a reference to it.
least as long as the entire list. This is the case for the elements and lists
in Listing 15-17, but not in every scenario.
Instead, we’ll change our definition of `List` to use `Rc<T>` in place of
`Box<T>`, as shown in Listing 15-18. Each `Cons` variant will now hold a value

2
rustbook-en/src/title-page.md

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
*by Steve Klabnik and Carol Nichols, with contributions from the Rust Community*
This version of the text assumes you’re using Rust 1.57 (released 2021-12-02)
This version of the text assumes you’re using Rust 1.58 (released 2022-01-13)
or later. See the [“Installation” section of Chapter 1][install]<!-- ignore -->
to install or update Rust.

Loading…
Cancel
Save