diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 65574a070e..ec1ab4b08a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.67 -c rust-docs - rustup default 1.67 + rustup toolchain install 1.76 -c rust-docs + rustup default 1.76 - name: Install mdbook run: | mkdir bin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a58ea42038..a20cb58501 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,4 +70,4 @@ a new language! We're waiting on [mdbook support] for multiple languages before we merge any in, but feel free to start! [Translations]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations -[mdbook support]: https://github.com/rust-lang-nursery/mdBook/issues/5 +[mdbook support]: https://github.com/rust-lang/mdBook/issues/5 diff --git a/Cargo.lock b/Cargo.lock index d0bbf7586c..5e9f838fe1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,18 +101,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -167,18 +167,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.137" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.137" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", @@ -193,9 +193,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.96" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ "proc-macro2", "quote", diff --git a/README.md b/README.md index f6341efc9c..8befc1b31e 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,11 @@ See the [releases] to download just the code of all the code listings that appea Building the book requires [mdBook], ideally the same version that rust-lang/rust uses in [this file][rust-mdbook]. To get it: -[mdBook]: https://github.com/rust-lang-nursery/mdBook +[mdBook]: https://github.com/rust-lang/mdBook [rust-mdbook]: https://github.com/rust-lang/rust/blob/master/src/tools/rustbook/Cargo.toml ```bash -$ cargo install mdbook --version +$ cargo install mdbook --locked --version ``` ## Building @@ -93,13 +93,13 @@ a new language! We're waiting on [mdbook support] for multiple languages before we merge any in, but feel free to start! [Translations]: https://github.com/rust-lang/book/issues?q=is%3Aopen+is%3Aissue+label%3ATranslations -[mdbook support]: https://github.com/rust-lang-nursery/mdBook/issues/5 +[mdbook support]: https://github.com/rust-lang/mdBook/issues/5 ## Spellchecking To scan source files for spelling errors, you can use the `spellcheck.sh` script available in the `ci` directory. It needs a dictionary of valid words, which is provided in `ci/dictionary.txt`. If the script produces a false -positive (say, you used word `BTreeMap` which the script considers invalid), +positive (say, you used the word `BTreeMap` which the script considers invalid), you need to add this word to `ci/dictionary.txt` (keep the sorted order for consistency). diff --git a/ci/dictionary.txt b/ci/dictionary.txt index a91df4a036..013d38dcc3 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -35,6 +35,7 @@ backtraces BACKTRACE Backtraces Baz's +beefeb benchmarking bioinformatics bitand diff --git a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock index edc20385bd..0fb52b33cb 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock +++ b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock @@ -10,9 +10,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -28,15 +28,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.127" +version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "rand" @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] diff --git a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index 3640c06946..9ae3a32d0c 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -11,14 +11,14 @@ error[E0308]: mismatched types --> src/main.rs:22:21 | 22 | match guess.cmp(&secret_number) { - | --- ^^^^^^^^^^^^^^ expected struct `String`, found integer + | --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}` | | - | arguments to this function are incorrect + | arguments to this method are incorrect | = note: expected reference `&String` found reference `&{integer}` -note: associated function defined here - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/cmp.rs:783:8 +note: method defined here + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/cmp.rs:814:8 For more information about this error, try `rustc --explain E0308`. -error: could not compile `guessing_game` due to previous error +error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error diff --git a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt index 9517af95f0..c7ce1c5256 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-02-without-expect/output.txt @@ -8,6 +8,10 @@ warning: unused `Result` that must be used | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +10 | let _ = io::stdin().read_line(&mut guess); + | +++++++ warning: `guessing_game` (bin "guessing_game") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.59s diff --git a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt index ed87cb2c87..73ca9d62fb 100644 --- a/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt @@ -13,4 +13,4 @@ error[E0384]: cannot assign twice to immutable variable `x` | ^^^^^ cannot assign twice to immutable variable For more information about this error, try `rustc --explain E0384`. -error: could not compile `variables` due to previous error +error: could not compile `variables` (bin "variables") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt index 31a07efc4b..2ddd39ff6e 100644 --- a/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt @@ -7,6 +7,12 @@ error[E0308]: mismatched types | ----- expected due to this value 3 | spaces = spaces.len(); | ^^^^^^^^^^^^ expected `&str`, found `usize` + | +help: try removing the method call + | +3 - spaces = spaces.len(); +3 + spaces = spaces; + | For more information about this error, try `rustc --explain E0308`. -error: could not compile `variables` due to previous error +error: could not compile `variables` (bin "variables") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt index 6ae56e09dc..504fdd6ec7 100644 --- a/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-19-statements-vs-expressions/output.txt @@ -5,22 +5,8 @@ error: expected expression, found `let` statement | 2 | let x = (let y = 6); | ^^^ - -error: expected expression, found statement (`let`) - --> src/main.rs:2:14 - | -2 | let x = (let y = 6); - | ^^^^^^^^^ - | - = note: variable declaration using `let` is a statement - -error[E0658]: `let` expressions in this position are unstable - --> src/main.rs:2:14 - | -2 | let x = (let y = 6); - | ^^^^^^^^^ | - = note: see issue #53667 for more information + = note: only supported directly in conditions of `if` and `while` expressions warning: unnecessary parentheses around assigned value --> src/main.rs:2:13 @@ -35,6 +21,5 @@ help: remove these parentheses 2 + let x = let y = 6; | -For more information about this error, try `rustc --explain E0658`. warning: `functions` (bin "functions") generated 1 warning -error: could not compile `functions` due to 3 previous errors; 1 warning emitted +error: could not compile `functions` (bin "functions") due to 1 previous error; 1 warning emitted diff --git a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt index d27a7fae28..18fdfd1b41 100644 --- a/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-23-statements-dont-return-values/output.txt @@ -11,4 +11,4 @@ error[E0308]: mismatched types | - help: remove this semicolon to return this value For more information about this error, try `rustc --explain E0308`. -error: could not compile `functions` due to previous error +error: could not compile `functions` (bin "functions") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt index 735bfe758e..c9c0b0c469 100644 --- a/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-28-if-condition-must-be-bool/output.txt @@ -7,4 +7,4 @@ error[E0308]: mismatched types | ^^^^^^ expected `bool`, found integer For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` due to previous error +error: could not compile `branches` (bin "branches") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt index e922acd29c..7fb857f035 100644 --- a/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt +++ b/listings/ch03-common-programming-concepts/no-listing-31-arms-must-return-same-type/output.txt @@ -9,4 +9,4 @@ error[E0308]: `if` and `else` have incompatible types | expected because of this For more information about this error, try `rustc --explain E0308`. -error: could not compile `branches` due to previous error +error: could not compile `branches` (bin "branches") due to 1 previous error diff --git a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt index 8a11cccd51..ee6a979432 100644 --- a/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt +++ b/listings/ch03-common-programming-concepts/output-only-01-no-type-annotations/output.txt @@ -1,15 +1,16 @@ $ cargo build Compiling no_type_annotations v0.1.0 (file:///projects/no_type_annotations) -error[E0282]: type annotations needed +error[E0284]: type annotations needed --> src/main.rs:2:9 | 2 | let guess = "42".parse().expect("Not a number!"); - | ^^^^^ + | ^^^^^ ----- type must be known at this point | + = note: cannot satisfy `<_ as FromStr>::Err == _` help: consider giving `guess` an explicit type | -2 | let guess: _ = "42".parse().expect("Not a number!"); - | +++ +2 | let guess: /* Type */ = "42".parse().expect("Not a number!"); + | ++++++++++++ -For more information about this error, try `rustc --explain E0282`. -error: could not compile `no_type_annotations` due to previous error +For more information about this error, try `rustc --explain E0284`. +error: could not compile `no_type_annotations` (bin "no_type_annotations") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/listing-04-06/output.txt b/listings/ch04-understanding-ownership/listing-04-06/output.txt index 1176f4e3ac..c78cd5d3de 100644 --- a/listings/ch04-understanding-ownership/listing-04-06/output.txt +++ b/listings/ch04-understanding-ownership/listing-04-06/output.txt @@ -3,10 +3,13 @@ $ cargo run error[E0596]: cannot borrow `*some_string` as mutable, as it is behind a `&` reference --> src/main.rs:8:5 | -7 | fn change(some_string: &String) { - | ------- help: consider changing this to be a mutable reference: `&mut String` 8 | some_string.push_str(", world"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^ `some_string` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +7 | fn change(some_string: &mut String) { + | +++ For more information about this error, try `rustc --explain E0596`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt index 4a53567018..8f9e017980 100644 --- a/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-04-cant-use-after-move/output.txt @@ -18,4 +18,4 @@ help: consider cloning the value if the performance cost is acceptable | ++++++++ For more information about this error, try `rustc --explain E0382`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt b/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt index 8820d2d695..97be4a2586 100644 --- a/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-10-multiple-mut-not-allowed/output.txt @@ -12,4 +12,4 @@ error[E0499]: cannot borrow `s` as mutable more than once at a time | -- first borrow later used here For more information about this error, try `rustc --explain E0499`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt b/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt index d1e9db2c4b..4548823230 100644 --- a/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-12-immutable-and-mutable-not-allowed/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta | -- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt index b466a3dce5..70e58af8b5 100644 --- a/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-14-dangling-reference/output.txt @@ -7,10 +7,15 @@ error[E0106]: missing lifetime specifier | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from -help: consider using the `'static` lifetime +help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | 5 | fn dangle() -> &'static String { | +++++++ +help: instead, you are more likely to want to return an owned value + | +5 - fn dangle() -> &String { +5 + fn dangle() -> String { + | For more information about this error, try `rustc --explain E0106`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt index ab0c41f4df..be05d65283 100644 --- a/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt +++ b/listings/ch04-understanding-ownership/no-listing-19-slice-error/output.txt @@ -13,4 +13,4 @@ error[E0502]: cannot borrow `s` as mutable because it is also borrowed as immuta | ---- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `ownership` due to previous error +error: could not compile `ownership` (bin "ownership") due to 1 previous error diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt b/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt index 7d3bfcdac4..ee169726d0 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-11/output.txt @@ -11,4 +11,4 @@ error[E0277]: `Rectangle` doesn't implement `std::fmt::Display` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. -error: could not compile `rectangles` due to previous error +error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt b/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt index e28da599c7..5f9344c512 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt @@ -28,4 +28,4 @@ help: consider introducing a named lifetime parameter | For more information about this error, try `rustc --explain E0106`. -error: could not compile `structs` due to 2 previous errors +error: could not compile `structs` (bin "structs") due to 2 previous errors diff --git a/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt b/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt index 2685859954..bfb88ebee6 100644 --- a/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/no-listing-05-dbg-macro/output.txt @@ -2,8 +2,8 @@ $ cargo run Compiling rectangles v0.1.0 (file:///projects/rectangles) Finished dev [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/rectangles` -[src/main.rs:10] 30 * scale = 60 -[src/main.rs:14] &rect1 = Rectangle { +[src/main.rs:10:16] 30 * scale = 60 +[src/main.rs:14:5] &rect1 = Rectangle { width: 60, height: 50, } diff --git a/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt b/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt index 58cb842bfa..71de1f7bd3 100644 --- a/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt +++ b/listings/ch05-using-structs-to-structure-related-data/output-only-01-debug/output.txt @@ -11,8 +11,9 @@ error[E0277]: `Rectangle` doesn't implement `Debug` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `Rectangle` with `#[derive(Debug)]` | -1 | #[derive(Debug)] +1 + #[derive(Debug)] +2 | struct Rectangle { | For more information about this error, try `rustc --explain E0277`. -error: could not compile `rectangles` due to previous error +error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index a16dc01807..fa202e6212 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt @@ -8,10 +8,10 @@ error[E0277]: cannot add `Option` to `i8` | = help: the trait `Add>` is not implemented for `i8` = help: the following other types implement trait `Add`: + + > <&'a i8 as Add> <&i8 as Add<&i8>> - > - For more information about this error, try `rustc --explain E0277`. -error: could not compile `enums` due to previous error +error: could not compile `enums` (bin "enums") due to 1 previous error diff --git a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 75d056f843..4ec05abf05 100644 --- a/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,10 +7,10 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:518:1 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:570:1 + ::: /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/option.rs:574:5 | - = note: -/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:522:5: not covered + = note: not covered = note: the matched value is of type `Option` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | @@ -19,4 +19,4 @@ help: ensure that all possible cases are being handled by adding a match arm wit | For more information about this error, try `rustc --explain E0004`. -error: could not compile `enums` due to previous error +error: could not compile `enums` (bin "enums") due to 1 previous error diff --git a/listings/ch07-managing-growing-projects/listing-07-03/output.txt b/listings/ch07-managing-growing-projects/listing-07-03/output.txt index 481dcb3f74..2d06c7fd15 100644 --- a/listings/ch07-managing-growing-projects/listing-07-03/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-03/output.txt @@ -4,7 +4,9 @@ error[E0603]: module `hosting` is private --> src/lib.rs:9:28 | 9 | crate::front_of_house::hosting::add_to_waitlist(); - | ^^^^^^^ private module + | ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported + | | + | private module | note: the module `hosting` is defined here --> src/lib.rs:2:5 @@ -16,7 +18,9 @@ error[E0603]: module `hosting` is private --> src/lib.rs:12:21 | 12 | front_of_house::hosting::add_to_waitlist(); - | ^^^^^^^ private module + | ^^^^^^^ --------------- function `add_to_waitlist` is not publicly re-exported + | | + | private module | note: the module `hosting` is defined here --> src/lib.rs:2:5 @@ -25,4 +29,4 @@ note: the module `hosting` is defined here | ^^^^^^^^^^^ For more information about this error, try `rustc --explain E0603`. -error: could not compile `restaurant` due to 2 previous errors +error: could not compile `restaurant` (lib) due to 2 previous errors diff --git a/listings/ch07-managing-growing-projects/listing-07-05/output.txt b/listings/ch07-managing-growing-projects/listing-07-05/output.txt index 63eb89a146..98d8d6e2aa 100644 --- a/listings/ch07-managing-growing-projects/listing-07-05/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-05/output.txt @@ -25,4 +25,4 @@ note: the function `add_to_waitlist` is defined here | ^^^^^^^^^^^^^^^^^^^^ For more information about this error, try `rustc --explain E0603`. -error: could not compile `restaurant` due to 2 previous errors +error: could not compile `restaurant` (lib) due to 2 previous errors diff --git a/listings/ch07-managing-growing-projects/listing-07-12/output.txt b/listings/ch07-managing-growing-projects/listing-07-12/output.txt index 1bc89bf322..0eda253125 100644 --- a/listings/ch07-managing-growing-projects/listing-07-12/output.txt +++ b/listings/ch07-managing-growing-projects/listing-07-12/output.txt @@ -1,5 +1,16 @@ $ cargo build Compiling restaurant v0.1.0 (file:///projects/restaurant) +error[E0433]: failed to resolve: use of undeclared crate or module `hosting` + --> src/lib.rs:11:9 + | +11 | hosting::add_to_waitlist(); + | ^^^^^^^ use of undeclared crate or module `hosting` + | +help: consider importing this module through its public re-export + | +10 + use crate::hosting; + | + warning: unused import: `crate::front_of_house::hosting` --> src/lib.rs:7:5 | @@ -8,12 +19,6 @@ warning: unused import: `crate::front_of_house::hosting` | = note: `#[warn(unused_imports)]` on by default -error[E0433]: failed to resolve: use of undeclared crate or module `hosting` - --> src/lib.rs:11:9 - | -11 | hosting::add_to_waitlist(); - | ^^^^^^^ use of undeclared crate or module `hosting` - For more information about this error, try `rustc --explain E0433`. warning: `restaurant` (lib) generated 1 warning -error: could not compile `restaurant` due to previous error; 1 warning emitted +error: could not compile `restaurant` (lib) due to 1 previous error; 1 warning emitted diff --git a/listings/ch08-common-collections/listing-08-06/output.txt b/listings/ch08-common-collections/listing-08-06/output.txt index 3104205f30..f98ab1cde7 100644 --- a/listings/ch08-common-collections/listing-08-06/output.txt +++ b/listings/ch08-common-collections/listing-08-06/output.txt @@ -10,7 +10,7 @@ error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immuta | ^^^^^^^^^ mutable borrow occurs here 7 | 8 | println!("The first element is: {first}"); - | ----- immutable borrow later used here + | ------- immutable borrow later used here For more information about this error, try `rustc --explain E0502`. -error: could not compile `collections` due to previous error +error: could not compile `collections` (bin "collections") due to 1 previous error diff --git a/listings/ch08-common-collections/listing-08-14/src/main.rs b/listings/ch08-common-collections/listing-08-14/src/main.rs index f701fd578b..bf737ab446 100644 --- a/listings/ch08-common-collections/listing-08-14/src/main.rs +++ b/listings/ch08-common-collections/listing-08-14/src/main.rs @@ -3,7 +3,7 @@ fn main() { let hello = String::from("السلام عليكم"); let hello = String::from("Dobrý den"); let hello = String::from("Hello"); - let hello = String::from("שָׁלוֹם"); + let hello = String::from("שלום"); let hello = String::from("नमस्ते"); let hello = String::from("こんにちは"); let hello = String::from("안녕하세요"); diff --git a/listings/ch08-common-collections/listing-08-19/output.txt b/listings/ch08-common-collections/listing-08-19/output.txt index 3a682457c6..de20b73edf 100644 --- a/listings/ch08-common-collections/listing-08-19/output.txt +++ b/listings/ch08-common-collections/listing-08-19/output.txt @@ -1,19 +1,19 @@ $ cargo run Compiling collections v0.1.0 (file:///projects/collections) error[E0277]: the type `String` cannot be indexed by `{integer}` - --> src/main.rs:3:13 + --> src/main.rs:3:16 | 3 | let h = s1[0]; - | ^^^^^ `String` cannot be indexed by `{integer}` + | ^ `String` cannot be indexed by `{integer}` | = help: the trait `Index<{integer}>` is not implemented for `String` = help: the following other types implement trait `Index`: - >> > - >> + >> + >> >> + >> >> - >> For more information about this error, try `rustc --explain E0277`. -error: could not compile `collections` due to previous error +error: could not compile `collections` (bin "collections") due to 1 previous error diff --git a/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt b/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt index 35db879c9b..855d6d2f6a 100644 --- a/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt +++ b/listings/ch08-common-collections/output-only-01-not-char-boundary/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling collections v0.1.0 (file:///projects/collections) Finished dev [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/collections` -thread 'main' panicked at 'byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте`', src/main.rs:4:14 +thread 'main' panicked at src/main.rs:4:19: +byte index 1 is not a char boundary; it is inside 'З' (bytes 0..2) of `Здравствуйте` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch09-error-handling/listing-09-01/output.txt b/listings/ch09-error-handling/listing-09-01/output.txt index 89aebb952f..225958320c 100644 --- a/listings/ch09-error-handling/listing-09-01/output.txt +++ b/listings/ch09-error-handling/listing-09-01/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling panic v0.1.0 (file:///projects/panic) Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/panic` -thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5 +thread 'main' panicked at src/main.rs:4:6: +index out of bounds: the len is 3 but the index is 99 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch09-error-handling/listing-09-04/output.txt b/listings/ch09-error-handling/listing-09-04/output.txt index f776a591ce..cc135c9fa6 100644 --- a/listings/ch09-error-handling/listing-09-04/output.txt +++ b/listings/ch09-error-handling/listing-09-04/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling error-handling v0.1.0 (file:///projects/error-handling) Finished dev [unoptimized + debuginfo] target(s) in 0.73s Running `target/debug/error-handling` -thread 'main' panicked at 'Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:8:23 +thread 'main' panicked at src/main.rs:8:23: +Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch09-error-handling/listing-09-10/output.txt b/listings/ch09-error-handling/listing-09-10/output.txt index 75b9cf2e33..dbc9bb13dc 100644 --- a/listings/ch09-error-handling/listing-09-10/output.txt +++ b/listings/ch09-error-handling/listing-09-10/output.txt @@ -11,4 +11,4 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu = help: the trait `FromResidual>` is not implemented for `()` For more information about this error, try `rustc --explain E0277`. -error: could not compile `error-handling` due to previous error +error: could not compile `error-handling` (bin "error-handling") due to 1 previous error diff --git a/listings/ch09-error-handling/no-listing-01-panic/output.txt b/listings/ch09-error-handling/no-listing-01-panic/output.txt index b25ed85d7c..d90e37e30e 100644 --- a/listings/ch09-error-handling/no-listing-01-panic/output.txt +++ b/listings/ch09-error-handling/no-listing-01-panic/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling panic v0.1.0 (file:///projects/panic) Finished dev [unoptimized + debuginfo] target(s) in 0.25s Running `target/debug/panic` -thread 'main' panicked at 'crash and burn', src/main.rs:2:5 +thread 'main' panicked at src/main.rs:2:5: +crash and burn note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt index 1a705ed570..05b96ca173 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-05/output.txt @@ -14,4 +14,4 @@ help: consider restricting type parameter `T` | ++++++++++++++++++++++ For more information about this error, try `rustc --explain E0369`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt index 2482c38432..5f6c3f4657 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-07/output.txt @@ -7,4 +7,4 @@ error[E0308]: mismatched types | ^^^ expected integer, found floating-point number For more information about this error, try `rustc --explain E0308`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt index ad73272099..6afb5b0c2a 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-16/output.txt @@ -3,6 +3,8 @@ $ cargo run error[E0597]: `x` does not live long enough --> src/main.rs:6:13 | +5 | let x = 5; + | - binding `x` declared here 6 | r = &x; | ^^ borrowed value does not live long enough 7 | } @@ -12,4 +14,4 @@ error[E0597]: `x` does not live long enough | - borrow later used here For more information about this error, try `rustc --explain E0597`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt index 534a984a63..a6783b2ccd 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-20/output.txt @@ -13,4 +13,4 @@ help: consider introducing a named lifetime parameter | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt index 0cf373f8a4..63d1668cae 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/listing-10-23/output.txt @@ -3,12 +3,14 @@ $ cargo run error[E0597]: `string2` does not live long enough --> src/main.rs:6:44 | +5 | let string2 = String::from("xyz"); + | ------- binding `string2` declared here 6 | result = longest(string1.as_str(), string2.as_str()); - | ^^^^^^^^^^^^^^^^ borrowed value does not live long enough + | ^^^^^^^ borrowed value does not live long enough 7 | } | - `string2` dropped here while still borrowed 8 | println!("The longest string is {result}"); | ------ borrow later used here For more information about this error, try `rustc --explain E0597`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt index 0c628b6977..9b9ef2338c 100644 --- a/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt +++ b/listings/ch10-generic-types-traits-and-lifetimes/no-listing-09-unrelated-lifetime/output.txt @@ -1,10 +1,13 @@ $ cargo run Compiling chapter10 v0.1.0 (file:///projects/chapter10) -error[E0515]: cannot return reference to local variable `result` +error[E0515]: cannot return value referencing local variable `result` --> src/main.rs:11:5 | 11 | result.as_str() - | ^^^^^^^^^^^^^^^ returns a reference to data owned by the current function + | ------^^^^^^^^^ + | | + | returns a value referencing data owned by the current function + | `result` is borrowed here For more information about this error, try `rustc --explain E0515`. -error: could not compile `chapter10` due to previous error +error: could not compile `chapter10` (bin "chapter10") due to 1 previous error diff --git a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs index 1b4a90c938..7d12d9af81 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-01/src/lib.rs @@ -1,8 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/listing-11-03/output.txt b/listings/ch11-writing-automated-tests/listing-11-03/output.txt index e8c31e79ec..1947556912 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-03/output.txt @@ -10,7 +10,8 @@ test tests::exploration ... ok failures: ---- tests::another stdout ---- -thread 'tests::another' panicked at 'Make this test fail', src/lib.rs:10:9 +thread 'tests::another' panicked at src/lib.rs:10:9: +Make this test fail note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs index a9ec008919..67b6552c71 100644 --- a/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-03/src/lib.rs @@ -1,11 +1,18 @@ // ANCHOR: here +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } - + #[test] fn another() { panic!("Make this test fail"); diff --git a/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs b/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs index cc1c5c35d0..1bb464137b 100644 --- a/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs +++ b/listings/ch11-writing-automated-tests/listing-11-09/src/lib.rs @@ -9,13 +9,11 @@ impl Guess { pub fn new(value: i32) -> Guess { if value < 1 { panic!( - "Guess value must be greater than or equal to 1, got {}.", - value + "Guess value must be greater than or equal to 1, got {value}." ); } else if value > 100 { panic!( - "Guess value must be less than or equal to 100, got {}.", - value + "Guess value must be less than or equal to 100, got {value}." ); } diff --git a/listings/ch11-writing-automated-tests/listing-11-10/output.txt b/listings/ch11-writing-automated-tests/listing-11-10/output.txt index b0d10deaa8..7a2b200ac2 100644 --- a/listings/ch11-writing-automated-tests/listing-11-10/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-10/output.txt @@ -11,9 +11,10 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)` - left: `5`, - right: `10`', src/lib.rs:19:9 +thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: +assertion `left == right` failed + left: 5 + right: 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs index e26fa71096..3822d6b976 100644 --- a/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs +++ b/listings/ch11-writing-automated-tests/listing-11-13/tests/integration_test.rs @@ -1,6 +1,6 @@ -use adder; +use adder::add_two; #[test] fn it_adds_two() { - assert_eq!(4, adder::add_two(2)); + assert_eq!(4, add_two(2)); } diff --git a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs index 330bddf6ac..5be58b93fc 100644 --- a/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-01-changing-test-name/src/lib.rs @@ -1,7 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn exploration() { - assert_eq!(2 + 2, 4); + let result = add(2, 2); + assert_eq!(result, 4); } } diff --git a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt index 6fbb5e4966..6e3061b9c3 100644 --- a/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-03-introducing-a-bug/output.txt @@ -10,7 +10,8 @@ test tests::smaller_cannot_hold_larger ... ok failures: ---- tests::larger_can_hold_smaller stdout ---- -thread 'tests::larger_can_hold_smaller' panicked at 'assertion failed: larger.can_hold(&smaller)', src/lib.rs:28:9 +thread 'tests::larger_can_hold_smaller' panicked at src/lib.rs:28:9: +assertion failed: larger.can_hold(&smaller) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt index 00bf63fff6..102479df6e 100644 --- a/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-04-bug-in-add-two/output.txt @@ -9,9 +9,10 @@ test tests::it_adds_two ... FAILED failures: ---- tests::it_adds_two stdout ---- -thread 'tests::it_adds_two' panicked at 'assertion failed: `(left == right)` - left: `4`, - right: `5`', src/lib.rs:11:9 +thread 'tests::it_adds_two' panicked at src/lib.rs:11:9: +assertion `left == right` failed + left: 4 + right: 5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt index 68d724f118..bbd42d04dc 100644 --- a/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-06-greeter-with-bug/output.txt @@ -9,7 +9,8 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'tests::greeting_contains_name' panicked at 'assertion failed: result.contains(\"Carol\")', src/lib.rs:12:9 +thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: +assertion failed: result.contains("Carol") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt index 03d6ad7f13..e6cc739c41 100644 --- a/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-07-custom-failure-message/output.txt @@ -9,7 +9,8 @@ test tests::greeting_contains_name ... FAILED failures: ---- tests::greeting_contains_name stdout ---- -thread 'tests::greeting_contains_name' panicked at 'Greeting did not contain name, value was `Hello!`', src/lib.rs:12:9 +thread 'tests::greeting_contains_name' panicked at src/lib.rs:12:9: +Greeting did not contain name, value was `Hello!` note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt index 0b045e8be9..6e80336e5e 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/output.txt @@ -9,7 +9,8 @@ test tests::greater_than_100 - should panic ... FAILED failures: ---- tests::greater_than_100 stdout ---- -thread 'tests::greater_than_100' panicked at 'Guess value must be greater than or equal to 1, got 200.', src/lib.rs:13:13 +thread 'tests::greater_than_100' panicked at src/lib.rs:13:13: +Guess value must be greater than or equal to 1, got 200. note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: panic did not contain expected string panic message: `"Guess value must be greater than or equal to 1, got 200."`, diff --git a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs index 7703dd75ae..fb5fc0e77b 100644 --- a/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs +++ b/listings/ch11-writing-automated-tests/no-listing-09-guess-with-panic-msg-bug/src/lib.rs @@ -7,13 +7,11 @@ impl Guess { // ANCHOR: here if value < 1 { panic!( - "Guess value must be less than or equal to 100, got {}.", - value + "Guess value must be less than or equal to 100, got {value}." ); } else if value > 100 { panic!( - "Guess value must be greater than or equal to 1, got {}.", - value + "Guess value must be greater than or equal to 1, got {value}." ); } // ANCHOR_END: here diff --git a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt index bc03145a18..b8aae1fae1 100644 --- a/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt +++ b/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt @@ -20,9 +20,10 @@ failures: ---- tests::this_test_will_fail stdout ---- I got the value 8 -thread 'tests::this_test_will_fail' panicked at 'assertion failed: `(left == right)` - left: `5`, - right: `10`', src/lib.rs:19:9 +thread 'tests::this_test_will_fail' panicked at src/lib.rs:19:9: +assertion `left == right` failed + left: 5 + right: 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-01/output.txt b/listings/ch12-an-io-project/listing-12-01/output.txt index 529115f8d4..7017af1ab9 100644 --- a/listings/ch12-an-io-project/listing-12-01/output.txt +++ b/listings/ch12-an-io-project/listing-12-01/output.txt @@ -2,6 +2,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 0.61s Running `target/debug/minigrep` -[src/main.rs:5] args = [ +[src/main.rs:5:5] args = [ "target/debug/minigrep", ] diff --git a/listings/ch12-an-io-project/listing-12-07/output.txt b/listings/ch12-an-io-project/listing-12-07/output.txt index d3fa7777d5..94666c8700 100644 --- a/listings/ch12-an-io-project/listing-12-07/output.txt +++ b/listings/ch12-an-io-project/listing-12-07/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` -thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:27:21 +thread 'main' panicked at src/main.rs:27:21: +index out of bounds: the len is 1 but the index is 1 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-08/output.txt b/listings/ch12-an-io-project/listing-12-08/output.txt index de2abd1afc..6d1103e4d4 100644 --- a/listings/ch12-an-io-project/listing-12-08/output.txt +++ b/listings/ch12-an-io-project/listing-12-08/output.txt @@ -2,5 +2,6 @@ $ cargo run Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 0.0s Running `target/debug/minigrep` -thread 'main' panicked at 'not enough arguments', src/main.rs:26:13 +thread 'main' panicked at src/main.rs:26:13: +not enough arguments note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/listing-12-12/output.txt b/listings/ch12-an-io-project/listing-12-12/output.txt index 9870b21255..7cd09e8276 100644 --- a/listings/ch12-an-io-project/listing-12-12/output.txt +++ b/listings/ch12-an-io-project/listing-12-12/output.txt @@ -1,4 +1,4 @@ -$ cargo run the poem.txt +$ cargo run -- the poem.txt Compiling minigrep v0.1.0 (file:///projects/minigrep) warning: unused `Result` that must be used --> src/main.rs:19:5 @@ -8,6 +8,10 @@ warning: unused `Result` that must be used | = note: this `Result` may be an `Err` variant, which should be handled = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +19 | let _ = run(config); + | +++++++ warning: `minigrep` (bin "minigrep") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.71s diff --git a/listings/ch12-an-io-project/listing-12-16/output.txt b/listings/ch12-an-io-project/listing-12-16/output.txt index be4a97eea2..893171bc40 100644 --- a/listings/ch12-an-io-project/listing-12-16/output.txt +++ b/listings/ch12-an-io-project/listing-12-16/output.txt @@ -9,9 +9,10 @@ test tests::one_result ... FAILED failures: ---- tests::one_result stdout ---- -thread 'tests::one_result' panicked at 'assertion failed: `(left == right)` - left: `["safe, fast, productive."]`, - right: `[]`', src/lib.rs:44:9 +thread 'tests::one_result' panicked at src/lib.rs:44:9: +assertion `left == right` failed + left: ["safe, fast, productive."] + right: [] note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch12-an-io-project/output-only-01-with-args/output.txt b/listings/ch12-an-io-project/output-only-01-with-args/output.txt index b48bb0e108..ef5743967e 100644 --- a/listings/ch12-an-io-project/output-only-01-with-args/output.txt +++ b/listings/ch12-an-io-project/output-only-01-with-args/output.txt @@ -2,7 +2,7 @@ $ cargo run -- needle haystack Compiling minigrep v0.1.0 (file:///projects/minigrep) Finished dev [unoptimized + debuginfo] target(s) in 1.57s Running `target/debug/minigrep needle haystack` -[src/main.rs:5] args = [ +[src/main.rs:5:5] args = [ "target/debug/minigrep", "needle", "haystack", diff --git a/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt b/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt index 93116dd5ed..7e46576b4a 100644 --- a/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt +++ b/listings/ch12-an-io-project/output-only-02-missing-lifetimes/output.txt @@ -13,4 +13,4 @@ help: consider introducing a named lifetime parameter | ++++ ++ ++ ++ For more information about this error, try `rustc --explain E0106`. -error: could not compile `minigrep` due to previous error +error: could not compile `minigrep` (lib) due to 1 previous error diff --git a/listings/ch13-functional-features/listing-13-03/output.txt b/listings/ch13-functional-features/listing-13-03/output.txt index 68838deff0..16716c3ac1 100644 --- a/listings/ch13-functional-features/listing-13-03/output.txt +++ b/listings/ch13-functional-features/listing-13-03/output.txt @@ -6,9 +6,16 @@ error[E0308]: mismatched types 5 | let n = example_closure(5); | --------------- ^- help: try using a conversion method: `.to_string()` | | | - | | expected struct `String`, found integer + | | expected `String`, found integer | arguments to this function are incorrect | +note: expected because the closure was earlier called with an argument of type `String` + --> src/main.rs:4:29 + | +4 | let s = example_closure(String::from("hello")); + | --------------- ^^^^^^^^^^^^^^^^^^^^^ expected because this argument is of type `String` + | | + | in this closure call note: closure parameter defined here --> src/main.rs:2:28 | @@ -16,4 +23,4 @@ note: closure parameter defined here | ^ For more information about this error, try `rustc --explain E0308`. -error: could not compile `closure-example` due to previous error +error: could not compile `closure-example` (bin "closure-example") due to 1 previous error diff --git a/listings/ch13-functional-features/listing-13-08/output.txt b/listings/ch13-functional-features/listing-13-08/output.txt index a910537667..7f5ce888d6 100644 --- a/listings/ch13-functional-features/listing-13-08/output.txt +++ b/listings/ch13-functional-features/listing-13-08/output.txt @@ -3,7 +3,7 @@ $ cargo run error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure --> src/main.rs:18:30 | -15 | let value = String::from("by key called"); +15 | let value = String::from("closure called"); | ----- captured outer variable 16 | 17 | list.sort_by_key(|r| { @@ -12,4 +12,4 @@ error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` clos | ^^^^^ move occurs because `value` has type `String`, which does not implement the `Copy` trait For more information about this error, try `rustc --explain E0507`. -error: could not compile `rectangles` due to previous error +error: could not compile `rectangles` (bin "rectangles") due to 1 previous error diff --git a/listings/ch13-functional-features/listing-13-08/src/main.rs b/listings/ch13-functional-features/listing-13-08/src/main.rs index 48920d39b4..e00fec70fc 100644 --- a/listings/ch13-functional-features/listing-13-08/src/main.rs +++ b/listings/ch13-functional-features/listing-13-08/src/main.rs @@ -12,7 +12,7 @@ fn main() { ]; let mut sort_operations = vec![]; - let value = String::from("by key called"); + let value = String::from("closure called"); list.sort_by_key(|r| { sort_operations.push(value); diff --git a/listings/ch13-functional-features/listing-13-14/output.txt b/listings/ch13-functional-features/listing-13-14/output.txt index 9930379910..53715015ed 100644 --- a/listings/ch13-functional-features/listing-13-14/output.txt +++ b/listings/ch13-functional-features/listing-13-14/output.txt @@ -8,6 +8,10 @@ warning: unused `Map` that must be used | = note: iterators are lazy and do nothing unless consumed = note: `#[warn(unused_must_use)]` on by default +help: use `let _ = ...` to ignore the resulting value + | +4 | let _ = v1.iter().map(|x| x + 1); + | +++++++ warning: `iterators` (bin "iterators") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 0.47s diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs index 1b4a90c938..7d12d9af81 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/src/lib.rs @@ -1,8 +1,14 @@ +pub fn add(left: usize, right: usize) -> usize { + left + right +} + #[cfg(test)] mod tests { + use super::*; + #[test] fn it_works() { - let result = 2 + 2; + let result = add(2, 2); assert_eq!(result, 4); } } diff --git a/listings/ch15-smart-pointers/listing-15-03/output.txt b/listings/ch15-smart-pointers/listing-15-03/output.txt index 04b6976fed..9e54b51938 100644 --- a/listings/ch15-smart-pointers/listing-15-03/output.txt +++ b/listings/ch15-smart-pointers/listing-15-03/output.txt @@ -14,4 +14,4 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | ++++ + For more information about this error, try `rustc --explain E0072`. -error: could not compile `cons-list` due to previous error +error: could not compile `cons-list` (bin "cons-list") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-09/output.txt b/listings/ch15-smart-pointers/listing-15-09/output.txt index 75e5f1c8c4..a295d26284 100644 --- a/listings/ch15-smart-pointers/listing-15-09/output.txt +++ b/listings/ch15-smart-pointers/listing-15-09/output.txt @@ -7,4 +7,4 @@ error[E0614]: type `MyBox<{integer}>` cannot be dereferenced | ^^ For more information about this error, try `rustc --explain E0614`. -error: could not compile `deref-example` due to previous error +error: could not compile `deref-example` (bin "deref-example") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-15/output.txt b/listings/ch15-smart-pointers/listing-15-15/output.txt index a38c9ccb76..8a53b28520 100644 --- a/listings/ch15-smart-pointers/listing-15-15/output.txt +++ b/listings/ch15-smart-pointers/listing-15-15/output.txt @@ -4,10 +4,12 @@ error[E0040]: explicit use of destructor method --> src/main.rs:16:7 | 16 | c.drop(); - | --^^^^-- - | | | - | | explicit destructor calls not allowed - | help: consider using `drop` function: `drop(c)` + | ^^^^ explicit destructor calls not allowed + | +help: consider using `drop` function + | +16 | drop(c); + | +++++ ~ For more information about this error, try `rustc --explain E0040`. -error: could not compile `drop-example` due to previous error +error: could not compile `drop-example` (bin "drop-example") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-17/output.txt b/listings/ch15-smart-pointers/listing-15-17/output.txt index ab314d8837..757a65fb54 100644 --- a/listings/ch15-smart-pointers/listing-15-17/output.txt +++ b/listings/ch15-smart-pointers/listing-15-17/output.txt @@ -11,4 +11,4 @@ error[E0382]: use of moved value: `a` | ^ value used here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `cons-list` due to previous error +error: could not compile `cons-list` (bin "cons-list") due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-21/output.txt b/listings/ch15-smart-pointers/listing-15-21/output.txt index 6b07b66ea2..3f00da3607 100644 --- a/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -3,12 +3,13 @@ $ cargo test error[E0596]: cannot borrow `self.sent_messages` as mutable, as it is behind a `&` reference --> src/lib.rs:58:13 | -2 | fn send(&self, msg: &str); - | ----- help: consider changing that to be a mutable reference: `&mut self` -... 58 | self.sent_messages.push(String::from(message)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | ^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +2 | fn send(&mut self, msg: &str); + | ~~~~~~~~~ For more information about this error, try `rustc --explain E0596`. -error: could not compile `limit-tracker` due to previous error -warning: build failed, waiting for other jobs to finish... +error: could not compile `limit-tracker` (lib test) due to 1 previous error diff --git a/listings/ch15-smart-pointers/listing-15-23/output.txt b/listings/ch15-smart-pointers/listing-15-23/output.txt index 0ffabf7650..5ad2087ed8 100644 --- a/listings/ch15-smart-pointers/listing-15-23/output.txt +++ b/listings/ch15-smart-pointers/listing-15-23/output.txt @@ -9,7 +9,8 @@ test tests::it_sends_an_over_75_percent_warning_message ... FAILED failures: ---- tests::it_sends_an_over_75_percent_warning_message stdout ---- -thread 'tests::it_sends_an_over_75_percent_warning_message' panicked at 'already borrowed: BorrowMutError', src/lib.rs:60:53 +thread 'tests::it_sends_an_over_75_percent_warning_message' panicked at src/lib.rs:60:53: +already borrowed: BorrowMutError note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace diff --git a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt index 8e84746eec..95b9b68a82 100644 --- a/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt +++ b/listings/ch15-smart-pointers/no-listing-01-cant-borrow-immutable-as-mutable/output.txt @@ -3,10 +3,13 @@ $ cargo run error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> src/main.rs:3:13 | -2 | let x = 5; - | - help: consider changing this to be mutable: `mut x` 3 | let y = &mut x; | ^^^^^^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +2 | let mut x = 5; + | +++ For more information about this error, try `rustc --explain E0596`. -error: could not compile `borrowing` due to previous error +error: could not compile `borrowing` (bin "borrowing") due to 1 previous error diff --git a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt index a03cc34e2e..c7ed502b27 100644 --- a/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt +++ b/listings/ch15-smart-pointers/output-only-01-comparing-to-reference/output.txt @@ -8,16 +8,16 @@ error[E0277]: can't compare `{integer}` with `&{integer}` | = help: the trait `PartialEq<&{integer}>` is not implemented for `{integer}` = help: the following other types implement trait `PartialEq`: - f32 - f64 - i128 + isize + i8 i16 i32 i64 - i8 - isize + i128 + usize + u8 and 6 others = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0277`. -error: could not compile `deref-example` due to previous error +error: could not compile `deref-example` (bin "deref-example") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-03/output.txt b/listings/ch16-fearless-concurrency/listing-16-03/output.txt index 3acd5ef098..3de4d4d3f2 100644 --- a/listings/ch16-fearless-concurrency/listing-16-03/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-03/output.txt @@ -22,4 +22,4 @@ help: to force the closure to take ownership of `v` (and any other referenced va | ++++ For more information about this error, try `rustc --explain E0373`. -error: could not compile `threads` due to previous error +error: could not compile `threads` (bin "threads") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-09/output.txt b/listings/ch16-fearless-concurrency/listing-16-09/output.txt index 2add0095e7..d521ebbb4b 100644 --- a/listings/ch16-fearless-concurrency/listing-16-09/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-09/output.txt @@ -11,6 +11,10 @@ error[E0382]: borrow of moved value: `val` | ^^^ value borrowed here after move | = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider cloning the value if the performance cost is acceptable + | +9 | tx.send(val.clone()).unwrap(); + | ++++++++ For more information about this error, try `rustc --explain E0382`. -error: could not compile `message-passing` due to previous error +error: could not compile `message-passing` (bin "message-passing") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-13/output.txt b/listings/ch16-fearless-concurrency/listing-16-13/output.txt index ea6963903d..5405f76bcf 100644 --- a/listings/ch16-fearless-concurrency/listing-16-13/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-13/output.txt @@ -1,15 +1,16 @@ $ cargo run Compiling shared-state v0.1.0 (file:///projects/shared-state) -error[E0382]: use of moved value: `counter` - --> src/main.rs:9:36 +error[E0382]: borrow of moved value: `counter` + --> src/main.rs:21:29 | 5 | let counter = Mutex::new(0); | ------- move occurs because `counter` has type `Mutex`, which does not implement the `Copy` trait ... 9 | let handle = thread::spawn(move || { - | ^^^^^^^ value moved into closure here, in previous iteration of loop -10 | let mut num = counter.lock().unwrap(); - | ------- use occurs due to use in closure + | ------- value moved into closure here, in previous iteration of loop +... +21 | println!("Result: {}", *counter.lock().unwrap()); + | ^^^^^^^ value borrowed here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `shared-state` due to previous error +error: could not compile `shared-state` (bin "shared-state") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/listings/ch16-fearless-concurrency/listing-16-14/output.txt index e8cf21a736..504826c1b8 100644 --- a/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -6,7 +6,7 @@ error[E0277]: `Rc>` cannot be sent between threads safely 11 | let handle = thread::spawn(move || { | ------------- ^------ | | | - | ______________________|_____________within this `[closure@src/main.rs:11:36: 11:43]` + | ______________________|_____________within this `{closure@src/main.rs:11:36: 11:43}` | | | | | required by a bound introduced by this call 12 | | let mut num = counter.lock().unwrap(); @@ -15,16 +15,14 @@ error[E0277]: `Rc>` cannot be sent between threads safely 15 | | }); | |_________^ `Rc>` cannot be sent between threads safely | - = help: within `[closure@src/main.rs:11:36: 11:43]`, the trait `Send` is not implemented for `Rc>` + = help: within `{closure@src/main.rs:11:36: 11:43}`, the trait `Send` is not implemented for `Rc>` note: required because it's used within this closure --> src/main.rs:11:36 | 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:704:8 - | - = note: required by this bound in `spawn` + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:678:1 For more information about this error, try `rustc --explain E0277`. -error: could not compile `shared-state` due to previous error +error: could not compile `shared-state` (bin "shared-state") due to 1 previous error diff --git a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt index fca5abeb80..929354c131 100644 --- a/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt +++ b/listings/ch16-fearless-concurrency/output-only-01-move-drop/output.txt @@ -15,4 +15,4 @@ error[E0382]: use of moved value: `v` | ^ value used here after move For more information about this error, try `rustc --explain E0382`. -error: could not compile `threads` due to previous error +error: could not compile `threads` (bin "threads") due to 1 previous error diff --git a/listings/ch17-oop/listing-17-10/output.txt b/listings/ch17-oop/listing-17-10/output.txt index e0a455f3b4..78d7c39a32 100644 --- a/listings/ch17-oop/listing-17-10/output.txt +++ b/listings/ch17-oop/listing-17-10/output.txt @@ -7,7 +7,7 @@ error[E0277]: the trait bound `String: Draw` is not satisfied | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Draw` is not implemented for `String` | = help: the trait `Draw` is implemented for `Button` - = note: required for the cast from `String` to the object type `dyn Draw` + = note: required for the cast from `Box` to `Box` For more information about this error, try `rustc --explain E0277`. -error: could not compile `gui` due to previous error +error: could not compile `gui` (bin "gui") due to 1 previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-05/output.txt b/listings/ch18-patterns-and-matching/listing-18-05/output.txt index 57916a1f15..8002272a72 100644 --- a/listings/ch18-patterns-and-matching/listing-18-05/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-05/output.txt @@ -12,4 +12,4 @@ error[E0308]: mismatched types found tuple `(_, _)` For more information about this error, try `rustc --explain E0308`. -error: could not compile `patterns` due to previous error +error: could not compile `patterns` (bin "patterns") due to 1 previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-08/output.txt b/listings/ch18-patterns-and-matching/listing-18-08/output.txt index 52efabb5c1..6ce3dfc582 100644 --- a/listings/ch18-patterns-and-matching/listing-18-08/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-08/output.txt @@ -1,6 +1,6 @@ $ cargo run Compiling patterns v0.1.0 (file:///projects/patterns) -error[E0005]: refutable pattern in local binding: `None` not covered +error[E0005]: refutable pattern in local binding --> src/main.rs:3:9 | 3 | let Some(x) = some_option_value; @@ -8,20 +8,11 @@ error[E0005]: refutable pattern in local binding: `None` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html -note: `Option` defined here - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:518:1 - | - = note: -/rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/option.rs:522:5: not covered = note: the matched value is of type `Option` -help: you might want to use `if let` to ignore the variant that isn't matched - | -3 | let x = if let Some(x) = some_option_value { x } else { todo!() }; - | ++++++++++ ++++++++++++++++++++++ -help: alternatively, you might want to use let else to handle the variant that isn't matched +help: you might want to use `let else` to handle the variant that isn't matched | 3 | let Some(x) = some_option_value else { todo!() }; | ++++++++++++++++ For more information about this error, try `rustc --explain E0005`. -error: could not compile `patterns` due to previous error +error: could not compile `patterns` (bin "patterns") due to 1 previous error diff --git a/listings/ch18-patterns-and-matching/listing-18-25/output.txt b/listings/ch18-patterns-and-matching/listing-18-25/output.txt index 7e0357eac2..bd5e0f9d7b 100644 --- a/listings/ch18-patterns-and-matching/listing-18-25/output.txt +++ b/listings/ch18-patterns-and-matching/listing-18-25/output.txt @@ -8,4 +8,4 @@ error: `..` can only be used once per tuple pattern | | | previously used here -error: could not compile `patterns` due to previous error +error: could not compile `patterns` (bin "patterns") due to 1 previous error diff --git a/listings/ch19-advanced-features/listing-19-05/output.txt b/listings/ch19-advanced-features/listing-19-05/output.txt index f4b7582acc..44bcc09135 100644 --- a/listings/ch19-advanced-features/listing-19-05/output.txt +++ b/listings/ch19-advanced-features/listing-19-05/output.txt @@ -14,4 +14,4 @@ error[E0499]: cannot borrow `*values` as mutable more than once at a time | returning this value requires that `*values` is borrowed for `'1` For more information about this error, try `rustc --explain E0499`. -error: could not compile `unsafe-example` due to previous error +error: could not compile `unsafe-example` (bin "unsafe-example") due to 1 previous error diff --git a/listings/ch19-advanced-features/listing-19-20/output.txt b/listings/ch19-advanced-features/listing-19-20/output.txt index 5942876044..3cb5961a1a 100644 --- a/listings/ch19-advanced-features/listing-19-20/output.txt +++ b/listings/ch19-advanced-features/listing-19-20/output.txt @@ -15,4 +15,4 @@ help: use the fully-qualified path to the only available implementation | +++++++ + For more information about this error, try `rustc --explain E0790`. -error: could not compile `traits-example` due to previous error +error: could not compile `traits-example` (bin "traits-example") due to 1 previous error diff --git a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock index 9a38c8ac26..6be987b21b 100644 --- a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock +++ b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.lock @@ -1,46 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml index aa076ac48b..ed9e917ad0 100644 --- a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml +++ b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" diff --git a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs index 11643a8d62..839ec83593 100644 --- a/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch19-advanced-features/listing-19-31/hello_macro/hello_macro_derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { diff --git a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock index 9a38c8ac26..6be987b21b 100644 --- a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock +++ b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.lock @@ -1,46 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml index aa076ac48b..ed9e917ad0 100644 --- a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml +++ b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" diff --git a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs index dac6c98f66..ba1215f510 100644 --- a/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch19-advanced-features/listing-19-33/hello_macro/hello_macro_derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { diff --git a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt index 0991f10faa..d5f2155f83 100644 --- a/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt +++ b/listings/ch19-advanced-features/no-listing-02-impl-outlineprint-for-point/output.txt @@ -1,10 +1,10 @@ $ cargo run Compiling traits-example v0.1.0 (file:///projects/traits-example) error[E0277]: `Point` doesn't implement `std::fmt::Display` - --> src/main.rs:20:6 + --> src/main.rs:20:23 | 20 | impl OutlinePrint for Point {} - | ^^^^^^^^^^^^ `Point` cannot be formatted with the default formatter + | ^^^^^ `Point` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `Point` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead @@ -15,4 +15,4 @@ note: required by a bound in `OutlinePrint` | ^^^^^^^^^^^^ required by this bound in `OutlinePrint` For more information about this error, try `rustc --explain E0277`. -error: could not compile `traits-example` due to previous error +error: could not compile `traits-example` (bin "traits-example") due to 1 previous error diff --git a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt index 104f2cf0fe..bc736bd689 100644 --- a/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt +++ b/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt @@ -6,11 +6,15 @@ error[E0746]: return type cannot have an unboxed trait object 1 | fn returns_closure() -> dyn Fn(i32) -> i32 { | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | - = note: for information on `impl Trait`, see -help: use `impl Fn(i32) -> i32` as the return type, as all return paths are of type `[closure@src/lib.rs:2:5: 2:8]`, which implements `Fn(i32) -> i32` +help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type | 1 | fn returns_closure() -> impl Fn(i32) -> i32 { - | ~~~~~~~~~~~~~~~~~~~ + | ~~~~ +help: box the return type, and wrap all of the returned values in `Box::new` + | +1 ~ fn returns_closure() -> Box i32> { +2 ~ Box::new(|x| x + 1) + | For more information about this error, try `rustc --explain E0746`. -error: could not compile `functions-example` due to previous error +error: could not compile `functions-example` (lib) due to 1 previous error diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock index 9a38c8ac26..6be987b21b 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.lock @@ -1,46 +1,46 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml index aa076ac48b..ed9e917ad0 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/Cargo.toml @@ -7,5 +7,5 @@ edition = "2021" proc-macro = true [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs index 5e0b96c277..654b6bee56 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(HelloMacro)] pub fn hello_macro_derive(input: TokenStream) -> TokenStream { diff --git a/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock b/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock index dee23ecf96..3849f15217 100644 --- a/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock +++ b/listings/ch19-advanced-features/no-listing-21-pancakes/pancakes/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "hello_macro" version = "0.1.0" @@ -8,51 +10,49 @@ version = "0.1.0" name = "hello_macro_derive" version = "0.1.0" dependencies = [ - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "quote", + "syn", ] [[package]] name = "pancakes" version = "0.1.0" dependencies = [ - "hello_macro 0.1.0", - "hello_macro_derive 0.1.0", + "hello_macro", + "hello_macro_derive", ] [[package]] name = "proc-macro2" -version = "1.0.8" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.2" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", ] [[package]] name = "syn" -version = "1.0.14" +version = "2.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" dependencies = [ - "proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum proc-macro2 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3acb317c6ff86a4e579dfa00fc5e6cca91ecbb4e7eb2df0468805b674eb88548" -"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" -"checksum syn 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "af6f3550d8dff9ef7dc34d384ac6f107e5d31c8f57d9f28e0081503f547ac8f5" -"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt index 5886bc6307..b2ed043a10 100644 --- a/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt +++ b/listings/ch19-advanced-features/output-only-01-missing-unsafe/output.txt @@ -9,4 +9,4 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or = note: consult the function's documentation for information on how to avoid undefined behavior For more information about this error, try `rustc --explain E0133`. -error: could not compile `unsafe-example` due to previous error +error: could not compile `unsafe-example` (bin "unsafe-example") due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-12/output.txt b/listings/ch20-web-server/listing-20-12/output.txt index 57a58b960e..0faae99204 100644 --- a/listings/ch20-web-server/listing-20-12/output.txt +++ b/listings/ch20-web-server/listing-20-12/output.txt @@ -7,4 +7,4 @@ error[E0433]: failed to resolve: use of undeclared type `ThreadPool` | ^^^^^^^^^^ use of undeclared type `ThreadPool` For more information about this error, try `rustc --explain E0433`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (bin "hello") due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-17/output.txt b/listings/ch20-web-server/listing-20-17/output.txt index 8bedfecfd4..cd06ca1b60 100644 --- a/listings/ch20-web-server/listing-20-17/output.txt +++ b/listings/ch20-web-server/listing-20-17/output.txt @@ -6,8 +6,16 @@ error[E0382]: use of moved value: `receiver` 21 | let (sender, receiver) = mpsc::channel(); | -------- move occurs because `receiver` has type `std::sync::mpsc::Receiver`, which does not implement the `Copy` trait ... +25 | for id in 0..size { + | ----------------- inside of this loop 26 | workers.push(Worker::new(id, receiver)); | ^^^^^^^^ value moved here, in previous iteration of loop + | +note: consider changing this parameter type in method `new` to borrow instead if owning the value isn't necessary + --> src/lib.rs:47:33 + | +47 | fn new(id: usize, receiver: mpsc::Receiver) -> Worker { + | --- in this method ^^^^^^^^^^^^^^^^^^^ this parameter takes ownership of the value For more information about this error, try `rustc --explain E0382`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (lib) due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-22/output.txt b/listings/ch20-web-server/listing-20-22/output.txt index 342bf9a16d..35588617dd 100644 --- a/listings/ch20-web-server/listing-20-22/output.txt +++ b/listings/ch20-web-server/listing-20-22/output.txt @@ -8,8 +8,8 @@ error[E0507]: cannot move out of `worker.thread` which is behind a mutable refer | | | move occurs because `worker.thread` has type `JoinHandle<()>`, which does not implement the `Copy` trait | -note: this function takes ownership of the receiver `self`, which moves `worker.thread` - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:1581:17 +note: `JoinHandle::::join` takes ownership of the receiver `self`, which moves `worker.thread` + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:1649:17 For more information about this error, try `rustc --explain E0507`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (lib) due to 1 previous error diff --git a/listings/ch20-web-server/listing-20-25/src/main.rs b/listings/ch20-web-server/listing-20-25/src/main.rs index a649ff1031..86e8d9e78c 100644 --- a/listings/ch20-web-server/listing-20-25/src/main.rs +++ b/listings/ch20-web-server/listing-20-25/src/main.rs @@ -1,10 +1,11 @@ use hello::ThreadPool; -use std::fs; -use std::io::prelude::*; -use std::net::TcpListener; -use std::net::TcpStream; -use std::thread; -use std::time::Duration; +use std::{ + fs, + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, + thread, + time::Duration, +}; // ANCHOR: here fn main() { @@ -24,30 +25,23 @@ fn main() { // ANCHOR_END: here fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 1024]; - stream.read(&mut buffer).unwrap(); - - let get = b"GET / HTTP/1.1\r\n"; - let sleep = b"GET /sleep HTTP/1.1\r\n"; - - let (status_line, filename) = if buffer.starts_with(get) { - ("HTTP/1.1 200 OK", "hello.html") - } else if buffer.starts_with(sleep) { - thread::sleep(Duration::from_secs(5)); - ("HTTP/1.1 200 OK", "hello.html") - } else { - ("HTTP/1.1 404 NOT FOUND", "404.html") + let buf_reader = BufReader::new(&mut stream); + let request_line = buf_reader.lines().next().unwrap().unwrap(); + + let (status_line, filename) = match &request_line[..] { + "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"), + "GET /sleep HTTP/1.1" => { + thread::sleep(Duration::from_secs(5)); + ("HTTP/1.1 200 OK", "hello.html") + } + _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), }; let contents = fs::read_to_string(filename).unwrap(); + let length = contents.len(); - let response = format!( - "{}\r\nContent-Length: {}\r\n\r\n{}", - status_line, - contents.len(), - contents - ); + let response = + format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); stream.write_all(response.as_bytes()).unwrap(); - stream.flush().unwrap(); } diff --git a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt index fa337b8a80..85ebfb8138 100644 --- a/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt +++ b/listings/ch20-web-server/no-listing-01-define-threadpool-struct/output.txt @@ -7,4 +7,4 @@ error[E0599]: no function or associated item named `new` found for struct `Threa | ^^^ function or associated item not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (bin "hello") due to 1 previous error diff --git a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt index 44c8f3953b..667041862d 100644 --- a/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt +++ b/listings/ch20-web-server/no-listing-02-impl-threadpool-new/output.txt @@ -4,7 +4,7 @@ error[E0599]: no method named `execute` found for struct `ThreadPool` in the cur --> src/main.rs:17:14 | 17 | pool.execute(|| { - | ^^^^^^^ method not found in `ThreadPool` + | -----^^^^^^^ method not found in `ThreadPool` For more information about this error, try `rustc --explain E0599`. -error: could not compile `hello` due to previous error +error: could not compile `hello` (bin "hello") due to 1 previous error diff --git a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index fec2377dc2..4a622de7f9 100644 --- a/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,7 +7,7 @@ error[E0599]: no method named `join` found for enum `Option` in the current scop | ^^^^ method not found in `Option>` | note: the method `join` exists on the type `JoinHandle<()>` - --> /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/thread/mod.rs:1581:5 + --> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/thread/mod.rs:1649:5 help: consider using `Option::expect` to unwrap the `JoinHandle<()>` value, panicking if the value is an `Option::None` | 52 | worker.thread.expect("REASON").join().unwrap(); @@ -17,7 +17,7 @@ error[E0308]: mismatched types --> src/lib.rs:72:22 | 72 | Worker { id, thread } - | ^^^^^^ expected enum `Option`, found struct `JoinHandle` + | ^^^^^^ expected `Option>`, found `JoinHandle<_>` | = note: expected enum `Option>` found struct `JoinHandle<_>` @@ -28,4 +28,4 @@ help: try wrapping the expression in `Some` Some errors have detailed explanations: E0308, E0599. For more information about an error, try `rustc --explain E0308`. -error: could not compile `hello` due to 2 previous errors +error: could not compile `hello` (lib) due to 2 previous errors diff --git a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs index 3161c2ee5c..b6aa046d1b 100644 --- a/listings/ch20-web-server/no-listing-07-final-code/src/main.rs +++ b/listings/ch20-web-server/no-listing-07-final-code/src/main.rs @@ -1,10 +1,11 @@ use hello::ThreadPool; -use std::fs; -use std::io::prelude::*; -use std::net::TcpListener; -use std::net::TcpStream; -use std::thread; -use std::time::Duration; +use std::{ + fs, + io::{prelude::*, BufReader}, + net::{TcpListener, TcpStream}, + thread, + time::Duration, +}; fn main() { let listener = TcpListener::bind("127.0.0.1:7878").unwrap(); @@ -22,30 +23,23 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let mut buffer = [0; 1024]; - stream.read(&mut buffer).unwrap(); - - let get = b"GET / HTTP/1.1\r\n"; - let sleep = b"GET /sleep HTTP/1.1\r\n"; - - let (status_line, filename) = if buffer.starts_with(get) { - ("HTTP/1.1 200 OK", "hello.html") - } else if buffer.starts_with(sleep) { - thread::sleep(Duration::from_secs(5)); - ("HTTP/1.1 200 OK", "hello.html") - } else { - ("HTTP/1.1 404 NOT FOUND", "404.html") + let buf_reader = BufReader::new(&mut stream); + let request_line = buf_reader.lines().next().unwrap().unwrap(); + + let (status_line, filename) = match &request_line[..] { + "GET / HTTP/1.1" => ("HTTP/1.1 200 OK", "hello.html"), + "GET /sleep HTTP/1.1" => { + thread::sleep(Duration::from_secs(5)); + ("HTTP/1.1 200 OK", "hello.html") + } + _ => ("HTTP/1.1 404 NOT FOUND", "404.html"), }; let contents = fs::read_to_string(filename).unwrap(); + let length = contents.len(); - let response = format!( - "{}\r\nContent-Length: {}\r\n\r\n{}", - status_line, - contents.len(), - contents - ); + let response = + format!("{status_line}\r\nContent-Length: {length}\r\n\r\n{contents}"); stream.write_all(response.as_bytes()).unwrap(); - stream.flush().unwrap(); } diff --git a/redirects/compiler-plugins.md b/redirects/compiler-plugins.md index 66061adf5a..67187f5f6b 100644 --- a/redirects/compiler-plugins.md +++ b/redirects/compiler-plugins.md @@ -2,12 +2,5 @@ There is a new edition of the book and this is an old link. -> Compiler plugins are user-provided libraries that extend the compiler's behavior with new syntax extensions, lint checks, etc. - ---- - -This particular chapter has moved to [the Unstable Book][2]. - -* **[In the Unstable Rust Book: `plugin`][2]** - -[2]: ../unstable-book/language-features/plugin.html +> Compiler plugins were user-provided libraries that extended the compiler's behavior in certain ways. +> Support for them has been removed. diff --git a/redirects/loops.md b/redirects/loops.md index 1686c115ee..30c7d4059f 100644 --- a/redirects/loops.md +++ b/redirects/loops.md @@ -14,17 +14,17 @@ loop { let mut number = 3; while number != 0 { - println!("{}!", number); + println!("{number}!"); number = number - 1; } let a = [10, 20, 30, 40, 50]; for element in a.iter() { - println!("the value is: {}", element); + println!("the value is: {element}"); } ``` --- You can find the latest version of this information -[here](ch03-05-control-flow.html#repetition-with-loops). \ No newline at end of file +[here](ch03-05-control-flow.html#repetition-with-loops). diff --git a/rust-toolchain b/rust-toolchain index 9ebd7af328..9242d8e7ab 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.67 +1.76 diff --git a/src/appendix-02-operators.md b/src/appendix-02-operators.md index bc770c703e..0a8dab9d61 100644 --- a/src/appendix-02-operators.md +++ b/src/appendix-02-operators.md @@ -103,7 +103,7 @@ hierarchy to an item. |--------|-------------| | `ident::ident` | Namespace path | | `::path` | Path relative to the crate root (i.e., an explicitly absolute path) | -| `self::path` | Path relative to the current module (i.e., an explicitly relative path). +| `self::path` | Path relative to the current module (i.e., an explicitly relative path). | | `super::path` | Path relative to the parent of the current module | | `type::ident`, `::ident` | Associated constants, functions, and types | | `::...` | Associated item for a type that cannot be directly named (e.g., `<&T>::...`, `<[T]>::...`, etc.) | diff --git a/src/appendix-03-derivable-traits.md b/src/appendix-03-derivable-traits.md index 299796dbf7..8b9b3d3584 100644 --- a/src/appendix-03-derivable-traits.md +++ b/src/appendix-03-derivable-traits.md @@ -45,7 +45,7 @@ The `Debug` trait allows you to print instances of a type for debugging purposes, so you and other programmers using your type can inspect an instance at a particular point in a program’s execution. -The `Debug` trait is required, for example, in use of the `assert_eq!` macro. +The `Debug` trait is required, for example, in using the `assert_eq!` macro. This macro prints the values of instances given as arguments if the equality assertion fails so programmers can see why the two instances weren’t equal. diff --git a/src/appendix-04-useful-development-tools.md b/src/appendix-04-useful-development-tools.md index 40b076153d..30249ed578 100644 --- a/src/appendix-04-useful-development-tools.md +++ b/src/appendix-04-useful-development-tools.md @@ -95,7 +95,7 @@ fn main() { The `for` loop variable is now named `_i`, and the warning no longer appears. You can also use the `cargo fix` command to transition your code between -different Rust editions. Editions are covered in Appendix E. +different Rust editions. Editions are covered in [Appendix E][editions]. ### More Lints with Clippy @@ -178,3 +178,4 @@ particular IDE. Your IDE will gain abilities such as autocompletion, jump to definition, and inline errors. [rust-analyzer]: https://rust-analyzer.github.io +[editions]: appendix-05-editions.md diff --git a/src/appendix-06-translation.md b/src/appendix-06-translation.md index 7e8c68d253..54d58376ee 100644 --- a/src/appendix-06-translation.md +++ b/src/appendix-06-translation.md @@ -22,7 +22,7 @@ For resources in languages other than English. Most are still in progress; see - [Esperanto](https://github.com/psychoslave/Rust-libro) - [ελληνική](https://github.com/TChatzigiannakis/rust-book-greek) - [Svenska](https://github.com/sebras/book) -- [Farsi](https://github.com/pomokhtari/rust-book-fa) +- [Farsi](https://github.com/RustFarsi/book) - [Deutsch](https://github.com/rust-lang-de/rustbook-de) - [हिंदी](https://github.com/venkatarun95/rust-book-hindi) - [ไทย](https://github.com/rust-lang-th/book-th) diff --git a/src/appendix-07-nightly-rust.md b/src/appendix-07-nightly-rust.md index 46e619c815..ac3fbb9df9 100644 --- a/src/appendix-07-nightly-rust.md +++ b/src/appendix-07-nightly-rust.md @@ -114,6 +114,12 @@ work as expected, you can report it to the team and get it fixed before the next stable release happens! Breakage in a beta release is relatively rare, but `rustc` is still a piece of software, and bugs do exist. +### Maintenance time + +The Rust project supports the most recent stable version. When a new stable +version is released, the old version reaches its end of life (EOL). This means +each version is supported for six weeks. + ### Unstable Features There’s one more catch with this release model: unstable features. Rust uses a diff --git a/src/ch00-00-introduction.md b/src/ch00-00-introduction.md index 536988cb19..12632aa0bf 100644 --- a/src/ch00-00-introduction.md +++ b/src/ch00-00-introduction.md @@ -38,7 +38,7 @@ Rust also brings contemporary developer tools to the systems programming world: ecosystem. * The Rustfmt formatting tool ensures a consistent coding style across developers. -* The Rust Language Server powers Integrated Development Environment (IDE) +* The rust-analyzer powers Integrated Development Environment (IDE) integration for code completion and inline error messages. By using these and other tools in the Rust ecosystem, developers can be diff --git a/src/ch01-01-installation.md b/src/ch01-01-installation.md index 87f37fab26..64968f6bc7 100644 --- a/src/ch01-01-installation.md +++ b/src/ch01-01-installation.md @@ -59,16 +59,9 @@ the `build-essential` package. On Windows, go to [https://www.rust-lang.org/tools/install][install] and follow the instructions for installing Rust. At some point in the installation, you’ll -receive a message explaining that you’ll also need the MSVC build tools for -Visual Studio 2013 or later. - -To acquire the build tools, you’ll need to install [Visual Studio -2022][visualstudio]. When asked which workloads to install, include: - -* “Desktop Development with C++” -* The Windows 10 or 11 SDK -* The English language pack component, along with any other language pack of - your choosing +be prompted to install Visual Studio. This provides a linker and the native +libraries needed to compile programs. If you need more help with this step, see +[https://rust-lang.github.io/rustup/installation/windows-msvc.html][msvc] The rest of this book uses commands that work in both *cmd.exe* and PowerShell. If there are specific differences, we’ll explain which to use. @@ -143,5 +136,5 @@ sure what it does or how to use it, use the application programming interface [otherinstall]: https://forge.rust-lang.org/infra/other-installation-methods.html [install]: https://www.rust-lang.org/tools/install -[visualstudio]: https://visualstudio.microsoft.com/downloads/ +[msvc]: https://rust-lang.github.io/rustup/installation/windows-msvc.html [community]: https://www.rust-lang.org/community diff --git a/src/ch01-02-hello-world.md b/src/ch01-02-hello-world.md index 8d8d754d7b..f291463799 100644 --- a/src/ch01-02-hello-world.md +++ b/src/ch01-02-hello-world.md @@ -198,4 +198,4 @@ code. Next, we’ll introduce you to the Cargo tool, which will help you write real-world Rust programs. [troubleshooting]: ch01-01-installation.html#troubleshooting -[devtools]: appendix-04-useful-development-tools.md +[devtools]: appendix-04-useful-development-tools.html diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index 5e27fb114d..e3d0a1194d 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -466,8 +466,8 @@ checked into source control with the rest of the code in your project. When you *do* want to update a crate, Cargo provides the command `update`, which will ignore the *Cargo.lock* file and figure out all the latest versions that fit your specifications in *Cargo.toml*. Cargo will then write those -versions to the *Cargo.lock* file. Otherwise, by default, Cargo will only look -for versions greater than 0.8.5 and less than 0.9.0. If the `rand` crate has +versions to the *Cargo.lock* file. In this case, Cargo will only look for +versions greater than 0.8.5 and less than 0.9.0. If the `rand` crate has released the two new versions 0.8.6 and 0.9.0, you would see the following if you ran `cargo update`: diff --git a/src/ch03-02-data-types.md b/src/ch03-02-data-types.md index bedf1450cc..2cfc156e89 100644 --- a/src/ch03-02-data-types.md +++ b/src/ch03-02-data-types.md @@ -352,7 +352,8 @@ cargo run --> ```console -thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 10', src/main.rs:19:19 +thread 'main' panicked at src/main.rs:19:19: +index out of bounds: the len is 5 but the index is 10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` diff --git a/src/ch03-05-control-flow.md b/src/ch03-05-control-flow.md index 60d6b95a96..ac416660d9 100644 --- a/src/ch03-05-control-flow.md +++ b/src/ch03-05-control-flow.md @@ -250,6 +250,9 @@ and then check whether the `counter` is equal to `10`. When it is, we use the semicolon to end the statement that assigns the value to `result`. Finally, we print the value in `result`, which in this case is `20`. +You can also `return` from inside a loop. While `break` only exits the current +loop, `return` always exits the current function. + #### Loop Labels to Disambiguate Between Multiple Loops If you have loops within loops, `break` and `continue` apply to the innermost @@ -297,7 +300,7 @@ evaluates to `true`, the code runs; otherwise, it exits the loop. #### Looping Through a Collection with `for` -You can choose to use the `while` construct to loop over the elements of a +You can also use the `while` construct to loop over the elements of a collection, such as an array. For example, the loop in Listing 3-4 prints each element in the array `a`. diff --git a/src/ch04-03-slices.md b/src/ch04-03-slices.md index 6ffb1dc114..c94fdc56f2 100644 --- a/src/ch04-03-slices.md +++ b/src/ch04-03-slices.md @@ -266,7 +266,7 @@ a string slice for the type of the `s` parameter If we have a string slice, we can pass that directly. If we have a `String`, we can pass a slice of the `String` or a reference to the `String`. This -flexibility takes advantage of *deref coercions*, a feature we will cover in +flexibility takes advantage of *deref coercions*, a feature we will cover in the [“Implicit Deref Coercions with Functions and Methods”][deref-coercions] section of Chapter 15. diff --git a/src/ch05-01-defining-structs.md b/src/ch05-01-defining-structs.md index d258d89cc5..c5db4dc74d 100644 --- a/src/ch05-01-defining-structs.md +++ b/src/ch05-01-defining-structs.md @@ -120,7 +120,7 @@ otherwise use the same values from `user1` that we created in Listing 5-2. {{#rustdoc_include ../listings/ch05-using-structs-to-structure-related-data/listing-05-06/src/main.rs:here}} ``` -Listing 5-6: Creating a new `User` instance using one of +Listing 5-6: Creating a new `User` instance using all but one of the values from `user1` Using struct update syntax, we can achieve the same effect with less code, as @@ -278,7 +278,7 @@ implement them on any type, including unit-like structs. > | > > For more information about this error, try `rustc --explain E0106`. -> error: could not compile `structs` due to 2 previous errors +> error: could not compile `structs` (bin "structs") due to 2 previous errors > ``` > > In Chapter 10, we’ll discuss how to fix these errors so you can store diff --git a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md index c8fb3247ff..85fc247376 100644 --- a/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md +++ b/src/ch07-03-paths-for-referring-to-an-item-in-the-module-tree.md @@ -184,8 +184,8 @@ interested in this topic, see [The Rust API Guidelines][api-guidelines]. > well as a *src/lib.rs* library crate root, and both crates will have the > package name by default. Typically, packages with this pattern of containing > both a library and a binary crate will have just enough code in the binary -> crate to start an executable that calls code with the library crate. This -> lets other projects benefit from the most functionality that the package +> crate to start an executable that calls code within the library crate. This +> lets other projects benefit from most of the functionality that the package > provides, because the library crate’s code can be shared. > > The module tree should be defined in *src/lib.rs*. Then, any public items can diff --git a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md index 921e5cecca..f50219ea33 100644 --- a/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md +++ b/src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md @@ -157,7 +157,8 @@ from a new scope with `pub use` Before this change, external code would have to call the `add_to_waitlist` function by using the path -`restaurant::front_of_house::hosting::add_to_waitlist()`. Now that this `pub +`restaurant::front_of_house::hosting::add_to_waitlist()`, which also would have +required the `front_of_house` module to be marked as `pub`. Now that this `pub use` has re-exported the `hosting` module from the root module, external code can now use the path `restaurant::hosting::add_to_waitlist()` instead. diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index 85d3bcfe41..d6d72de069 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -202,7 +202,7 @@ some of the columns in the row contain integers, some floating-point numbers, and some strings. We can define an enum whose variants will hold the different value types, and all the enum variants will be considered the same type: that of the enum. Then we can create a vector to hold that enum and so, ultimately, -holds different types. We’ve demonstrated this in Listing 8-9. +hold different types. We’ve demonstrated this in Listing 8-9. ```rust {{#rustdoc_include ../listings/ch08-common-collections/listing-08-09/src/main.rs:here}} diff --git a/src/ch09-01-unrecoverable-errors-with-panic.md b/src/ch09-01-unrecoverable-errors-with-panic.md index 5675fe3e76..3928f8d61a 100644 --- a/src/ch09-01-unrecoverable-errors-with-panic.md +++ b/src/ch09-01-unrecoverable-errors-with-panic.md @@ -117,24 +117,25 @@ check the backtrace number mentioned in the text below the listing ```console $ RUST_BACKTRACE=1 cargo run -thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 99', src/main.rs:4:5 +thread 'main' panicked at src/main.rs:4:6: +index out of bounds: the len is 3 but the index is 99 stack backtrace: 0: rust_begin_unwind - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:584:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5 1: core::panicking::panic_fmt - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:142:14 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14 2: core::panicking::panic_bounds_check - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:84:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:208:5 3: >::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/slice/index.rs:242:10 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:255:10 4: core::slice::index:: for [T]>::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/slice/index.rs:18:9 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/slice/index.rs:18:9 5: as core::ops::index::Index>::index - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc/src/vec/mod.rs:2591:9 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/vec/mod.rs:2770:9 6: panic::main - at ./src/main.rs:4:5 + at ./src/main.rs:4:6 7: core::ops::function::FnOnce::call_once - at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:248:5 + at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ``` diff --git a/src/ch09-02-recoverable-errors-with-result.md b/src/ch09-02-recoverable-errors-with-result.md index 2dd864f08c..c6c4e4b962 100644 --- a/src/ch09-02-recoverable-errors-with-result.md +++ b/src/ch09-02-recoverable-errors-with-result.md @@ -188,9 +188,8 @@ copy and paste relevant text --> ```text -thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { -code: 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:4:49 +thread 'main' panicked at src/main.rs:4:49: +called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` Similarly, the `expect` method lets us also choose the `panic!` error message. @@ -216,9 +215,8 @@ copy and paste relevant text --> ```text -thread 'main' panicked at 'hello.txt should be included in this project: Os { -code: 2, kind: NotFound, message: "No such file or directory" }', -src/main.rs:5:10 +thread 'main' panicked at src/main.rs:5:10: +hello.txt should be included in this project: Os { code: 2, kind: NotFound, message: "No such file or directory" } ``` In production-quality code, most Rustaceans choose `expect` rather than diff --git a/src/ch10-03-lifetime-syntax.md b/src/ch10-03-lifetime-syntax.md index 498f01f0b5..e77be953b3 100644 --- a/src/ch10-03-lifetime-syntax.md +++ b/src/ch10-03-lifetime-syntax.md @@ -93,7 +93,7 @@ Here, `x` has the lifetime `'b`, which in this case is larger than `'a`. This means `r` can reference `x` because Rust knows that the reference in `r` will always be valid while `x` is valid. -Now that you know where the lifetimes of references are and how Rust analyzes +Now that you know what the lifetimes of references are and how Rust analyzes lifetimes to ensure references will always be valid, let’s explore generic lifetimes of parameters and return values in the context of functions. diff --git a/src/ch11-01-writing-tests.md b/src/ch11-01-writing-tests.md index df09aadc84..f1295931f4 100644 --- a/src/ch11-01-writing-tests.md +++ b/src/ch11-01-writing-tests.md @@ -62,7 +62,7 @@ cd ../../.. Listing 11-1: The test module and function generated automatically by `cargo new` -For now, let’s ignore the top two lines and focus on the function. Note the +For now, let’s focus solely on the `it_works()` function. Note the `#[test]` annotation: this attribute indicates this is a test function, so the test runner knows to treat this function as a test. We might also have non-test functions in the `tests` module to help set up common scenarios or perform @@ -309,7 +309,7 @@ Run the tests again: ``` Our test caught the bug! The `it_adds_two` test failed, and the message tells -us that the assertion that fails was `` assertion failed: `(left == right)` `` +us that the assertion that fails was ``assertion `left == right` failed`` and what the `left` and `right` values are. This message helps us start debugging: the `left` argument was `4` but the `right` argument, where we had `add_two(2)`, was `5`. You can imagine that this would be especially helpful @@ -497,10 +497,10 @@ This time when we run the `should_panic` test, it will fail: ``` The failure message indicates that this test did indeed panic as we expected, -but the panic message did not include the expected string `'Guess value must be -less than or equal to 100'`. The panic message that we did get in this case was -`Guess value must be greater than or equal to 1, got 200.` Now we can start -figuring out where our bug is! +but the panic message did not include the expected string `less than or equal +to 100`. The panic message that we did get in this case was `Guess value must +be greater than or equal to 1, got 200.` Now we can start figuring out where +our bug is! ### Using `Result` in Tests diff --git a/src/ch11-03-test-organization.md b/src/ch11-03-test-organization.md index 9f26546cf4..fb592e909c 100644 --- a/src/ch11-03-test-organization.md +++ b/src/ch11-03-test-organization.md @@ -70,7 +70,7 @@ Note that the `internal_adder` function is not marked as `pub`. Tests are just Rust code, and the `tests` module is just another module. As we discussed in the [“Paths for Referring to an Item in the Module Tree”][paths] section, items in child modules can use the items in their ancestor modules. In -this test, we bring all of the `test` module’s parent’s items into scope with +this test, we bring all of the `tests` module’s parent’s items into scope with `use super::*`, and then the test can call `internal_adder`. If you don’t think private functions should be tested, there’s nothing in Rust that will compel you to do so. @@ -118,8 +118,9 @@ Enter the code in Listing 11-13 into the *tests/integration_test.rs* file: `adder` crate Each file in the `tests` directory is a separate crate, so we need to bring our -library into each test crate’s scope. For that reason we add `use adder` at the -top of the code, which we didn’t need in the unit tests. +library into each test crate’s scope. For that reason we add `use +adder::add_two` at the top of the code, which we didn’t need in the unit +tests. We don’t need to annotate any code in *tests/integration_test.rs* with `#[cfg(test)]`. Cargo treats the `tests` directory specially and compiles files diff --git a/src/ch12-05-working-with-environment-variables.md b/src/ch12-05-working-with-environment-variables.md index 4e6b40fb3b..263c80cd06 100644 --- a/src/ch12-05-working-with-environment-variables.md +++ b/src/ch12-05-working-with-environment-variables.md @@ -113,7 +113,7 @@ function, as shown in Listing 12-22. This still won’t compile yet. Finally, we need to check for the environment variable. The functions for working with environment variables are in the `env` module in the standard library, so we bring that module into scope at the top of *src/lib.rs*. Then -we’ll use the `var` function from the `env` module to check to see if any value +we’ll use the `var` function from the `env` module to check if any value has been set for an environment variable named `IGNORE_CASE`, as shown in Listing 12-23. diff --git a/src/ch13-01-closures.md b/src/ch13-01-closures.md index f1ae324354..d9e3ac6841 100644 --- a/src/ch13-01-closures.md +++ b/src/ch13-01-closures.md @@ -382,7 +382,7 @@ compiler won’t let us use this closure with `sort_by_key`: `sort_by_key` This is a contrived, convoluted way (that doesn’t work) to try and count the -number of times `sort_by_key` gets called when sorting `list`. This code +number of times `sort_by_key` calls the closure when sorting `list`. This code attempts to do this counting by pushing `value`—a `String` from the closure’s environment—into the `sort_operations` vector. The closure captures `value` then moves `value` out of the closure by transferring ownership of `value` to @@ -399,7 +399,7 @@ implement `FnMut`: The error points to the line in the closure body that moves `value` out of the environment. To fix this, we need to change the closure body so that it doesn’t -move values out of the environment. To count the number of times `sort_by_key` +move values out of the environment. To count the number of times the closure is called, keeping a counter in the environment and incrementing its value in the closure body is a more straightforward way to calculate that. The closure in Listing 13-9 works with `sort_by_key` because it is only capturing a mutable diff --git a/src/ch13-03-improving-our-io-project.md b/src/ch13-03-improving-our-io-project.md index 42a5be89d2..e4deec5627 100644 --- a/src/ch13-03-improving-our-io-project.md +++ b/src/ch13-03-improving-our-io-project.md @@ -90,7 +90,7 @@ We’ve updated the signature of the `Config::build` function so the parameter `args` has a generic type with the trait bounds `impl Iterator` instead of `&[String]`. This usage of the `impl Trait` syntax we discussed in the [“Traits as Parameters”][impl-trait] section of Chapter 10 -means that `args` can be any type that implements the `Iterator` type and +means that `args` can be any type that implements the `Iterator` trait and returns `String` items. Because we’re taking ownership of `args` and we’ll be mutating `args` by diff --git a/src/ch14-02-publishing-to-crates-io.md b/src/ch14-02-publishing-to-crates-io.md index c5b1ac7fc3..d4d33babc4 100644 --- a/src/ch14-02-publishing-to-crates-io.md +++ b/src/ch14-02-publishing-to-crates-io.md @@ -273,10 +273,11 @@ in via a GitHub account. (The GitHub account is currently a requirement, but the site might support other ways of creating an account in the future.) Once you’re logged in, visit your account settings at [https://crates.io/me/](https://crates.io/me/) and retrieve your -API key. Then run the `cargo login` command with your API key, like this: +API key. Then run the `cargo login` command and paste your API key when prompted, like this: ```console -$ cargo login abcdefghijklmnopqrstuvwxyz012345 +$ cargo login +abcdefghijklmnopqrstuvwxyz012345 ``` This command will inform Cargo of your API token and store it locally in diff --git a/src/ch15-01-box.md b/src/ch15-01-box.md index 8380625527..53e829a4c3 100644 --- a/src/ch15-01-box.md +++ b/src/ch15-01-box.md @@ -193,7 +193,7 @@ after doing automatic regeneration, look at listings/ch15-smart-pointers/listing --> ```text -help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `List` representable +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle | 2 | Cons(i32, Box), | ++++ + diff --git a/src/ch15-02-deref.md b/src/ch15-02-deref.md index 23c9fe8bfc..56db7c0a02 100644 --- a/src/ch15-02-deref.md +++ b/src/ch15-02-deref.md @@ -14,7 +14,7 @@ smart pointers to work in ways similar to references. Then we’ll look at Rust’s *deref coercion* feature and how it lets us work with either references or smart pointers. -> Note: there’s one big difference between the `MyBox` type we’re about to +> Note: There’s one big difference between the `MyBox` type we’re about to > build and the real `Box`: our version will not store its data on the heap. > We are focusing this example on `Deref`, so where the data is actually stored > is less important than the pointer-like behavior. diff --git a/src/ch16-02-message-passing.md b/src/ch16-02-message-passing.md index e2f0b63c14..c468b94c33 100644 --- a/src/ch16-02-message-passing.md +++ b/src/ch16-02-message-passing.md @@ -52,7 +52,7 @@ producer for now, but we’ll add multiple producers when we get this example working. The `mpsc::channel` function returns a tuple, the first element of which is the -sending end--the transmitter--and the second element is the receiving end--the +sending end—the transmitter—and the second element is the receiving end—the receiver. The abbreviations `tx` and `rx` are traditionally used in many fields for *transmitter* and *receiver* respectively, so we name our variables as such to indicate each end. We’re using a `let` statement with a pattern that diff --git a/src/ch16-03-shared-state.md b/src/ch16-03-shared-state.md index 918d162cf5..a5f806c5bf 100644 --- a/src/ch16-03-shared-state.md +++ b/src/ch16-03-shared-state.md @@ -128,7 +128,7 @@ We hinted that this example wouldn’t compile. Now let’s find out why! The error message states that the `counter` value was moved in the previous iteration of the loop. Rust is telling us that we can’t move the ownership -of lock `counter` into multiple threads. Let’s fix the compiler error with a +of `counter` into multiple threads. Let’s fix the compiler error with a multiple-ownership method we discussed in Chapter 15. #### Multiple Ownership with Multiple Threads diff --git a/src/ch17-01-what-is-oo.md b/src/ch17-01-what-is-oo.md index a47afebd93..4a11b7cc08 100644 --- a/src/ch17-01-what-is-oo.md +++ b/src/ch17-01-what-is-oo.md @@ -86,10 +86,10 @@ Because we’ve encapsulated the implementation details of the struct in the future. For instance, we could use a `HashSet` instead of a `Vec` for the `list` field. As long as the signatures of the `add`, `remove`, and `average` public methods stay the same, code using -`AveragedCollection` wouldn’t need to change. If we made `list` public instead, -this wouldn’t necessarily be the case: `HashSet` and `Vec` have -different methods for adding and removing items, so the external code would -likely have to change if it were modifying `list` directly. +`AveragedCollection` wouldn’t need to change in order to compile. If we made +`list` public instead, this wouldn’t necessarily be the case: `HashSet` and +`Vec` have different methods for adding and removing items, so the external +code would likely have to change if it were modifying `list` directly. If encapsulation is a required aspect for a language to be considered object-oriented, then Rust meets that requirement. The option to use `pub` or diff --git a/src/ch18-02-refutability.md b/src/ch18-02-refutability.md index be3c31765c..c8ca8b5766 100644 --- a/src/ch18-02-refutability.md +++ b/src/ch18-02-refutability.md @@ -60,10 +60,10 @@ the code in the curly brackets, giving it a way to continue validly. Listing Listing 18-9: Using `if let` and a block with refutable patterns instead of `let` -We’ve given the code an out! This code is perfectly valid, although it means we -cannot use an irrefutable pattern without receiving an error. If we give `if -let` a pattern that will always match, such as `x`, as shown in Listing 18-10, -the compiler will give a warning. +We’ve given the code an out! This code is perfectly valid now. However, +if we give `if let` an irrefutable pattern (a pattern that will always +match), such as `x`, as shown in Listing 18-10, the compiler will give a +warning. ```rust {{#rustdoc_include ../listings/ch18-patterns-and-matching/listing-18-10/src/main.rs:here}} diff --git a/src/ch19-01-unsafe-rust.md b/src/ch19-01-unsafe-rust.md index 6ff229dd37..a8133ca8e5 100644 --- a/src/ch19-01-unsafe-rust.md +++ b/src/ch19-01-unsafe-rust.md @@ -34,7 +34,7 @@ include the ability to: * Call an unsafe function or method * Access or modify a mutable static variable * Implement an unsafe trait -* Access fields of `union`s +* Access fields of a `union` It’s important to understand that `unsafe` doesn’t turn off the borrow checker or disable any other of Rust’s safety checks: if you use a reference in unsafe diff --git a/src/ch19-03-advanced-traits.md b/src/ch19-03-advanced-traits.md index 6fd3e09f49..789591357b 100644 --- a/src/ch19-03-advanced-traits.md +++ b/src/ch19-03-advanced-traits.md @@ -442,7 +442,7 @@ that holds an instance of `Vec`; then we can implement `Display` on The implementation of `Display` uses `self.0` to access the inner `Vec`, because `Wrapper` is a tuple struct and `Vec` is the item at index 0 in the -tuple. Then we can use the functionality of the `Display` type on `Wrapper`. +tuple. Then we can use the functionality of the `Display` trait on `Wrapper`. The downside of using this technique is that `Wrapper` is a new type, so it doesn’t have the methods of the value it’s holding. We would have to implement diff --git a/src/ch19-06-macros.md b/src/ch19-06-macros.md index 7731869eae..f24a818c18 100644 --- a/src/ch19-06-macros.md +++ b/src/ch19-06-macros.md @@ -508,6 +508,6 @@ and do one more project! [tlborm]: https://veykril.github.io/tlborm/ [`syn`]: https://crates.io/crates/syn [`quote`]: https://crates.io/crates/quote -[syn-docs]: https://docs.rs/syn/1.0/syn/struct.DeriveInput.html +[syn-docs]: https://docs.rs/syn/2.0/syn/struct.DeriveInput.html [quote-docs]: https://docs.rs/quote [decl]: #declarative-macros-with-macro_rules-for-general-metaprogramming diff --git a/src/ch20-01-single-threaded.md b/src/ch20-01-single-threaded.md index 993239a981..b980856fd2 100644 --- a/src/ch20-01-single-threaded.md +++ b/src/ch20-01-single-threaded.md @@ -448,7 +448,7 @@ uses the `status_line` and `filename` variables. This makes it easier to see the difference between the two cases, and it means we have only one place to update the code if we want to change how the file reading and response writing work. The behavior of the code in Listing 20-9 will be the same as that in -Listing 20-8. +Listing 20-7. Awesome! We now have a simple web server in approximately 40 lines of Rust code that responds to one request with a page of content and responds to all other diff --git a/src/ch20-02-multithreaded.md b/src/ch20-02-multithreaded.md index 5a4a50ac01..cec2272db5 100644 --- a/src/ch20-02-multithreaded.md +++ b/src/ch20-02-multithreaded.md @@ -653,7 +653,7 @@ overloaded if the server receives a lot of requests. If we make a request to */sleep*, the server will be able to serve other requests by having another thread run them. -> Note: if you open */sleep* in multiple browser windows simultaneously, they +> Note: If you open */sleep* in multiple browser windows simultaneously, they > might load one at a time in 5 second intervals. Some web browsers execute > multiple instances of the same request sequentially for caching reasons. This > limitation is not caused by our web server. diff --git a/src/title-page.md b/src/title-page.md index 5f7a7a680a..19f2fc8de3 100644 --- a/src/title-page.md +++ b/src/title-page.md @@ -2,13 +2,13 @@ *by Steve Klabnik and Carol Nichols, with contributions from the Rust Community* -This version of the text assumes you’re using Rust 1.67.1 (released 2023-02-09) +This version of the text assumes you’re using Rust 1.76.0 (released 2024-02-08) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust. The HTML format is available online at [https://doc.rust-lang.org/stable/book/](https://doc.rust-lang.org/stable/book/) -and offline with installations of Rust made with `rustup`; run `rustup docs +and offline with installations of Rust made with `rustup`; run `rustup doc --book` to open. Several community [translations] are also available.