diff --git a/ci/dictionary.txt b/ci/dictionary.txt index 4364dc0d61..e6dfe6225e 100644 --- a/ci/dictionary.txt +++ b/ci/dictionary.txt @@ -61,6 +61,7 @@ BTreeSet BufRead BufReader BuildHasher +byteorder Cacher cacher Cagain @@ -104,6 +105,7 @@ CustomSmartPointer CustomSmartPointers data's DataStruct +dbea deallocate deallocated deallocating @@ -566,6 +568,7 @@ Uncomment uncommenting unevaluated unhandled +unicode Uninstalling uninstall unittests @@ -598,6 +601,7 @@ Vlissides vscode vtable waitlist +wasi wasn weakt WeatherForecast @@ -616,4 +620,5 @@ WriteMessage xcode xpression yyyy +zerocopy ZipImpl 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 0fb52b33cb..2aa1298037 100644 --- a/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock +++ b/listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "cfg-if" version = "1.0.0" @@ -10,9 +16,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -28,15 +34,36 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] [[package]] name = "rand" @@ -68,8 +95,46 @@ dependencies = [ "getrandom", ] +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock deleted file mode 100644 index ee5d79095f..0000000000 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "guessing_game" -version = "0.1.0" diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml index 78c94fef95..4e348c8d26 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml +++ b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/Cargo.toml @@ -3,6 +3,4 @@ name = "guessing_game" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt index 33409e38cf..32ed12b639 100644 --- a/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt +++ b/listings/ch02-guessing-game-tutorial/no-listing-01-cargo-new/output.txt @@ -1,5 +1,4 @@ -$ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.50s - Running `target/debug/guessing_game` + Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.80s + Running `file:///projects/guessing_game/target/debug/guessing_game` Hello, world! diff --git a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock b/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock deleted file mode 100644 index 8b8c69d33a..0000000000 --- a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "adder" -version = "0.1.0" diff --git a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml b/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml index b7d36d44cb..e61cb12e3e 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml +++ b/listings/ch11-writing-automated-tests/listing-11-01/Cargo.toml @@ -3,6 +3,4 @@ name = "adder" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] diff --git a/listings/ch11-writing-automated-tests/listing-11-01/output.txt b/listings/ch11-writing-automated-tests/listing-11-01/output.txt index 128309c129..3b09a15ece 100644 --- a/listings/ch11-writing-automated-tests/listing-11-01/output.txt +++ b/listings/ch11-writing-automated-tests/listing-11-01/output.txt @@ -1,7 +1,7 @@ $ cargo test Compiling adder v0.1.0 (file:///projects/adder) Finished `test` profile [unoptimized + debuginfo] target(s) in 0.57s - Running unittests src/lib.rs (target/debug/deps/adder-92948b65e88960b4) + Running unittests src/lib.rs (file:///projects/adder/target/debug/deps/adder-7acb243c25ffd9dc) running 1 test test tests::it_works ... ok @@ -13,4 +13,3 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini running 0 tests test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - 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 7d12d9af81..b93cf3ffd9 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,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/listing-14-07/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock deleted file mode 100644 index d37189b337..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.lock +++ /dev/null @@ -1,6 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "adder" -version = "0.1.0" - diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml deleted file mode 100644 index c5ea8e510b..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/Cargo.toml +++ /dev/null @@ -1,5 +0,0 @@ -[workspace] - -members = [ - "adder", -] diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml deleted file mode 100644 index e61cb12e3e..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "adder" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs b/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs deleted file mode 100644 index e7a11a969c..0000000000 --- a/listings/ch14-more-about-cargo/no-listing-01-workspace-with-adder-crate/add/adder/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml new file mode 100644 index 0000000000..61bdb9cbf2 --- /dev/null +++ b/listings/ch14-more-about-cargo/no-listing-01-workspace/add/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +resolver = "2" diff --git a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-03-workspace-with-external-dependency/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/no-listing-04-workspace-with-tests/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml index c5ea8e510b..38ea3f5655 100644 --- a/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml @@ -1,5 +1,3 @@ [workspace] - -members = [ - "adder", -] +resolver = "2" +members = ["adder"] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml index 1448801d5b..8c9ab0e120 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = [ "add_one","adder"] diff --git a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml index 9000184707..8af4ab8166 100644 --- a/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-02-add-one/add/add_one/Cargo.toml @@ -3,6 +3,4 @@ name = "add_one" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] 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 7d12d9af81..b93cf3ffd9 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,4 +1,4 @@ -pub fn add(left: usize, right: usize) -> usize { +pub fn add(left: u64, right: u64) -> u64 { left + right } diff --git a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml index 1448801d5b..9e542690c7 100644 --- a/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml +++ b/listings/ch14-more-about-cargo/output-only-03-use-rand/add/Cargo.toml @@ -1,6 +1,3 @@ [workspace] - -members = [ - "adder", - "add_one", -] +resolver = "2" +members = ["adder", "add_one"] diff --git a/packages/tools/src/bin/lfp.rs b/packages/tools/src/bin/lfp.rs index ee7f39c3c8..64bdaa99d8 100644 --- a/packages/tools/src/bin/lfp.rs +++ b/packages/tools/src/bin/lfp.rs @@ -106,6 +106,8 @@ fn is_line_of_interest(line: &str) -> bool { line.split_whitespace().any(|sub_string| { sub_string.contains("file://") && !sub_string.contains("file:///projects/") + && !sub_string.contains("file:///home/.cargo") + && !sub_string.contains("file:///home/.rustup") }) } diff --git a/src/ch02-00-guessing-game-tutorial.md b/src/ch02-00-guessing-game-tutorial.md index d0d27f2b1b..848ce75fbe 100644 --- a/src/ch02-00-guessing-game-tutorial.md +++ b/src/ch02-00-guessing-game-tutorial.md @@ -305,7 +305,7 @@ input 6 --> ```console $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 6.44s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.44s Running `target/debug/guessing_game` Guess the number! Please input your guess. @@ -380,22 +380,28 @@ cargo build --> ```console $ cargo build Updating crates.io index - Downloaded rand v0.8.5 - Downloaded libc v0.2.127 - Downloaded getrandom v0.2.7 - Downloaded cfg-if v1.0.0 - Downloaded ppv-lite86 v0.2.16 - Downloaded rand_chacha v0.3.1 - Downloaded rand_core v0.6.3 - Compiling libc v0.2.127 - Compiling getrandom v0.2.7 + Locking 16 packages to latest compatible versions + Adding wasi v0.11.0+wasi-snapshot-preview1 (latest: v0.13.3+wasi-0.2.2) + Adding zerocopy v0.7.35 (latest: v0.8.9) + Adding zerocopy-derive v0.7.35 (latest: v0.8.9) + Downloaded syn v2.0.87 + Downloaded 1 crate (278.1 KB) in 0.16s + Compiling proc-macro2 v1.0.89 + Compiling unicode-ident v1.0.13 + Compiling libc v0.2.161 Compiling cfg-if v1.0.0 - Compiling ppv-lite86 v0.2.16 - Compiling rand_core v0.6.3 + Compiling byteorder v1.5.0 + Compiling getrandom v0.2.15 + Compiling rand_core v0.6.4 + Compiling quote v1.0.37 + Compiling syn v2.0.87 + Compiling zerocopy-derive v0.7.35 + Compiling zerocopy v0.7.35 + Compiling ppv-lite86 v0.2.20 Compiling rand_chacha v0.3.1 Compiling rand v0.8.5 Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 2.53s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.69s ``` @@ -433,7 +439,7 @@ cargo build --> ```console $ cargo build Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 2.53 secs + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s ``` These lines show that Cargo only updates the build with your tiny change to the @@ -557,7 +563,7 @@ cargo run ```console $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 2.53s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/guessing_game` Guess the number! The secret number is: 7 @@ -566,7 +572,7 @@ Please input your guess. You guessed: 4 $ cargo run - Finished dev [unoptimized + debuginfo] target(s) in 0.02s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/guessing_game` Guess the number! The secret number is: 83 @@ -717,6 +723,7 @@ Let’s run the program now: @@ -724,7 +731,7 @@ cargo run ```console $ cargo run Compiling guessing_game v0.1.0 (file:///projects/guessing_game) - Finished dev [unoptimized + debuginfo] target(s) in 0.43s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.26s Running `target/debug/guessing_game` Guess the number! The secret number is: 58 @@ -767,6 +774,7 @@ advantage of that to allow the user to quit, as shown here: ```console -$ cargo run https://www.rust-lang.org +$ cargo run -- https://www.rust-lang.org + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s + Running `target/debug/async_await 'https://www.rust-lang.org'` The title for https://www.rust-lang.org was -Rust Programming Language + Rust Programming Language ``` Phew: we finally have some working async code! This now compiles, and we can run diff --git a/src/ch17-03-more-futures.md b/src/ch17-03-more-futures.md index 5a9fea4482..cab96d1f1d 100644 --- a/src/ch17-03-more-futures.md +++ b/src/ch17-03-more-futures.md @@ -39,7 +39,7 @@ replace `join!` with `join_all`. Unfortunately, this doesn’t compile. Instead, we get this error: @@ -47,33 +47,21 @@ copy just the compiler error ```text error[E0308]: mismatched types - --> src/main.rs:43:37 + --> src/main.rs:45:37 | -8 | let tx1_fut = async move { - | _______________________- -9 | | let vals = vec![ -10 | | String::from("hi"), -11 | | String::from("from"), -... | -19 | | } -20 | | }; - | |_________- the expected `async` block -21 | -22 | let rx_fut = async { - | ______________________- -23 | | while let Some(value) = rx.recv().await { -24 | | println!("received '{value}'"); -25 | | } -26 | | }; - | |_________- the found `async` block +10 | let tx1_fut = async move { + | ---------- the expected `async` block ... -43 | let futures = vec![tx1_fut, rx_fut, tx_fut]; - | ^^^^^^ expected `async` block, found a different `async` block +24 | let rx_fut = async { + | ----- the found `async` block +... +45 | let futures = vec![tx1_fut, rx_fut, tx_fut]; + | ^^^^^^ expected `async` block, found a different `async` block | - = note: expected `async` block `{async block@src/main.rs:8:23: 20:10}` - found `async` block `{async block@src/main.rs:22:22: 26:10}` + = note: expected `async` block `{async block@src/main.rs:10:23: 10:33}` + found `async` block `{async block@src/main.rs:24:22: 24:27}` = note: no two async blocks, even if identical, have the same type - = help: consider pinning your async block and and casting it to a trait object + = help: consider pinning your async block and casting it to a trait object ``` This might be surprising. After all, none of them return anything, so each @@ -135,25 +123,74 @@ the errors mentioning `Unpin`. Although there are three of them, notice that each is very similar in its contents. ```text -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:24 +error[E0308]: mismatched types + --> src/main.rs:46:46 + | +10 | let tx1_fut = async move { + | ---------- the expected `async` block +... +24 | let rx_fut = async { + | ----- the found `async` block +... +46 | vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + | -------- ^^^^^^ expected `async` block, found a different `async` block + | | + | arguments to this function are incorrect + | + = note: expected `async` block `{async block@src/main.rs:10:23: 10:33}` + found `async` block `{async block@src/main.rs:24:22: 24:27}` + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and casting it to a trait object +note: associated function defined here + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/alloc/src/boxed.rs:255:12 + | +255 | pub fn new(x: T) -> Self { + | ^^^ + +error[E0308]: mismatched types + --> src/main.rs:46:64 + | +10 | let tx1_fut = async move { + | ---------- the expected `async` block +... +30 | let tx_fut = async move { + | ---------- the found `async` block +... +46 | vec![Box::new(tx1_fut), Box::new(rx_fut), Box::new(tx_fut)]; + | -------- ^^^^^^ expected `async` block, found a different `async` block + | | + | arguments to this function are incorrect | -46 | trpl::join_all(futures).await; - | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` + = note: expected `async` block `{async block@src/main.rs:10:23: 10:33}` + found `async` block `{async block@src/main.rs:30:22: 30:32}` + = note: no two async blocks, even if identical, have the same type + = help: consider pinning your async block and casting it to a trait object +note: associated function defined here + --> file:///home/.rustup/toolchains/1.82/lib/rustlib/src/rust/library/alloc/src/boxed.rs:255:12 + | +255 | pub fn new(x: T) -> Self { + | ^^^ + +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:24 + | +48 | trpl::join_all(futures).await; + | -------------- ^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | | | required by a bound introduced by this call | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` note: required by a bound in `join_all` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:105:14 | 102 | pub fn join_all(iter: I) -> JoinAll | -------- required by a bound in this function @@ -161,17 +198,17 @@ note: required by a bound in `join_all` 105 | I::Item: Future, | ^^^^^^ required by this bound in `join_all` -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:9 +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:9 | -46 | trpl::join_all(futures).await; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` +48 | trpl::join_all(futures).await; + | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll | ------- required by a bound in this struct @@ -179,26 +216,23 @@ note: required by a bound in `JoinAll` 29 | F: Future, | ^^^^^^ required by this bound in `JoinAll` -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:33 +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:33 | -46 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` +48 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll | ------- required by a bound in this struct 28 | where 29 | F: Future, | ^^^^^^ required by this bound in `JoinAll` - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. ``` That is a *lot* to digest, so let’s pull it apart. The first part of the message @@ -369,7 +403,7 @@ a pair of futures. To begin, each future only hands control back to the runtime If you run this, you will see this output: diff --git a/src/ch17-04-streams.md b/src/ch17-04-streams.md index 0000ac9c88..1f20e873b3 100644 --- a/src/ch17-04-streams.md +++ b/src/ch17-04-streams.md @@ -39,39 +39,36 @@ stream as they arrive with the `while let` loop. Unfortunately, when we try to run the code, it doesn’t compile. Instead, as we can see in the output, it reports that there is no `next` method available. - ```console error[E0599]: no method named `next` found for struct `Iter` in the current scope - --> src/main.rs:8:40 - | -8 | while let Some(value) = stream.next().await { - | ^^^^ - | - = note: the full type name has been written to '/Users/chris/dev/rust-lang/book/listings/ch17-async-await/listing-17-30/target/debug/deps/async_await-bbd5bb8f6851cb5f.long-type-18426562901668632191.txt' - = note: consider using `--verbose` to print the full type name to the console - = help: items from traits can only be used if the trait is in scope + --> src/main.rs:10:40 + | +10 | while let Some(value) = stream.next().await { + | ^^^^ + | + = note: the full type name has been written to 'file:///projects/async_await/target/debug/deps/async_await-9de943556a6001b8.long-type-1281356139287206597.txt' + = note: consider using `--verbose` to print the full type name to the console + = help: items from traits can only be used if the trait is in scope help: the following traits which provide `next` are implemented but not in scope; perhaps you want to import one of them - | -1 + use futures_util::stream::stream::StreamExt; - | -1 + use std::iter::Iterator; - | -1 + use std::str::pattern::Searcher; - | -1 + use trpl::StreamExt; - | + | +1 + use crate::trpl::StreamExt; + | +1 + use futures_util::stream::stream::StreamExt; + | +1 + use std::iter::Iterator; + | +1 + use std::str::pattern::Searcher; + | help: there is a method `try_next` with a similar name - | -8 | while let Some(value) = stream.try_next().await { - | ~~~~~~~~ - -For more information about this error, try `rustc --explain E0599`. + | +10 | while let Some(value) = stream.try_next().await { + | ~~~~~~~~ ``` As the output suggests, the reason for the compiler error is that we need the @@ -231,7 +228,7 @@ Now our code has a much more interesting result! Between every other pair of messages, we see an error reported: `Problem: Elapsed(())`. @@ -395,7 +392,7 @@ This is the inherent “laziness” of Rust’s futures at work again, allowing choose our performance characteristics. diff --git a/src/ch17-05-traits-for-async.md b/src/ch17-05-traits-for-async.md index 836c73b617..1b7b23b7d8 100644 --- a/src/ch17-05-traits-for-async.md +++ b/src/ch17-05-traits-for-async.md @@ -115,36 +115,33 @@ it is not yet ready. ### Pinning and the Pin and Unpin Traits -When we introduced the idea of pinning while working on Listing 17-17, we ran +When we introduced the idea of pinning while working on Listing 17-16, we ran into a very gnarly error message. Here is the relevant part of it again: ```text -error[E0277]: `{async block@src/main.rs:8:23: 20:10}` cannot be unpinned - --> src/main.rs:46:33 +error[E0277]: `{async block@src/main.rs:10:23: 10:33}` cannot be unpinned + --> src/main.rs:48:33 | -46 | trpl::join_all(futures).await; - | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:8:23: 20:10}`, which is required by `Box<{async block@src/main.rs:8:23: 20:10}>: std::future::Future` +48 | trpl::join_all(futures).await; + | ^^^^^ the trait `Unpin` is not implemented for `{async block@src/main.rs:10:23: 10:33}`, which is required by `Box<{async block@src/main.rs:10:23: 10:33}>: Future` | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope - = note: required for `Box<{async block@src/main.rs:8:23: 20:10}>` to implement `std::future::Future` -note: required by a bound in `JoinAll` - --> /Users/chris/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 + = note: required for `Box<{async block@src/main.rs:10:23: 10:33}>` to implement `Future` +note: required by a bound in `futures_util::future::join_all::JoinAll` + --> file:///home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-util-0.3.30/src/future/join_all.rs:29:8 | 27 | pub struct JoinAll | ------- required by a bound in this struct 28 | where 29 | F: Future, | ^^^^^^ required by this bound in `JoinAll` - -Some errors have detailed explanations: E0277, E0308. -For more information about an error, try `rustc --explain E0277`. ``` When we read this error message carefully, it not only tells us that we need to diff --git a/src/ch21-02-multithreaded.md b/src/ch21-02-multithreaded.md index f8043fc30f..788ee54688 100644 --- a/src/ch21-02-multithreaded.md +++ b/src/ch21-02-multithreaded.md @@ -619,28 +619,28 @@ Can't automate because the output depends on making requests ```console $ cargo run Compiling hello v0.1.0 (file:///projects/hello) -warning: field is never read: `workers` +warning: field `workers` is never read --> src/lib.rs:7:5 | +6 | pub struct ThreadPool { + | ---------- field in this struct 7 | workers: Vec, - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default -warning: field is never read: `id` +warning: fields `id` and `thread` are never read --> src/lib.rs:48:5 | +47 | struct Worker { + | ------ fields in this struct 48 | id: usize, - | ^^^^^^^^^ - -warning: field is never read: `thread` - --> src/lib.rs:49:5 - | + | ^^ 49 | thread: thread::JoinHandle<()>, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^ -warning: `hello` (lib) generated 3 warnings - Finished dev [unoptimized + debuginfo] target(s) in 1.40s +warning: `hello` (lib) generated 2 warnings + Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.91s Running `target/debug/hello` Worker 0 got a job; executing. Worker 2 got a job; executing. diff --git a/src/ch21-03-graceful-shutdown-and-cleanup.md b/src/ch21-03-graceful-shutdown-and-cleanup.md index 9d2a02e54f..b60278240a 100644 --- a/src/ch21-03-graceful-shutdown-and-cleanup.md +++ b/src/ch21-03-graceful-shutdown-and-cleanup.md @@ -182,7 +182,7 @@ Can't automate because the output depends on making requests ```console $ cargo run Compiling hello v0.1.0 (file:///projects/hello) - Finished dev [unoptimized + debuginfo] target(s) in 1.0s + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.41s Running `target/debug/hello` Worker 0 got a job; executing. Shutting down.