From bb9c967e93caffafca23e786524e3df57475e6ac Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 25 Feb 2025 17:44:42 +0000 Subject: [PATCH 1/6] Update to Rust 2024 edition. --- .github/workflows/build.yml | 3 +++ .github/workflows/publish.yml | 3 +++ book.toml | 2 +- mdbook-course/Cargo.toml | 2 +- mdbook-exerciser/Cargo.toml | 2 +- src/android/testing/Cargo.toml | 2 +- src/bare-metal/alloc-example/Cargo.toml | 2 +- src/bare-metal/alloc-example/src/main.rs | 5 +++-- src/bare-metal/aps/examples/Cargo.toml | 2 +- src/bare-metal/aps/examples/build.rs | 7 +++++-- src/bare-metal/microcontrollers/examples/Cargo.toml | 2 +- src/bare-metal/useful-crates/allocator-example/Cargo.toml | 2 +- src/bare-metal/useful-crates/zerocopy-example/Cargo.toml | 2 +- src/borrowing/Cargo.toml | 2 +- src/concurrency/async-exercises/chat-async/Cargo.toml | 2 +- src/concurrency/async-exercises/dining-philosophers.md | 2 +- src/concurrency/sync-exercises/Cargo.toml | 2 +- src/concurrency/sync-exercises/dining-philosophers.md | 2 +- src/concurrency/sync-exercises/link-checker.md | 2 +- src/control-flow-basics/Cargo.toml | 2 +- src/error-handling/Cargo.toml | 2 +- src/exercises/bare-metal/compass/Cargo.toml | 2 +- src/exercises/bare-metal/rtc/Cargo.toml | 2 +- src/exercises/bare-metal/rtc/build.rs | 7 +++++-- src/generics/Cargo.toml | 2 +- src/iterators/Cargo.toml | 2 +- src/lifetimes/Cargo.toml | 4 ++-- src/memory-management/Cargo.toml | 2 +- src/methods-and-traits/Cargo.toml | 2 +- src/modules/Cargo.toml | 2 +- src/pattern-matching/Cargo.toml | 2 +- src/references/Cargo.toml | 2 +- src/smart-pointers/Cargo.toml | 2 +- src/std-traits/Cargo.toml | 2 +- src/std-types/Cargo.toml | 2 +- src/testing/Cargo.toml | 2 +- src/tuples-and-arrays/Cargo.toml | 2 +- src/types-and-values/Cargo.toml | 2 +- src/unsafe-rust/Cargo.toml | 4 ++-- src/user-defined-types/Cargo.toml | 2 +- theme/book.js | 2 ++ xtask/src/main.rs | 6 +++--- 42 files changed, 61 insertions(+), 46 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1aa0ff30f6e7..1299d487c0c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -206,6 +206,9 @@ jobs: with: fetch-depth: 0 + - name: Update Rust + run: rustup update + - name: Setup Rust cache uses: ./.github/workflows/setup-rust-cache diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 53d547cfc0f2..da9bab8e0fd3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,6 +33,9 @@ jobs: with: fetch-depth: 0 # We need the full history for build.sh below. + - name: Update Rust + run: rustup update + - name: Setup Rust cache uses: ./.github/workflows/setup-rust-cache diff --git a/book.toml b/book.toml index ebdf6d965973..057e39389386 100644 --- a/book.toml +++ b/book.toml @@ -5,7 +5,7 @@ src = "src" title = "Comprehensive Rust 🦀" [rust] -edition = "2021" +edition = "2024" [build] extra-watch-dirs = ["po", "third_party"] diff --git a/mdbook-course/Cargo.toml b/mdbook-course/Cargo.toml index 76fa4b3e458f..9f49291f33c2 100644 --- a/mdbook-course/Cargo.toml +++ b/mdbook-course/Cargo.toml @@ -2,7 +2,7 @@ name = "mdbook-course" version = "0.1.0" authors = ["Dustin Mitchell "] -edition = "2021" +edition = "2024" license = "Apache-2.0" publish = false repository = "https://github.com/google/comprehensive-rust" diff --git a/mdbook-exerciser/Cargo.toml b/mdbook-exerciser/Cargo.toml index e60f2c73f077..57797d668f20 100644 --- a/mdbook-exerciser/Cargo.toml +++ b/mdbook-exerciser/Cargo.toml @@ -2,7 +2,7 @@ name = "mdbook-exerciser" version = "0.1.0" authors = ["Andrew Walbran "] -edition = "2021" +edition = "2024" license = "Apache-2.0" repository = "https://github.com/google/comprehensive-rust" description = "A tool for extracting starter code for exercises from Markdown files." diff --git a/src/android/testing/Cargo.toml b/src/android/testing/Cargo.toml index 8b540e81f74f..cb2309c943f1 100644 --- a/src/android/testing/Cargo.toml +++ b/src/android/testing/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "android-testing" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[example]] diff --git a/src/bare-metal/alloc-example/Cargo.toml b/src/bare-metal/alloc-example/Cargo.toml index 5b83e2c9fa65..a8dc51aac3fc 100644 --- a/src/bare-metal/alloc-example/Cargo.toml +++ b/src/bare-metal/alloc-example/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "alloc-example" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/bare-metal/alloc-example/src/main.rs b/src/bare-metal/alloc-example/src/main.rs index 3e1fd664d3eb..cc3e0c84cea0 100644 --- a/src/bare-metal/alloc-example/src/main.rs +++ b/src/bare-metal/alloc-example/src/main.rs @@ -26,13 +26,14 @@ use buddy_system_allocator::LockedHeap; #[global_allocator] static HEAP_ALLOCATOR: LockedHeap<32> = LockedHeap::<32>::new(); -static mut HEAP: [u8; 65536] = [0; 65536]; +const HEAP_SIZE: usize = 65536; +static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE]; pub fn entry() { // SAFETY: `HEAP` is only used here and `entry` is only called once. unsafe { // Give the allocator some memory to allocate. - HEAP_ALLOCATOR.lock().init(HEAP.as_mut_ptr() as usize, HEAP.len()); + HEAP_ALLOCATOR.lock().init(&raw mut HEAP as usize, HEAP_SIZE); } // Now we can do things that require heap allocation. diff --git a/src/bare-metal/aps/examples/Cargo.toml b/src/bare-metal/aps/examples/Cargo.toml index 7bd1a5b17c01..69ac09adef73 100644 --- a/src/bare-metal/aps/examples/Cargo.toml +++ b/src/bare-metal/aps/examples/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "ap-examples" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/bare-metal/aps/examples/build.rs b/src/bare-metal/aps/examples/build.rs index 2a7372b42070..adad5ed59cad 100644 --- a/src/bare-metal/aps/examples/build.rs +++ b/src/bare-metal/aps/examples/build.rs @@ -16,8 +16,11 @@ use cc::Build; use std::env; fn main() { - env::set_var("CROSS_COMPILE", "aarch64-none-elf"); - env::set_var("CC", "clang"); + // SAFETY: The build script is single-threaded. + unsafe { + env::set_var("CROSS_COMPILE", "aarch64-none-elf"); + env::set_var("CC", "clang"); + } Build::new() .file("entry.S") diff --git a/src/bare-metal/microcontrollers/examples/Cargo.toml b/src/bare-metal/microcontrollers/examples/Cargo.toml index 021848a92464..876f8f6fb60b 100644 --- a/src/bare-metal/microcontrollers/examples/Cargo.toml +++ b/src/bare-metal/microcontrollers/examples/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "microcontroller-examples" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/bare-metal/useful-crates/allocator-example/Cargo.toml b/src/bare-metal/useful-crates/allocator-example/Cargo.toml index 40fbe5ff0842..38031194295a 100644 --- a/src/bare-metal/useful-crates/allocator-example/Cargo.toml +++ b/src/bare-metal/useful-crates/allocator-example/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "allocator-example" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/bare-metal/useful-crates/zerocopy-example/Cargo.toml b/src/bare-metal/useful-crates/zerocopy-example/Cargo.toml index d1a4434410e3..4fed1d9c8be8 100644 --- a/src/bare-metal/useful-crates/zerocopy-example/Cargo.toml +++ b/src/bare-metal/useful-crates/zerocopy-example/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "zerocopy-example" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/borrowing/Cargo.toml b/src/borrowing/Cargo.toml index df8e7ff941fb..38495770cdf1 100644 --- a/src/borrowing/Cargo.toml +++ b/src/borrowing/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "borrowing" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/src/concurrency/async-exercises/chat-async/Cargo.toml b/src/concurrency/async-exercises/chat-async/Cargo.toml index 05e4a6a7ebe0..29a591f0153f 100644 --- a/src/concurrency/async-exercises/chat-async/Cargo.toml +++ b/src/concurrency/async-exercises/chat-async/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "chat-async" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] futures-util = { version = "0.3.31", features = ["sink"] } diff --git a/src/concurrency/async-exercises/dining-philosophers.md b/src/concurrency/async-exercises/dining-philosophers.md index 6151116e0808..1af88c1d6a48 100644 --- a/src/concurrency/async-exercises/dining-philosophers.md +++ b/src/concurrency/async-exercises/dining-philosophers.md @@ -45,7 +45,7 @@ can use the following `Cargo.toml`: [package] name = "dining-philosophers-async-dine" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] tokio = { version = "1.26.0", features = ["sync", "time", "macros", "rt-multi-thread"] } diff --git a/src/concurrency/sync-exercises/Cargo.toml b/src/concurrency/sync-exercises/Cargo.toml index 7ea21633803d..69a66347710a 100644 --- a/src/concurrency/sync-exercises/Cargo.toml +++ b/src/concurrency/sync-exercises/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sync-exercises" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/concurrency/sync-exercises/dining-philosophers.md b/src/concurrency/sync-exercises/dining-philosophers.md index b5e9429ead8a..ccf0a644d3ea 100644 --- a/src/concurrency/sync-exercises/dining-philosophers.md +++ b/src/concurrency/sync-exercises/dining-philosophers.md @@ -51,7 +51,7 @@ You can use the following `Cargo.toml`: [package] name = "dining-philosophers" version = "0.1.0" -edition = "2021" +edition = "2024" ```
diff --git a/src/concurrency/sync-exercises/link-checker.md b/src/concurrency/sync-exercises/link-checker.md index 46dc2c341c34..13744c2f0d59 100644 --- a/src/concurrency/sync-exercises/link-checker.md +++ b/src/concurrency/sync-exercises/link-checker.md @@ -34,7 +34,7 @@ The `cargo add` calls will update the `Cargo.toml` file to look like this: [package] name = "link-checker" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/control-flow-basics/Cargo.toml b/src/control-flow-basics/Cargo.toml index 8ea0c0bd588b..4885f71bcaed 100644 --- a/src/control-flow-basics/Cargo.toml +++ b/src/control-flow-basics/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "control-flow-basics" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/error-handling/Cargo.toml b/src/error-handling/Cargo.toml index 639cfe815fa3..f7f8e2bc3b9a 100644 --- a/src/error-handling/Cargo.toml +++ b/src/error-handling/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "error-handling" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/exercises/bare-metal/compass/Cargo.toml b/src/exercises/bare-metal/compass/Cargo.toml index 9098c1920e10..d0347bc15b2f 100644 --- a/src/exercises/bare-metal/compass/Cargo.toml +++ b/src/exercises/bare-metal/compass/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "compass" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/exercises/bare-metal/rtc/Cargo.toml b/src/exercises/bare-metal/rtc/Cargo.toml index 73b93afa8448..d005128fa986 100644 --- a/src/exercises/bare-metal/rtc/Cargo.toml +++ b/src/exercises/bare-metal/rtc/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "rtc" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] diff --git a/src/exercises/bare-metal/rtc/build.rs b/src/exercises/bare-metal/rtc/build.rs index 5fc5a872e4b6..457d15d9872a 100644 --- a/src/exercises/bare-metal/rtc/build.rs +++ b/src/exercises/bare-metal/rtc/build.rs @@ -16,8 +16,11 @@ use cc::Build; use std::env; fn main() { - env::set_var("CROSS_COMPILE", "aarch64-none-elf"); - env::set_var("CC", "clang"); + // SAFETY: The build script is single-threaded. + unsafe { + env::set_var("CROSS_COMPILE", "aarch64-none-elf"); + env::set_var("CC", "clang"); + } Build::new() .file("entry.S") diff --git a/src/generics/Cargo.toml b/src/generics/Cargo.toml index 80a38c250117..cc851e2a267b 100644 --- a/src/generics/Cargo.toml +++ b/src/generics/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "generics" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/src/iterators/Cargo.toml b/src/iterators/Cargo.toml index c379e76d4d3c..2ed59362049d 100644 --- a/src/iterators/Cargo.toml +++ b/src/iterators/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "iterators" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/src/lifetimes/Cargo.toml b/src/lifetimes/Cargo.toml index 9f9921768ae0..44f738202cfe 100644 --- a/src/lifetimes/Cargo.toml +++ b/src/lifetimes/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "lifetimes" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] -thiserror = "*" +thiserror = "2.0.11" [lib] name = "protobuf" diff --git a/src/memory-management/Cargo.toml b/src/memory-management/Cargo.toml index d3d6e0c8b8b2..49cc396bc9ce 100644 --- a/src/memory-management/Cargo.toml +++ b/src/memory-management/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "memory-management" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/methods-and-traits/Cargo.toml b/src/methods-and-traits/Cargo.toml index b04dbde9469d..781a640a6acb 100644 --- a/src/methods-and-traits/Cargo.toml +++ b/src/methods-and-traits/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "methods-and-traits" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/modules/Cargo.toml b/src/modules/Cargo.toml index a86b03865f40..df29ef8971c6 100644 --- a/src/modules/Cargo.toml +++ b/src/modules/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "modules" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/pattern-matching/Cargo.toml b/src/pattern-matching/Cargo.toml index 35fb9d8b07b9..0af7fa687925 100644 --- a/src/pattern-matching/Cargo.toml +++ b/src/pattern-matching/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pattern-matching" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/src/references/Cargo.toml b/src/references/Cargo.toml index 279efb39326b..adb49a79eae4 100644 --- a/src/references/Cargo.toml +++ b/src/references/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "references" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/smart-pointers/Cargo.toml b/src/smart-pointers/Cargo.toml index c5262152af91..edb7408fe499 100644 --- a/src/smart-pointers/Cargo.toml +++ b/src/smart-pointers/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "smart-pointers" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/src/std-traits/Cargo.toml b/src/std-traits/Cargo.toml index bc9dec7f5271..b0a496e5694a 100644 --- a/src/std-traits/Cargo.toml +++ b/src/std-traits/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "std-traits" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lib] diff --git a/src/std-types/Cargo.toml b/src/std-types/Cargo.toml index fe46d703726b..bcfaadc5bec5 100644 --- a/src/std-types/Cargo.toml +++ b/src/std-types/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "std-types" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/testing/Cargo.toml b/src/testing/Cargo.toml index c6abcf21018a..e5f59ab55005 100644 --- a/src/testing/Cargo.toml +++ b/src/testing/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "testing" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [lints.rust] diff --git a/src/tuples-and-arrays/Cargo.toml b/src/tuples-and-arrays/Cargo.toml index 186737317d7b..8068fc014bde 100644 --- a/src/tuples-and-arrays/Cargo.toml +++ b/src/tuples-and-arrays/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tuples-and-arrays" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/types-and-values/Cargo.toml b/src/types-and-values/Cargo.toml index 4603dd990a9c..112fa7eb97a8 100644 --- a/src/types-and-values/Cargo.toml +++ b/src/types-and-values/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "types-and-values" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/src/unsafe-rust/Cargo.toml b/src/unsafe-rust/Cargo.toml index d846404d909d..9571045369cf 100644 --- a/src/unsafe-rust/Cargo.toml +++ b/src/unsafe-rust/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "unsafe-rust" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [dependencies] -tempfile = "*" +tempfile = "3.17.1" [[bin]] name = "listdir" diff --git a/src/user-defined-types/Cargo.toml b/src/user-defined-types/Cargo.toml index 10655db330e1..8f44b4c49c53 100644 --- a/src/user-defined-types/Cargo.toml +++ b/src/user-defined-types/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "user-defined-types" version = "0.1.0" -edition = "2021" +edition = "2024" publish = false [[bin]] diff --git a/theme/book.js b/theme/book.js index 66e86989eb5f..7d53c7352d0a 100644 --- a/theme/book.js +++ b/theme/book.js @@ -137,6 +137,8 @@ function playground_text(playground, hidden = true) { edition = "2018"; } else if(classes.contains("edition2021")) { edition = "2021"; + } else if(classes.contains("edition2024")) { + edition = "2024"; } var params = { backtrace: true, diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 954b22dfb04c..aacb1ffba395 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -57,10 +57,10 @@ fn install_tools() -> Result<()> { let install_args = vec![ // The --locked flag is important for reproducible builds. It also // avoids breakage due to skews between mdbook and mdbook-svgbob. - vec!["mdbook", "--locked", "--version", "0.4.44"], - vec!["mdbook-svgbob", "--locked", "--version", "0.2.1"], + vec!["mdbook", "--locked", "--version", "0.4.48"], + vec!["mdbook-svgbob", "--locked", "--version", "0.2.2"], vec!["mdbook-pandoc", "--locked", "--version", "0.9.3"], - vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.5"], + vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.6"], vec!["i18n-report", "--locked", "--version", "0.2.0"], // These packages are located in this repository vec!["--path", "mdbook-exerciser", "--locked"], From 4f8099a230648c286c49b457a3daeac578616aeb Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 25 Feb 2025 18:29:17 +0000 Subject: [PATCH 2/6] Update text to mention 2024 edition. --- src/cargo/rust-ecosystem.md | 4 ++-- src/unsafe-rust/mutable-static.md | 20 +++++++++++++------- src/unsafe-rust/unsafe-functions/rust.md | 18 +++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/cargo/rust-ecosystem.md b/src/cargo/rust-ecosystem.md index c193a5a6642c..e4de7658fbbf 100644 --- a/src/cargo/rust-ecosystem.md +++ b/src/cargo/rust-ecosystem.md @@ -32,8 +32,8 @@ Key points: - Dependencies can also be resolved from alternative [registries], git, folders, and more. -- Rust also has [editions]: the current edition is Rust 2021. Previous editions - were Rust 2015 and Rust 2018. +- Rust also has [editions]: the current edition is Rust 2024. Previous editions + were Rust 2015, Rust 2018 and Rust 2021. - The editions are allowed to make backwards incompatible changes to the language. diff --git a/src/unsafe-rust/mutable-static.md b/src/unsafe-rust/mutable-static.md index 1d3e7baaec05..b94fa4c319e2 100644 --- a/src/unsafe-rust/mutable-static.md +++ b/src/unsafe-rust/mutable-static.md @@ -22,6 +22,7 @@ static mut COUNTER: u32 = 0; fn add_to_counter(inc: u32) { // SAFETY: There are no other threads which could be accessing `COUNTER`. + #[allow(static_mut_refs)] unsafe { COUNTER += inc; } @@ -31,6 +32,7 @@ fn main() { add_to_counter(42); // SAFETY: There are no other threads which could be accessing `COUNTER`. + #[allow(static_mut_refs)] unsafe { println!("COUNTER: {COUNTER}"); } @@ -40,12 +42,16 @@ fn main() {
- The program here is safe because it is single-threaded. However, the Rust - compiler is conservative and will assume the worst. Try removing the `unsafe` - and see how the compiler explains that it is undefined behavior to mutate a - static from multiple threads. - -- Using a mutable static is generally a bad idea, but there are some cases where - it might make sense in low-level `no_std` code, such as implementing a heap - allocator or working with some C APIs. + compiler reasons about functions individually so can't assume that. Try + removing the `unsafe` and see how the compiler explains that it is undefined + behavior to access a mutable static from multiple threads. +- Rust 2024 edition goes further and makes accessing a mutable static by + reference an error by default. We work around this in the example with + `#[allow(static_mut_refs)]`. Don't do this. +- Using a mutable static is almost always a bad idea, you should use interior + mutability instead. +- There are some cases where it might be necessary in low-level `no_std` code, + such as implementing a heap allocator or working with some C APIs. In this + case you should use pointers rather than references.
diff --git a/src/unsafe-rust/unsafe-functions/rust.md b/src/unsafe-rust/unsafe-functions/rust.md index 7d6bb01bbccc..2473fc7ec0ef 100644 --- a/src/unsafe-rust/unsafe-functions/rust.md +++ b/src/unsafe-rust/unsafe-functions/rust.md @@ -11,9 +11,13 @@ preconditions to avoid undefined behaviour. /// The pointers must be valid, properly aligned, and not otherwise accessed for /// the duration of the function call. unsafe fn swap(a: *mut u8, b: *mut u8) { - let temp = *a; - *a = *b; - *b = temp; + // SAFETY: Our caller promised that the pointers are valid, properly aligned + // and have no other access. + unsafe { + let temp = *a; + *a = *b; + *b = temp; + } } fn main() { @@ -35,9 +39,9 @@ fn main() { We wouldn't actually use pointers for a `swap` function --- it can be done safely with references. -Note that unsafe code is allowed within an unsafe function without an `unsafe` -block. We can prohibit this with `#[deny(unsafe_op_in_unsafe_fn)]`. Try adding -it and see what happens. This will -[change in the 2024 Rust edition](https://github.com/rust-lang/rust/issues/120535). +Note that Rust 2021 and earlier allow unsafe code within an unsafe function +without an `unsafe` block. This changed in the 2024 edition. We can prohibit it +in older editions with `#[deny(unsafe_op_in_unsafe_fn)]`. Try adding it and see +what happens.
From 4f94a87681d4ddd3d55cc22057da0055be161eba Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Thu, 27 Feb 2025 15:03:50 +0000 Subject: [PATCH 3/6] cargo fmt --- dprint.json | 2 +- mdbook-course/src/course.rs | 14 ++++++-------- mdbook-exerciser/src/lib.rs | 2 +- mdbook-exerciser/src/main.rs | 2 +- .../async-exercises/chat-async/src/bin/client.rs | 2 +- .../async-exercises/chat-async/src/bin/server.rs | 2 +- .../sync-exercises/dining-philosophers.rs | 2 +- src/concurrency/sync-exercises/link-checker.rs | 4 ++-- src/tuples-and-arrays/exercise.rs | 4 ++-- third_party/cxx/blobstore/build.rs | 3 ++- xtask/src/main.rs | 3 ++- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/dprint.json b/dprint.json index 244ce75310d8..d47cd41ce9fe 100644 --- a/dprint.json +++ b/dprint.json @@ -9,7 +9,7 @@ "command": "yapf3", "exts": ["py"] }, { - "command": "rustup run stable rustfmt --edition 2021", + "command": "rustup run stable rustfmt --edition 2024", "exts": ["rs"] }] }, diff --git a/mdbook-course/src/course.rs b/mdbook-course/src/course.rs index 354b7e2419e1..ec9fa3e7042a 100644 --- a/mdbook-course/src/course.rs +++ b/mdbook-course/src/course.rs @@ -35,8 +35,8 @@ //! item becomes the first slide in that segment. Any other sub-items of the //! top-level item are treated as further slides in the same segment. -use crate::frontmatter::{split_frontmatter, Frontmatter}; -use crate::markdown::{duration, Table}; +use crate::frontmatter::{Frontmatter, split_frontmatter}; +use crate::markdown::{Table, duration}; use mdbook::book::{Book, BookItem, Chapter}; use std::fmt::Write; use std::path::PathBuf; @@ -318,7 +318,9 @@ impl Session { } format!( "Including {BREAK_DURATION} minute breaks, this session should take about {}. It contains:\n\n{}", - duration(self.minutes()), segments) + duration(self.minutes()), + segments + ) } /// Return the total duration of this session. @@ -337,11 +339,7 @@ impl Session { /// /// This includes breaks between segments. pub fn target_minutes(&self) -> u64 { - if self.target_minutes > 0 { - self.target_minutes - } else { - self.minutes() - } + if self.target_minutes > 0 { self.target_minutes } else { self.minutes() } } } diff --git a/mdbook-exerciser/src/lib.rs b/mdbook-exerciser/src/lib.rs index 8f6040d675d0..c51bc017ef65 100644 --- a/mdbook-exerciser/src/lib.rs +++ b/mdbook-exerciser/src/lib.rs @@ -14,7 +14,7 @@ use log::{info, trace}; use pulldown_cmark::{Event, Parser, Tag, TagEnd}; -use std::fs::{create_dir_all, File}; +use std::fs::{File, create_dir_all}; use std::io::Write; use std::path::Path; diff --git a/mdbook-exerciser/src/main.rs b/mdbook-exerciser/src/main.rs index 57332ca290e5..9c2e14e4075a 100644 --- a/mdbook-exerciser/src/main.rs +++ b/mdbook-exerciser/src/main.rs @@ -14,9 +14,9 @@ use anyhow::Context; use log::trace; +use mdbook::BookItem; use mdbook::book::Book; use mdbook::renderer::RenderContext; -use mdbook::BookItem; use mdbook_exerciser::process; use std::fs::{create_dir, remove_dir_all}; use std::io::stdin; diff --git a/src/concurrency/async-exercises/chat-async/src/bin/client.rs b/src/concurrency/async-exercises/chat-async/src/bin/client.rs index bc912a28b376..01e0c8fd11c4 100644 --- a/src/concurrency/async-exercises/chat-async/src/bin/client.rs +++ b/src/concurrency/async-exercises/chat-async/src/bin/client.rs @@ -14,8 +14,8 @@ // ANCHOR: solution // ANCHOR: setup -use futures_util::stream::StreamExt; use futures_util::SinkExt; +use futures_util::stream::StreamExt; use http::Uri; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio_websockets::{ClientBuilder, Message}; diff --git a/src/concurrency/async-exercises/chat-async/src/bin/server.rs b/src/concurrency/async-exercises/chat-async/src/bin/server.rs index 46aedbc2b734..57bc1f7b0d45 100644 --- a/src/concurrency/async-exercises/chat-async/src/bin/server.rs +++ b/src/concurrency/async-exercises/chat-async/src/bin/server.rs @@ -19,7 +19,7 @@ use futures_util::stream::StreamExt; use std::error::Error; use std::net::SocketAddr; use tokio::net::{TcpListener, TcpStream}; -use tokio::sync::broadcast::{channel, Sender}; +use tokio::sync::broadcast::{Sender, channel}; use tokio_websockets::{Message, ServerBuilder, WebSocketStream}; // ANCHOR_END: setup diff --git a/src/concurrency/sync-exercises/dining-philosophers.rs b/src/concurrency/sync-exercises/dining-philosophers.rs index 6900acdb60f1..d6667ecb1731 100644 --- a/src/concurrency/sync-exercises/dining-philosophers.rs +++ b/src/concurrency/sync-exercises/dining-philosophers.rs @@ -14,7 +14,7 @@ // ANCHOR: solution // ANCHOR: Philosopher -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{Arc, Mutex, mpsc}; use std::thread; use std::time::Duration; diff --git a/src/concurrency/sync-exercises/link-checker.rs b/src/concurrency/sync-exercises/link-checker.rs index 442add2e003e..eee665cbe9a7 100644 --- a/src/concurrency/sync-exercises/link-checker.rs +++ b/src/concurrency/sync-exercises/link-checker.rs @@ -13,12 +13,12 @@ // limitations under the License. // ANCHOR: solution -use std::sync::{mpsc, Arc, Mutex}; +use std::sync::{Arc, Mutex, mpsc}; use std::thread; // ANCHOR: setup -use reqwest::blocking::Client; use reqwest::Url; +use reqwest::blocking::Client; use scraper::{Html, Selector}; use thiserror::Error; diff --git a/src/tuples-and-arrays/exercise.rs b/src/tuples-and-arrays/exercise.rs index a84caf85571b..e9c7d6651d36 100644 --- a/src/tuples-and-arrays/exercise.rs +++ b/src/tuples-and-arrays/exercise.rs @@ -40,8 +40,8 @@ fn main() { // ANCHOR_END: main // ANCHOR_END: solution -// This test does not appear in the exercise, as this is very early in the course, but it verifies -// that the solution is correct. +// This test does not appear in the exercise, as this is very early in the +// course, but it verifies that the solution is correct. #[test] fn test_transpose() { let matrix = [ diff --git a/third_party/cxx/blobstore/build.rs b/third_party/cxx/blobstore/build.rs index 411581158b98..c3b0031e52b9 100644 --- a/third_party/cxx/blobstore/build.rs +++ b/third_party/cxx/blobstore/build.rs @@ -1,6 +1,7 @@ fn main() { // Find target directory, either from CARGO_TARGET_DIR or in-tree if unset. - let mut src_dir = std::env::var_os("CARGO_TARGET_DIR").unwrap_or("../../../target".into()); + let mut src_dir = + std::env::var_os("CARGO_TARGET_DIR").unwrap_or("../../../target".into()); src_dir.push("/cxxbridge/demo/src"); cxx_build::bridge("src/main.rs") diff --git a/xtask/src/main.rs b/xtask/src/main.rs index aacb1ffba395..cf818a36dcea 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -21,7 +21,8 @@ use anyhow::{anyhow, Ok, Result}; use clap::Parser; -use std::{env, process::Command}; +use std::env; +use std::process::Command; fn main() -> Result<()> { if let Err(e) = execute_task() { From e56715dd17565f9f1025bd98793d2ee2e9e97818 Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 15 Apr 2025 13:37:01 +0100 Subject: [PATCH 4/6] dprint fmt --- src/android/interoperability/java/src/lib.rs | 2 +- src/bare-metal/aps/examples/src/exceptions.rs | 2 +- .../aps/examples/src/main_improved.rs | 2 +- src/bare-metal/aps/examples/src/main_logger.rs | 4 ++-- .../aps/examples/src/main_minimal.rs | 2 +- .../microcontrollers/examples/src/bin/hal.rs | 2 +- src/bare-metal/useful-crates/tinyvec.md | 2 +- src/closures/capturing.md | 6 +----- src/concurrency/async-control-flow/select.md | 2 +- .../async-exercises/dining-philosophers.rs | 2 +- src/concurrency/async-pitfalls/async-traits.md | 2 +- src/concurrency/async-pitfalls/pin.md | 2 +- src/control-flow-basics/functions.md | 6 +----- src/error-handling/anyhow.md | 2 +- src/exercises/bare-metal/compass/src/main.rs | 2 +- src/exercises/bare-metal/rtc/src/exceptions.rs | 2 +- src/exercises/bare-metal/rtc/src/main.rs | 6 +++--- src/generics/generic-functions.md | 18 +++--------------- src/lifetimes/lifetime-annotations.md | 6 +----- src/user-defined-types/const.md | 6 +----- xtask/src/main.rs | 2 +- 21 files changed, 26 insertions(+), 54 deletions(-) diff --git a/src/android/interoperability/java/src/lib.rs b/src/android/interoperability/java/src/lib.rs index 5bf2377cab7a..fa951253bcac 100644 --- a/src/android/interoperability/java/src/lib.rs +++ b/src/android/interoperability/java/src/lib.rs @@ -15,9 +15,9 @@ // ANCHOR: hello //! Rust <-> Java FFI demo. +use jni::JNIEnv; use jni::objects::{JClass, JString}; use jni::sys::jstring; -use jni::JNIEnv; /// HelloWorld::hello method implementation. // SAFETY: There is no other global function of this name. diff --git a/src/bare-metal/aps/examples/src/exceptions.rs b/src/bare-metal/aps/examples/src/exceptions.rs index 2d5aa0cb5e8e..cc52a1fe3379 100644 --- a/src/bare-metal/aps/examples/src/exceptions.rs +++ b/src/bare-metal/aps/examples/src/exceptions.rs @@ -14,8 +14,8 @@ // ANCHOR: exceptions use log::error; -use smccc::psci::system_off; use smccc::Hvc; +use smccc::psci::system_off; // SAFETY: There is no other global function of this name. #[unsafe(no_mangle)] diff --git a/src/bare-metal/aps/examples/src/main_improved.rs b/src/bare-metal/aps/examples/src/main_improved.rs index 90996e3a65cc..0e262da0f9ef 100644 --- a/src/bare-metal/aps/examples/src/main_improved.rs +++ b/src/bare-metal/aps/examples/src/main_improved.rs @@ -23,8 +23,8 @@ use crate::pl011::Uart; use core::fmt::Write; use core::panic::PanicInfo; use log::error; -use smccc::psci::system_off; use smccc::Hvc; +use smccc::psci::system_off; /// Base address of the primary PL011 UART. const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _; diff --git a/src/bare-metal/aps/examples/src/main_logger.rs b/src/bare-metal/aps/examples/src/main_logger.rs index e6abb1868c4e..b90e5668ee69 100644 --- a/src/bare-metal/aps/examples/src/main_logger.rs +++ b/src/bare-metal/aps/examples/src/main_logger.rs @@ -22,9 +22,9 @@ mod pl011; use crate::pl011::Uart; use core::panic::PanicInfo; -use log::{error, info, LevelFilter}; -use smccc::psci::system_off; +use log::{LevelFilter, error, info}; use smccc::Hvc; +use smccc::psci::system_off; /// Base address of the primary PL011 UART. const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _; diff --git a/src/bare-metal/aps/examples/src/main_minimal.rs b/src/bare-metal/aps/examples/src/main_minimal.rs index 24c2d5f3b12e..a85423374586 100644 --- a/src/bare-metal/aps/examples/src/main_minimal.rs +++ b/src/bare-metal/aps/examples/src/main_minimal.rs @@ -23,8 +23,8 @@ use crate::pl011_minimal::Uart; use core::fmt::Write; use core::panic::PanicInfo; use log::error; -use smccc::psci::system_off; use smccc::Hvc; +use smccc::psci::system_off; /// Base address of the primary PL011 UART. const PL011_BASE_ADDRESS: *mut u8 = 0x900_0000 as _; diff --git a/src/bare-metal/microcontrollers/examples/src/bin/hal.rs b/src/bare-metal/microcontrollers/examples/src/bin/hal.rs index 8e6356fb3b43..3b2f05d02b70 100644 --- a/src/bare-metal/microcontrollers/examples/src/bin/hal.rs +++ b/src/bare-metal/microcontrollers/examples/src/bin/hal.rs @@ -20,7 +20,7 @@ extern crate panic_halt as _; use cortex_m_rt::entry; use embedded_hal::digital::OutputPin; -use nrf52833_hal::gpio::{p0, Level}; +use nrf52833_hal::gpio::{Level, p0}; use nrf52833_hal::pac::Peripherals; #[entry] diff --git a/src/bare-metal/useful-crates/tinyvec.md b/src/bare-metal/useful-crates/tinyvec.md index 9a96f2a2ffbe..6e74e6571ac5 100644 --- a/src/bare-metal/useful-crates/tinyvec.md +++ b/src/bare-metal/useful-crates/tinyvec.md @@ -8,7 +8,7 @@ many elements are used and panics if you try to use more than are allocated. ```rust,editable,compile_fail -use tinyvec::{array_vec, ArrayVec}; +use tinyvec::{ArrayVec, array_vec}; fn main() { let mut numbers: ArrayVec<[u32; 5]> = array_vec!(42, 66); diff --git a/src/closures/capturing.md b/src/closures/capturing.md index 024d96874c1a..1393c4a9a9b5 100644 --- a/src/closures/capturing.md +++ b/src/closures/capturing.md @@ -10,11 +10,7 @@ A closure can capture variables from the environment where it was defined. fn main() { let max_value = 5; let clamp = |v| { - if v > max_value { - max_value - } else { - v - } + if v > max_value { max_value } else { v } }; dbg!(clamp(1)); diff --git a/src/concurrency/async-control-flow/select.md b/src/concurrency/async-control-flow/select.md index e8581649f708..47908d9af0f4 100644 --- a/src/concurrency/async-control-flow/select.md +++ b/src/concurrency/async-control-flow/select.md @@ -17,7 +17,7 @@ the resulting variables. The `statement` result becomes the result of the ```rust,editable,compile_fail use tokio::sync::mpsc; -use tokio::time::{sleep, Duration}; +use tokio::time::{Duration, sleep}; #[tokio::main] async fn main() { diff --git a/src/concurrency/async-exercises/dining-philosophers.rs b/src/concurrency/async-exercises/dining-philosophers.rs index 18d1ec65956f..87caaef71940 100644 --- a/src/concurrency/async-exercises/dining-philosophers.rs +++ b/src/concurrency/async-exercises/dining-philosophers.rs @@ -15,7 +15,7 @@ // ANCHOR: solution // ANCHOR: Philosopher use std::sync::Arc; -use tokio::sync::{mpsc, Mutex}; +use tokio::sync::{Mutex, mpsc}; use tokio::time; struct Chopstick; diff --git a/src/concurrency/async-pitfalls/async-traits.md b/src/concurrency/async-pitfalls/async-traits.md index 8d5520527c6f..23f1cda9f7f2 100644 --- a/src/concurrency/async-pitfalls/async-traits.md +++ b/src/concurrency/async-pitfalls/async-traits.md @@ -22,7 +22,7 @@ with some caveats: ```rust,editable,compile_fail use async_trait::async_trait; use std::time::Instant; -use tokio::time::{sleep, Duration}; +use tokio::time::{Duration, sleep}; #[async_trait] trait Sleeper { diff --git a/src/concurrency/async-pitfalls/pin.md b/src/concurrency/async-pitfalls/pin.md index 27b70a1caaa6..722566825384 100644 --- a/src/concurrency/async-pitfalls/pin.md +++ b/src/concurrency/async-pitfalls/pin.md @@ -20,7 +20,7 @@ location. ```rust,editable,compile_fail use tokio::sync::{mpsc, oneshot}; use tokio::task::spawn; -use tokio::time::{sleep, Duration}; +use tokio::time::{Duration, sleep}; // A work item. In this case, just sleep for the given time and respond // with a message on the `respond_on` channel. diff --git a/src/control-flow-basics/functions.md b/src/control-flow-basics/functions.md index 3cd53280ff45..1dd1fea870f3 100644 --- a/src/control-flow-basics/functions.md +++ b/src/control-flow-basics/functions.md @@ -8,11 +8,7 @@ minutes: 3 ```rust,editable fn gcd(a: u32, b: u32) -> u32 { - if b > 0 { - gcd(b, a % b) - } else { - a - } + if b > 0 { gcd(b, a % b) } else { a } } fn main() { diff --git a/src/error-handling/anyhow.md b/src/error-handling/anyhow.md index fe1bcf2aeaa9..cf3c8f5f4ff7 100644 --- a/src/error-handling/anyhow.md +++ b/src/error-handling/anyhow.md @@ -15,7 +15,7 @@ writing out trait impls explicitly for custom error types. [`thiserror`]: https://docs.rs/thiserror/ ```rust,editable,compile_fail -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use std::fs; use std::io::Read; use thiserror::Error; diff --git a/src/exercises/bare-metal/compass/src/main.rs b/src/exercises/bare-metal/compass/src/main.rs index 0e7905140332..ffcb134cfdec 100644 --- a/src/exercises/bare-metal/compass/src/main.rs +++ b/src/exercises/bare-metal/compass/src/main.rs @@ -26,12 +26,12 @@ use embedded_hal::digital::InputPin; use lsm303agr::{ AccelMode, AccelOutputDataRate, Lsm303agr, MagMode, MagOutputDataRate, }; +use microbit::Board; use microbit::display::blocking::Display; use microbit::hal::twim::Twim; use microbit::hal::uarte::{Baudrate, Parity, Uarte}; use microbit::hal::{Delay, Timer}; use microbit::pac::twim0::frequency::FREQUENCY_A; -use microbit::Board; const COMPASS_SCALE: i32 = 30000; const ACCELEROMETER_SCALE: i32 = 700; diff --git a/src/exercises/bare-metal/rtc/src/exceptions.rs b/src/exercises/bare-metal/rtc/src/exceptions.rs index fa7286d2f50b..ba9cd2258332 100644 --- a/src/exercises/bare-metal/rtc/src/exceptions.rs +++ b/src/exercises/bare-metal/rtc/src/exceptions.rs @@ -14,8 +14,8 @@ use arm_gic::gicv3::GicV3; use log::{error, info, trace}; -use smccc::psci::system_off; use smccc::Hvc; +use smccc::psci::system_off; // SAFETY: There is no other global function of this name. #[unsafe(no_mangle)] diff --git a/src/exercises/bare-metal/rtc/src/main.rs b/src/exercises/bare-metal/rtc/src/main.rs index 3ab2ced5f223..f4eef29ef95b 100644 --- a/src/exercises/bare-metal/rtc/src/main.rs +++ b/src/exercises/bare-metal/rtc/src/main.rs @@ -24,16 +24,16 @@ mod pl011; mod pl031; use crate::pl031::Rtc; -use arm_gic::{irq_enable, wfi, IntId, Trigger}; +use arm_gic::{IntId, Trigger, irq_enable, wfi}; use chrono::{TimeZone, Utc}; use core::hint::spin_loop; // ANCHOR: imports use crate::pl011::Uart; use arm_gic::gicv3::GicV3; use core::panic::PanicInfo; -use log::{error, info, trace, LevelFilter}; -use smccc::psci::system_off; +use log::{LevelFilter, error, info, trace}; use smccc::Hvc; +use smccc::psci::system_off; /// Base addresses of the GICv3. const GICD_BASE_ADDRESS: *mut u64 = 0x800_0000 as _; diff --git a/src/generics/generic-functions.md b/src/generics/generic-functions.md index a18e90b16f06..b7d538abf9ac 100644 --- a/src/generics/generic-functions.md +++ b/src/generics/generic-functions.md @@ -9,11 +9,7 @@ Rust supports generics, which lets you abstract algorithms or data structures ```rust,editable fn pick(cond: bool, left: T, right: T) -> T { - if cond { - left - } else { - right - } + if cond { left } else { right } } fn main() { @@ -31,19 +27,11 @@ fn main() { ```rust fn pick_i32(cond: bool, left: i32, right: i32) -> i32 { - if cond { - left - } else { - right - } + if cond { left } else { right } } fn pick_char(cond: bool, left: char, right: char) -> char { - if cond { - left - } else { - right - } + if cond { left } else { right } } ``` diff --git a/src/lifetimes/lifetime-annotations.md b/src/lifetimes/lifetime-annotations.md index 8d8279995ec3..b80ff854098d 100644 --- a/src/lifetimes/lifetime-annotations.md +++ b/src/lifetimes/lifetime-annotations.md @@ -29,11 +29,7 @@ job. struct Point(i32, i32); fn left_most(p1: &Point, p2: &Point) -> &Point { - if p1.0 < p2.0 { - p1 - } else { - p2 - } + if p1.0 < p2.0 { p1 } else { p2 } } fn main() { diff --git a/src/user-defined-types/const.md b/src/user-defined-types/const.md index 08b4c742e992..d7d1b4be70a7 100644 --- a/src/user-defined-types/const.md +++ b/src/user-defined-types/const.md @@ -14,11 +14,7 @@ const DIGEST_SIZE: usize = 3; const FILL_VALUE: u8 = calculate_fill_value(); const fn calculate_fill_value() -> u8 { - if DIGEST_SIZE < 10 { - 42 - } else { - 13 - } + if DIGEST_SIZE < 10 { 42 } else { 13 } } fn compute_digest(text: &str) -> [u8; DIGEST_SIZE] { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index cf818a36dcea..bf63a923e5ab 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -19,7 +19,7 @@ //! `cargo xtask install-tools` and the logic defined here will install //! the tools. -use anyhow::{anyhow, Ok, Result}; +use anyhow::{Ok, Result, anyhow}; use clap::Parser; use std::env; use std::process::Command; From 7632c9990fe1ad86d7a4ad9b737509f899904a8a Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 16 Apr 2025 15:50:43 +0100 Subject: [PATCH 5/6] Update mdbook-pandoc to 0.10.1. --- xtask/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bf63a923e5ab..59d9c52f5541 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -60,7 +60,7 @@ fn install_tools() -> Result<()> { // avoids breakage due to skews between mdbook and mdbook-svgbob. vec!["mdbook", "--locked", "--version", "0.4.48"], vec!["mdbook-svgbob", "--locked", "--version", "0.2.2"], - vec!["mdbook-pandoc", "--locked", "--version", "0.9.3"], + vec!["mdbook-pandoc", "--locked", "--version", "0.10.1"], vec!["mdbook-i18n-helpers", "--locked", "--version", "0.3.6"], vec!["i18n-report", "--locked", "--version", "0.2.0"], // These packages are located in this repository From 5dcf142a455fdc855694113beb52c9d4c705ba3f Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Wed, 23 Apr 2025 11:53:32 +0100 Subject: [PATCH 6/6] Use mdbook-linkcheck2. mdbook-linkcheck hasn't had a release in 2 years and doesn't support Rust 2024 edition. --- .github/workflows/build.yml | 4 ++-- README.md | 2 +- book.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1299d487c0c9..5a945db28703 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -161,9 +161,9 @@ jobs: MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' mdbook build -d po msgfmt -o /dev/null --statistics po/messages.pot - - name: Install mdbook-linkcheck + - name: Install mdbook-linkcheck2 if: contains(fromJSON(env.LINK_CHECKED_LANGUAGES), matrix.language) - run: cargo install mdbook-linkcheck --locked --version 0.7.7 + run: cargo install mdbook-linkcheck2 --locked --version 0.9.1 - name: Build ${{ matrix.language }} translation run: | diff --git a/README.md b/README.md index 1315de592232..dac581e926f1 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ The course is built using a few tools: - [mdbook-course](mdbook-course/) In addition, -[mdbook-linkcheck](https://github.com/Michael-F-Bryan/mdbook-linkcheck) checks +[mdbook-linkcheck2](https://github.com/marxin/mdbook-linkcheck2) checks the internal links. First install Rust by following the instructions on https://rustup.rs/. Then diff --git a/book.toml b/book.toml index 057e39389386..749fe6faa0fc 100644 --- a/book.toml +++ b/book.toml @@ -291,7 +291,7 @@ use-boolean-and = true [output.exerciser] output-directory = "comprehensive-rust-exercises" -[output.linkcheck] +[output.linkcheck2] optional = true follow-web-links = false # change to true to check web links exclude = [