Skip to content

Commit fc6e5c7

Browse files
authored
Update to Rust 2024 edition. (#2658)
1 parent db47709 commit fc6e5c7

File tree

83 files changed

+150
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+150
-149
lines changed

.github/workflows/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ else
2525
# Back-date the sources to POT-Creation-Date. The content lives in two
2626
# directories:
2727
rm -r src/ third_party/
28-
git restore --source "$(git rev-list -n 1 --before "$pot_creation_date" @)" src/ third_party/
28+
git restore --source "$(git rev-list -n 1 --before "$pot_creation_date" @)" src/ third_party/ book.toml
2929
# Set language and adjust site URL. Clear the redirects since they are
3030
# in sync with the source files, not the translation.
3131
export MDBOOK_BOOK__LANGUAGE=$book_lang

.github/workflows/build.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ jobs:
161161
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' mdbook build -d po
162162
msgfmt -o /dev/null --statistics po/messages.pot
163163
164-
- name: Install mdbook-linkcheck
164+
- name: Install mdbook-linkcheck2
165165
if: contains(fromJSON(env.LINK_CHECKED_LANGUAGES), matrix.language)
166-
run: cargo install mdbook-linkcheck --locked --version 0.7.7
166+
run: |
167+
cargo uninstall mdbook-linkcheck || true
168+
cargo install mdbook-linkcheck2 --locked --version 0.9.1
167169
168170
- name: Build ${{ matrix.language }} translation
169171
run: |
@@ -210,6 +212,9 @@ jobs:
210212
with:
211213
fetch-depth: 0
212214

215+
- name: Update Rust
216+
run: rustup update
217+
213218
- name: Setup Rust cache
214219
uses: ./.github/workflows/setup-rust-cache
215220

.github/workflows/install-mdbook/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ runs:
1313
run: |
1414
sudo apt-get update
1515
sudo apt-get install -y texlive texlive-luatex texlive-lang-cjk texlive-lang-arabic librsvg2-bin fonts-noto
16-
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.6.2/pandoc-3.6.2-linux-amd64.tar.gz | tar zxf -
17-
echo "$PWD/pandoc-3.6.2/bin" >> $GITHUB_PATH
16+
curl -LsSf https://github.com/jgm/pandoc/releases/download/3.7.0.1/pandoc-3.7.0.1-linux-amd64.tar.gz | tar zxf -
17+
echo "$PWD/pandoc-3.7.0.1/bin" >> $GITHUB_PATH
1818
shell: bash

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
with:
3636
fetch-depth: 0 # We need the full history for build.sh below.
3737

38+
- name: Update Rust
39+
run: rustup update
40+
3841
- name: Setup Rust cache
3942
uses: ./.github/workflows/setup-rust-cache
4043

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The course is built using a few tools:
5555
- [mdbook-i18n-helpers and i18n-report](https://github.com/google/mdbook-i18n-helpers)
5656
- [mdbook-exerciser](mdbook-exerciser/)
5757
- [mdbook-course](mdbook-course/)
58-
- [mdbook-linkcheck](https://github.com/Michael-F-Bryan/mdbook-linkcheck)
58+
- [mdbook-linkcheck2](https://github.com/marxin/mdbook-linkcheck2)
5959

6060
First install Rust by following the instructions on https://rustup.rs/. Then
6161
clone this repository:

book.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ src = "src"
55
title = "Comprehensive Rust 🦀"
66

77
[rust]
8-
edition = "2021"
8+
edition = "2024"
99

1010
[build]
1111
extra-watch-dirs = ["po", "third_party"]
@@ -299,3 +299,12 @@ exclude = [
299299
"comprehensive-rust-exercises.zip",
300300
# "crates.io", # uncomment when follow-web-links is true
301301
]
302+
303+
[output.linkcheck2]
304+
optional = true
305+
follow-web-links = false # change to true to check web links
306+
exclude = [
307+
"comprehensive-rust.pdf",
308+
"comprehensive-rust-exercises.zip",
309+
# "crates.io", # uncomment when follow-web-links is true
310+
]

dprint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"command": "yapf3",
1010
"exts": ["py"]
1111
}, {
12-
"command": "rustup run stable rustfmt --edition 2021",
12+
"command": "rustup run stable rustfmt --edition 2024",
1313
"exts": ["rs"]
1414
}]
1515
},

mdbook-course/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mdbook-course"
33
version = "0.1.0"
44
authors = ["Dustin Mitchell <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66
license = "Apache-2.0"
77
publish = false
88
repository = "https://github.com/google/comprehensive-rust"

mdbook-course/src/course.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
//! item becomes the first slide in that segment. Any other sub-items of the
3636
//! top-level item are treated as further slides in the same segment.
3737
38-
use crate::frontmatter::{split_frontmatter, Frontmatter};
39-
use crate::markdown::{duration, Table};
38+
use crate::frontmatter::{Frontmatter, split_frontmatter};
39+
use crate::markdown::{Table, duration};
4040
use mdbook::book::{Book, BookItem, Chapter};
4141
use std::fmt::Write;
4242
use std::path::PathBuf;
@@ -318,7 +318,9 @@ impl Session {
318318
}
319319
format!(
320320
"Including {BREAK_DURATION} minute breaks, this session should take about {}. It contains:\n\n{}",
321-
duration(self.minutes()), segments)
321+
duration(self.minutes()),
322+
segments
323+
)
322324
}
323325

