Skip to content

Update to Rust 2024 edition. #2658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ else
# Back-date the sources to POT-Creation-Date. The content lives in two
# directories:
rm -r src/ third_party/
git restore --source "$(git rev-list -n 1 --before "$pot_creation_date" @)" src/ third_party/
git restore --source "$(git rev-list -n 1 --before "$pot_creation_date" @)" src/ third_party/ book.toml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up @jonodeno: I believe your google/mdbook-i18n-helpers#268 will need to be updated to take this into account.

Cc @michael-kerscher as well, who has been reviewing the other PR.

# Set language and adjust site URL. Clear the redirects since they are
# in sync with the source files, not the translation.
export MDBOOK_BOOK__LANGUAGE=$book_lang
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ 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 uninstall mdbook-linkcheck || true
cargo install mdbook-linkcheck2 --locked --version 0.9.1

- name: Build ${{ matrix.language }} translation
run: |
Expand Down Expand Up @@ -210,6 +212,9 @@ jobs:
with:
fetch-depth: 0

- name: Update Rust
run: rustup update

- name: Setup Rust cache
uses: ./.github/workflows/setup-rust-cache

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/install-mdbook/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ runs:
run: |
sudo apt-get update
sudo apt-get install -y texlive texlive-luatex texlive-lang-cjk texlive-lang-arabic librsvg2-bin fonts-noto
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.6.2/pandoc-3.6.2-linux-amd64.tar.gz | tar zxf -
echo "$PWD/pandoc-3.6.2/bin" >> $GITHUB_PATH
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.7.0.1/pandoc-3.7.0.1-linux-amd64.tar.gz | tar zxf -
echo "$PWD/pandoc-3.7.0.1/bin" >> $GITHUB_PATH
shell: bash
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The course is built using a few tools:
- [mdbook-i18n-helpers and i18n-report](https://github.com/google/mdbook-i18n-helpers)
- [mdbook-exerciser](mdbook-exerciser/)
- [mdbook-course](mdbook-course/)
- [mdbook-linkcheck](https://github.com/Michael-F-Bryan/mdbook-linkcheck)
- [mdbook-linkcheck2](https://github.com/marxin/mdbook-linkcheck2)

First install Rust by following the instructions on https://rustup.rs/. Then
clone this repository:
Expand Down
11 changes: 10 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ src = "src"
title = "Comprehensive Rust 🦀"

[rust]
edition = "2021"
edition = "2024"

[build]
extra-watch-dirs = ["po", "third_party"]
Expand Down Expand Up @@ -299,3 +299,12 @@ exclude = [
"comprehensive-rust-exercises.zip",
# "crates.io", # uncomment when follow-web-links is true
]

[output.linkcheck2]
optional = true
follow-web-links = false # change to true to check web links
exclude = [
"comprehensive-rust.pdf",
"comprehensive-rust-exercises.zip",
# "crates.io", # uncomment when follow-web-links is true
]
2 changes: 1 addition & 1 deletion dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"command": "yapf3",
"exts": ["py"]
}, {
"command": "rustup run stable rustfmt --edition 2021",
"command": "rustup run stable rustfmt --edition 2024",
"exts": ["rs"]
}]
},
Expand Down
2 changes: 1 addition & 1 deletion mdbook-course/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mdbook-course"
version = "0.1.0"
authors = ["Dustin Mitchell <[email protected]>"]
edition = "2021"
edition = "2024"
license = "Apache-2.0"
publish = false
repository = "https://github.com/google/comprehensive-rust"
Expand Down
14 changes: 6 additions & 8 deletions mdbook-course/src/course.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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() }
}
}

Expand Down
2 changes: 1 addition & 1 deletion mdbook-exerciser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "mdbook-exerciser"
version = "0.1.0"
authors = ["Andrew Walbran <[email protected]>"]
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."
Expand Down
2 changes: 1 addition & 1 deletion mdbook-exerciser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion mdbook-exerciser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/android/interoperability/java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/android/testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "android-testing"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[[example]]
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/alloc-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[package]
name = "alloc-example"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
5 changes: 3 additions & 2 deletions src/bare-metal/alloc-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/aps/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[package]
name = "ap-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/aps/examples/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/aps/examples/src/main_improved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down
4 changes: 2 additions & 2 deletions src/bare-metal/aps/examples/src/main_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/aps/examples/src/main_minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,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 _;
Expand Down
4 changes: 2 additions & 2 deletions src/bare-metal/aps/examples/src/main_rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
mod exceptions;

use aarch64_paging::paging::Attributes;
use aarch64_rt::{entry, initial_pagetable, InitialPagetable};
use aarch64_rt::{InitialPagetable, entry, initial_pagetable};
use arm_pl011_uart::{PL011Registers, Uart, UniqueMmioPointer};
use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::NonNull;
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: NonNull<PL011Registers> =
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/microcontrollers/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[package]
name = "microcontroller-examples"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/microcontrollers/examples/src/bin/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/useful-crates/allocator-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "allocator-example"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/useful-crates/tinyvec.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ many elements are used and panics if you try to use more than are allocated.
<!-- mdbook-xgettext: skip -->

```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);
Expand Down
2 changes: 1 addition & 1 deletion src/bare-metal/useful-crates/zerocopy-example/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zerocopy-example"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/borrowing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "borrowing"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[lib]
Expand Down
4 changes: 2 additions & 2 deletions src/borrowing/borrowck.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ fn main() {

</details>

[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8f5896878611566845fe3b0f4dc5af68
[2]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f293a31f2d4d0d31770486247c2e8437
[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8f5896878611566845fe3b0f4dc5af68
[2]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f293a31f2d4d0d31770486247c2e8437
2 changes: 1 addition & 1 deletion src/borrowing/shared.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ Notes on stack returns and inlining:

</details>

[Playground]: https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=0cb13be1c05d7e3446686ad9947c4671
[Playground]: https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=0cb13be1c05d7e3446686ad9947c4671
4 changes: 2 additions & 2 deletions src/cargo/rust-ecosystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions src/closures/capturing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/async-control-flow/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/concurrency/async-exercises/chat-async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading
Loading