From 4a07baf9dcd342d1f32245b576c219a83322e74f Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 25 Feb 2025 17:44:42 +0000 Subject: [PATCH] Update to Rust 2024 edition. --- .github/workflows/build.yml | 3 +++ .github/workflows/publish.yml | 3 +++ book.toml | 2 +- install-mdbook.sh | 2 +- mdbook-course/Cargo.toml | 2 +- mdbook-exerciser/Cargo.toml | 2 +- mdbook-slide-evaluator/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 ++ 43 files changed, 60 insertions(+), 45 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eca610cc..f5d5a427 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -204,6 +204,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 53d547cf..da9bab8e 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 c2cf646b..9a8f28f8 100644 --- a/book.toml +++ b/book.toml @@ -6,7 +6,7 @@ src = "src" title = "Comprehensive Rust 🦀" [rust] -edition = "2021" +edition = "2024" [build] extra-watch-dirs = ["po", "third_party"] diff --git a/install-mdbook.sh b/install-mdbook.sh index abd81258..ee6a9ce3 100755 --- a/install-mdbook.sh +++ b/install-mdbook.sh @@ -4,7 +4,7 @@ cargo install mdbook --locked --version 0.4.44 cargo install mdbook-svgbob --locked --version 0.2.1 cargo install mdbook-pandoc --locked --version 0.9.3 -cargo install mdbook-i18n-helpers --locked --version 0.3.5 +cargo install mdbook-i18n-helpers --locked --version 0.3.6 cargo install i18n-report --locked --version 0.2.0 # these packages are located in this repository cargo install --path mdbook-exerciser --locked diff --git a/mdbook-course/Cargo.toml b/mdbook-course/Cargo.toml index 96b5a2f4..ca5e0260 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 34f1f700..a7eb119b 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/mdbook-slide-evaluator/Cargo.toml b/mdbook-slide-evaluator/Cargo.toml index d8266784..9b9dfbc4 100644 --- a/mdbook-slide-evaluator/Cargo.toml +++ b/mdbook-slide-evaluator/Cargo.toml @@ -2,7 +2,7 @@ name = "mdbook-slide-evaluator" version = "0.1.0" authors = ["Michael Kerscher "] -edition = "2021" +edition = "2024" license = "Apache-2.0" repository = "https://github.com/google/comprehensive-rust" description = "A tool for evaluating mdbook slides by rendering the html pages and spot violations to the policies" diff --git a/src/android/testing/Cargo.toml b/src/android/testing/Cargo.toml index 84f4d8cd..289488ee 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 5b83e2c9..a8dc51aa 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 3e1fd664..cc3e0c84 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 ef51b6b9..ada84123 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 2a7372b4..adad5ed5 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 021848a9..876f8f6f 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 40fbe5ff..38031194 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 8dbedb08..092025e9 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 df8e7ff9..38495770 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 4f7a7d1d..d7a56335 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 6151116e..1af88c1d 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 4c09d6c4..0298dd09 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 b5e9429e..ccf0a644 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 46dc2c34..13744c2f 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 8ea0c0bd..4885f71b 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 639cfe81..f7f8e2bc 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 9098c192..d0347bc1 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 0e020a5a..1ce189bc 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 5fc5a872..457d15d9 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 80a38c25..cc851e2a 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 c379e76d..2ed59362 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 9f992176..44f73820 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 d3d6e0c8..49cc396b 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 b04dbde9..781a640a 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 a86b0386..df29ef89 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 35fb9d8b..0af7fa68 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 279efb39..adb49a79 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 c5262152..edb7408f 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 bc9dec7f..b0a496e5 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 fe46d703..bcfaadc5 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 c6abcf21..e5f59ab5 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 18673731..8068fc01 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 4603dd99..112fa7eb 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 d846404d..95710453 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 10655db3..8f44b4c4 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 66e86989..7d53c735 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,