324326
/// Return the total duration of this session.
@@ -337,11 +339,7 @@ impl Session {
337339
///
338340
/// This includes breaks between segments.
339341
pub fn target_minutes(&self) -> u64 {
340-
if self.target_minutes > 0 {
341-
self.target_minutes
342-
} else {
343-
self.minutes()
344-
}
342+
if self.target_minutes > 0 { self.target_minutes } else { self.minutes() }
345343
}
346344
}
347345

mdbook-exerciser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mdbook-exerciser"
33
version = "0.1.0"
44
authors = ["Andrew Walbran <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66
license = "Apache-2.0"
77
repository = "https://github.com/google/comprehensive-rust"
88
description = "A tool for extracting starter code for exercises from Markdown files."

mdbook-exerciser/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use log::{info, trace};
1616
use pulldown_cmark::{Event, Parser, Tag, TagEnd};
17-
use std::fs::{create_dir_all, File};
17+
use std::fs::{File, create_dir_all};
1818
use std::io::Write;
1919
use std::path::Path;
2020

mdbook-exerciser/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
use anyhow::Context;
1616
use log::trace;
17+
use mdbook::BookItem;
1718
use mdbook::book::Book;
1819
use mdbook::renderer::RenderContext;
19-
use mdbook::BookItem;
2020
use mdbook_exerciser::process;
2121
use std::fs::{create_dir, remove_dir_all};
2222
use std::io::stdin;

src/android/interoperability/java/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// ANCHOR: hello
1616
//! Rust <-> Java FFI demo.
1717
18+
use jni::JNIEnv;
1819
use jni::objects::{JClass, JString};
1920
use jni::sys::jstring;
20-
use jni::JNIEnv;
2121

2222
/// HelloWorld::hello method implementation.
2323
// SAFETY: There is no other global function of this name.

src/android/testing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "android-testing"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66

77
[[example]]

src/bare-metal/alloc-example/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[package]
44
name = "alloc-example"
55
version = "0.1.0"
6-
edition = "2021"
6+
edition = "2024"
77
publish = false
88

99
[dependencies]

src/bare-metal/alloc-example/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ use buddy_system_allocator::LockedHeap;
2626
#[global_allocator]
2727
static HEAP_ALLOCATOR: LockedHeap<32> = LockedHeap::<32>::new();
2828

29-
static mut HEAP: [u8; 65536] = [0; 65536];
29+
const HEAP_SIZE: usize = 65536;
30+
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
3031

3132
pub fn entry() {
3233
// SAFETY: `HEAP` is only used here and `entry` is only called once.
3334
unsafe {
3435
// Give the allocator some memory to allocate.
35-
HEAP_ALLOCATOR.lock().init(HEAP.as_mut_ptr() as usize, HEAP.len());
36+
HEAP_ALLOCATOR.lock().init(&raw mut HEAP as usize, HEAP_SIZE);
3637
}
3738

3839
// Now we can do things that require heap allocation.

src/bare-metal/aps/examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[package]
44
name = "ap-examples"
55
version = "0.1.0"
6-
edition = "2021"
6+
edition = "2024"
77
publish = false
88

99
[dependencies]

src/bare-metal/aps/examples/src/exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
// ANCHOR: exceptions
1616
use log::error;
17-
use smccc::psci::system_off;
1817
use smccc::Hvc;
18+
use smccc::psci::system_off;
1919

2020
// SAFETY: There is no other global function of this name.
2121
#[unsafe(no_mangle)]

src/bare-metal/aps/examples/src/main_improved.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use crate::pl011::Uart;
2323
use core::fmt::Write;
2424
use core::panic::PanicInfo;
2525
use log::error;
26-
use smccc::psci::system_off;
2726
use smccc::Hvc;
27+
use smccc::psci::system_off;
2828

2929
/// Base address of the primary PL011 UART.
3030
const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _;

src/bare-metal/aps/examples/src/main_logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ mod pl011;
2222

2323
use crate::pl011::Uart;
2424
use core::panic::PanicInfo;
25-
use log::{error, info, LevelFilter};
26-
use smccc::psci::system_off;
25+
use log::{LevelFilter, error, info};
2726
use smccc::Hvc;
27+
use smccc::psci::system_off;
2828

2929
/// Base address of the primary PL011 UART.
3030
const PL011_BASE_ADDRESS: *mut u32 = 0x900_0000 as _;

src/bare-metal/aps/examples/src/main_minimal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::pl011_minimal::Uart;
2424
use core::fmt::Write;
2525
use core::panic::PanicInfo;
2626
use log::error;
27-
use smccc::psci::system_off;
2827
use smccc::Hvc;
28+
use smccc::psci::system_off;
2929

3030
/// Base address of the primary PL011 UART.
3131
const PL011_BASE_ADDRESS: *mut u8 = 0x900_0000 as _;

src/bare-metal/aps/examples/src/main_rt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
mod exceptions;
2020

2121
use aarch64_paging::paging::Attributes;
22-
use aarch64_rt::{entry, initial_pagetable, InitialPagetable};
22+
use aarch64_rt::{InitialPagetable, entry, initial_pagetable};
2323
use arm_pl011_uart::{PL011Registers, Uart, UniqueMmioPointer};
2424
use core::fmt::Write;
2525
use core::panic::PanicInfo;
2626
use core::ptr::NonNull;
2727
use log::error;
28-
use smccc::psci::system_off;
2928
use smccc::Hvc;
29+
use smccc::psci::system_off;
3030

3131
/// Base address of the primary PL011 UART.
3232
const PL011_BASE_ADDRESS: NonNull<PL011Registers> =

src/bare-metal/microcontrollers/examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[package]
44
name = "microcontroller-examples"
55
version = "0.1.0"
6-
edition = "2021"
6+
edition = "2024"
77
publish = false
88

99
[dependencies]

src/bare-metal/microcontrollers/examples/src/bin/hal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern crate panic_halt as _;
2020

2121
use cortex_m_rt::entry;
2222
use embedded_hal::digital::OutputPin;
23-
use nrf52833_hal::gpio::{p0, Level};
23+
use nrf52833_hal::gpio::{Level, p0};
2424
use nrf52833_hal::pac::Peripherals;
2525

2626
#[entry]

src/bare-metal/useful-crates/allocator-example/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "allocator-example"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66

77
[dependencies]

src/bare-metal/useful-crates/tinyvec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ many elements are used and panics if you try to use more than are allocated.
88
<!-- mdbook-xgettext: skip -->
99

1010
```rust,editable,compile_fail
11-
use tinyvec::{array_vec, ArrayVec};
11+
use tinyvec::{ArrayVec, array_vec};
1212
1313
fn main() {
1414
let mut numbers: ArrayVec<[u32; 5]> = array_vec!(42, 66);

src/bare-metal/useful-crates/zerocopy-example/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "zerocopy-example"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66

77
[dependencies]

src/borrowing/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "borrowing"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66

77
[lib]

src/borrowing/borrowck.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ fn main() {
8282

8383
</details>
8484

85-
[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8f5896878611566845fe3b0f4dc5af68
86-
[2]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f293a31f2d4d0d31770486247c2e8437
85+
[1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=8f5896878611566845fe3b0f4dc5af68
86+
[2]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f293a31f2d4d0d31770486247c2e8437

src/borrowing/shared.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ Notes on stack returns and inlining:
7272

7373
</details>
7474

75-
[Playground]: https://play.rust-lang.org/?version=stable&mode=release&edition=2021&gist=0cb13be1c05d7e3446686ad9947c4671
75+
[Playground]: https://play.rust-lang.org/?version=stable&mode=release&edition=2024&gist=0cb13be1c05d7e3446686ad9947c4671

src/cargo/rust-ecosystem.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Key points:
3232
- Dependencies can also be resolved from alternative [registries], git, folders,
3333
and more.
3434

35-
- Rust also has [editions]: the current edition is Rust 2021. Previous editions
36-
were Rust 2015 and Rust 2018.
35+
- Rust also has [editions]: the current edition is Rust 2024. Previous editions
36+
were Rust 2015, Rust 2018 and Rust 2021.
3737

3838
- The editions are allowed to make backwards incompatible changes to the
3939
language.

src/closures/capturing.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ A closure can capture variables from the environment where it was defined.
1010
fn main() {
1111
let max_value = 5;
1212
let clamp = |v| {
13-
if v > max_value {
14-
max_value
15-
} else {
16-
v
17-
}
13+
if v > max_value { max_value } else { v }
1814
};
1915
2016
dbg!(clamp(1));

src/concurrency/async-control-flow/select.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ the resulting variables. The `statement` result becomes the result of the
1717

1818
```rust,editable,compile_fail
1919
use tokio::sync::mpsc;
20-
use tokio::time::{sleep, Duration};
20+
use tokio::time::{Duration, sleep};
2121
2222
#[tokio::main]
2323
async fn main() {

src/concurrency/async-exercises/chat-async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "chat-async"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
futures-util = { version = "0.3.31", features = ["sink"] }

src/concurrency/async-exercises/chat-async/src/bin/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
// ANCHOR: solution
1616
// ANCHOR: setup
17-
use futures_util::stream::StreamExt;
1817
use futures_util::SinkExt;
18+
use futures_util::stream::StreamExt;
1919
use http::Uri;
2020
use tokio::io::{AsyncBufReadExt, BufReader};
2121
use tokio_websockets::{ClientBuilder, Message};

0 commit comments

Comments
 (0)