Skip to content

Commit 09583df

Browse files
feat: Rust 2024 edition (#309)
* feat: Rust `2024` edition * fix: remind assembler its still riscv64gc This is a workaround for rust-lang/rust#80608 * fmt * fmt * remove expects * Update Cargo.toml
1 parent 42cd71a commit 09583df

File tree

148 files changed

+287
-306
lines changed

Some content is hidden

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

148 files changed

+287
-306
lines changed

Cargo.toml

+1-13
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,14 @@ resolver = "2"
44

55
[workspace.package]
66
version = "0.1.0"
7-
edition = "2021"
7+
edition = "2024"
88
authors = ["Jonas Kruckenberg <[email protected]>"]
99
license = "MIT OR Apache-2.0"
1010

1111
[workspace.lints.rust]
12-
rust-2024-compatibility = "deny"
13-
if_let_rescope = "allow"
14-
1512
# allow loom
1613
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)'] }
1714

18-
#keyword_idents_2024 = 'warn'
19-
#unsafe-attr-outside-unsafe = 'warn'
20-
#deprecated-safe-2024 = 'warn'
21-
#rust-2024-guarded-string-incompatible-syntax = 'warn'
22-
#rust-2024-prelude-collisions = 'warn'
23-
#rust-2024-incompatible-pat = 'warn'
24-
#missing-unsafe-on-extern = 'warn'
25-
#impl-trait-overcaptures = 'warn'
26-
2715
[workspace.lints.clippy]
2816
# numeric safety
2917
#arithmetic_side_effects = "deny" TODO audit arithmetic & reenable

flake.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kernel/src/allocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// copied, modified, or distributed except according to those terms.
77

88
use crate::vm::bootstrap_alloc::BootstrapAllocator;
9-
use crate::{arch, INITIAL_HEAP_SIZE_PAGES};
9+
use crate::{INITIAL_HEAP_SIZE_PAGES, arch};
1010
use core::alloc::Layout;
1111
use core::range::Range;
1212
use loader_api::BootInfo;

kernel/src/arch/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
//! - `with_user_memory_access` for temporarily enabling kernel access to userspace memory
1717
//! - `mb`, `rmb`, `wmb` for memory barriers
1818
//! - `set_thread_ptr`, `get_stack_pointer`, `get_next_older_pc_from_fp`, `assert_fp_is_aligned` for
19-
//! WASM stack support
19+
//! WASM stack support
2020
//! - `device::cpu::init`, `device::cpu::with_cpu_info` for CPU initialization
2121
//! - `invalidate_range`, `is_kernel_address`, `AddressSpace`, `KERNEL_ASPACE_BASE`,
22-
//! `USER_ASPACE_BASE`, `PAGE_SHIFT`, `CANONICAL_ADDRESS_MASK`, `PAGE_SIZE`, `DEFAULT_ASID` to
23-
//! support the virtual memory subsystem
22+
//! `USER_ASPACE_BASE`, `PAGE_SHIFT`, `CANONICAL_ADDRESS_MASK`, `PAGE_SIZE`, `DEFAULT_ASID` to
23+
//! support the virtual memory subsystem
2424
2525
cfg_if::cfg_if! {
2626
if #[cfg(target_arch = "riscv64")] {

kernel/src/arch/riscv64/device/cpu.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77

8+
use crate::CPUID;
89
use crate::arch::device;
910
use crate::device_tree::DeviceTree;
1011
use crate::error::Error;
1112
use crate::irq::InterruptController;
1213
use crate::time::clock::Ticks;
1314
use crate::time::{Clock, NANOS_PER_SEC};
14-
use crate::CPUID;
1515
use bitflags::bitflags;
1616
use core::cell::OnceCell;
1717
use core::str::FromStr;
@@ -82,15 +82,13 @@ pub fn with_cpu<F, R>(f: F) -> R
8282
where
8383
F: FnOnce(&Cpu) -> R,
8484
{
85-
#[expect(tail_expr_drop_order, reason = "")]
8685
CPU.with(|cpu_info| f(cpu_info.get().expect("CPU info not initialized")))
8786
}
8887

8988
pub fn try_with_cpu<F, R>(f: F) -> Result<R, Error>
9089
where
9190
F: FnOnce(&Cpu) -> R,
9291
{
93-
#[expect(tail_expr_drop_order, reason = "")]
9492
CPU.try_with(|cpu_info| Ok(f(cpu_info.get().ok_or(Error::Uninitialized)?)))?
9593
}
9694

kernel/src/arch/riscv64/device/plic.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use crate::arch::PAGE_SIZE;
99
use crate::device_tree::{Device, DeviceTree, IrqSource};
1010
use crate::irq::{InterruptController, IrqClaim};
1111
use crate::vm::{
12-
with_kernel_aspace, AddressRangeExt, AddressSpaceRegion, Permissions, PhysicalAddress,
12+
AddressRangeExt, AddressSpaceRegion, Permissions, PhysicalAddress, with_kernel_aspace,
1313
};
1414
use alloc::string::ToString;
1515
use core::alloc::Layout;
16-
use core::mem::{offset_of, MaybeUninit};
16+
use core::mem::{MaybeUninit, offset_of};
1717
use core::num::NonZero;
1818
use core::ops::{BitAnd, BitOr, Not};
1919
use core::ptr;
@@ -34,8 +34,7 @@ pub struct Plic {
3434
ndev: usize,
3535
}
3636

37-
#[repr(packed(4))]
38-
#[repr(C)]
37+
#[repr(C, packed(4))]
3938
struct PlicRegs {
4039
source_priority: [MmioReg<u32>; 1024], // 0x0000000 -- 0x0000fff
4140
/// A 32x32 array of 32-bit registers, each representing a bitfield of 1024 pending interrupt bits.
@@ -67,8 +66,7 @@ const_assert_eq!(offset_of!(PlicRegs, pending), 0x001000);
6766
const_assert_eq!(offset_of!(PlicRegs, enable), 0x002000);
6867
const_assert_eq!(offset_of!(PlicRegs, thresholds_claims), 0x0200000);
6968

70-
#[repr(packed(4))]
71-
#[repr(C)]
69+
#[repr(C, packed(4))]
7270
struct ThresholdsClaimsRegs {
7371
threshold: MmioReg<u32>,
7472
claim_complete: MmioReg<u32>,

kernel/src/arch/riscv64/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use crate::vm::VirtualAddress;
1616
use core::arch::asm;
1717
use riscv::sstatus::FS;
1818
use riscv::{interrupt, scounteren, sie, sstatus};
19-
pub use setjmp_longjmp::{call_with_setjmp, longjmp, JmpBuf};
19+
pub use setjmp_longjmp::{JmpBuf, call_with_setjmp, longjmp};
2020
pub use vm::{
21-
invalidate_range, is_kernel_address, AddressSpace, CANONICAL_ADDRESS_MASK, DEFAULT_ASID,
22-
KERNEL_ASPACE_BASE, PAGE_SHIFT, PAGE_SIZE, USER_ASPACE_BASE,
21+
AddressSpace, CANONICAL_ADDRESS_MASK, DEFAULT_ASID, KERNEL_ASPACE_BASE, PAGE_SHIFT, PAGE_SIZE,
22+
USER_ASPACE_BASE, invalidate_range, is_kernel_address,
2323
};
2424

2525
/// Global RISC-V specific initialization.

kernel/src/arch/riscv64/setjmp_longjmp.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub type JmpBuf = *const JmpBufStruct;
7272
/// This function pretty weird, it can return more than one time:
7373
/// - The first time it returns, the return value is `0` indicating that the context has been saved.
7474
/// - Subsequently, calls to `longjmp` that transfer control to the `*mut JumpBuf` used by this `setjmp`
75-
/// will cause this function to return again, this time with the value passed to `longjmp`.
75+
/// will cause this function to return again, this time with the value passed to `longjmp`.
7676
///
7777
/// This implementation has been adapted from the [LLVM libc implementation (Apache License v2.0 with LLVM Exceptions)](https://github.com/llvm/llvm-project/blob/bbf2ad026eb0b399364a889799ef6b45878cd299/libc/src/setjmp/riscv/setjmp.cpp)
7878
///
@@ -87,6 +87,10 @@ pub unsafe extern "C" fn setjmp(env: JmpBuf) -> i32 {
8787
cfg_if::cfg_if! {
8888
if #[cfg(target_feature = "d")] {
8989
naked_asm! {
90+
// FIXME this is a workaround for bug in rustc/llvm
91+
// https://github.com/rust-lang/rust/issues/80608#issuecomment-1094267279
92+
".attribute arch, \"rv64gc\"",
93+
9094
save_gp!(ra => a0[0]),
9195
save_gp!(s0 => a0[1]),
9296
save_gp!(s1 => a0[2]),
@@ -159,6 +163,10 @@ pub unsafe extern "C" fn longjmp(env: JmpBuf, val: i32) -> ! {
159163
cfg_if::cfg_if! {
160164
if #[cfg(target_feature = "d")] {
161165
naked_asm! {
166+
// FIXME this is a workaround for bug in rustc/llvm
167+
// https://github.com/rust-lang/rust/issues/80608#issuecomment-1094267279
168+
".attribute arch, \"rv64gc\"",
169+
162170
load_gp!(a0[0] => ra),
163171
load_gp!(a0[1] => s0),
164172
load_gp!(a0[2] => s1),

kernel/src/arch/riscv64/trap_handler.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// copied, modified, or distributed except according to those terms.
77

88
use super::utils::{define_op, load_fp, load_gp, save_fp, save_gp};
9+
use crate::TRAP_STACK_SIZE_PAGES;
910
use crate::arch::PAGE_SIZE;
1011
use crate::scheduler::scheduler;
1112
use crate::traps::TrapReason;
1213
use crate::vm::VirtualAddress;
13-
use crate::TRAP_STACK_SIZE_PAGES;
1414
use core::arch::{asm, naked_asm};
1515
use cpu_local::cpu_local;
1616
use riscv::scause::{Exception, Interrupt, Trap};
@@ -85,9 +85,13 @@ unsafe extern "C" fn default_trap_entry() {
8585
// Safety: inline assembly
8686
unsafe {
8787
naked_asm! {
88-
".align 2",
88+
// FIXME this is a workaround for bug in rustc/llvm
89+
// https://github.com/rust-lang/rust/issues/80608#issuecomment-1094267279
90+
".attribute arch, \"rv64gc\"",
8991

92+
".align 2",
9093
"csrrw sp, sscratch, sp", // sp points to the TrapFrame
94+
9195
"add sp, sp, -0x210",
9296

9397
// save gp regs
@@ -261,7 +265,9 @@ fn default_trap_handler(
261265

262266
let cause = scause::read().cause();
263267

264-
tracing::trace!("trap_handler cause {cause:?}, a1 {a1:#x} a2 {a2:#x} a3 {a3:#x} a4 {a4:#x} a5 {a5:#x} a6 {a6:#x} a7 {a7:#x}");
268+
tracing::trace!(
269+
"trap_handler cause {cause:?}, a1 {a1:#x} a2 {a2:#x} a3 {a3:#x} a4 {a4:#x} a5 {a5:#x} a6 {a6:#x} a7 {a7:#x}"
270+
);
265271
let epc = sepc::read();
266272
let tval = stval::read();
267273
tracing::trace!("{:?};epc={epc:#x};tval={tval:#x}", sstatus::read());

kernel/src/arch/riscv64/vm.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
// copied, modified, or distributed except according to those terms.
77

88
use crate::arch::{mb, wmb};
9+
use crate::vm::Error;
910
use crate::vm::flush::Flush;
1011
use crate::vm::frame_alloc::Frame;
11-
use crate::vm::Error;
12-
use crate::vm::{frame_alloc, PhysicalAddress, VirtualAddress};
12+
use crate::vm::{PhysicalAddress, VirtualAddress, frame_alloc};
1313
use alloc::vec;
1414
use alloc::vec::Vec;
1515
use bitflags::bitflags;
@@ -202,7 +202,6 @@ impl crate::vm::ArchAddressSpace for AddressSpace {
202202
wired_frames: vec![root_pgtable],
203203
};
204204

205-
#[expect(tail_expr_drop_order, reason = "")]
206205
Ok((this, Flush::empty(asid)))
207206
}
208207

@@ -218,7 +217,6 @@ impl crate::vm::ArchAddressSpace for AddressSpace {
218217
wired_frames: vec![],
219218
};
220219

221-
#[expect(tail_expr_drop_order, reason = "")]
222220
(this, Flush::empty(asid))
223221
}
224222

kernel/src/backtrace/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ impl<const MAX_FRAMES: usize> Backtrace<'_, MAX_FRAMES> {
104104
}
105105
}
106106

107-
#[expect(tail_expr_drop_order, reason = "")]
108107
Ok(Self {
109108
symbolize_ctx: SYMBOLIZE_CONTEXT.as_ref(),
110109
frames,

kernel/src/backtrace/symbolize.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::ffi::c_void;
99
use core::{fmt, str};
1010
use fallible_iterator::FallibleIterator;
1111
use gimli::{EndianSlice, NativeEndian};
12-
use rustc_demangle::{try_demangle, Demangle};
12+
use rustc_demangle::{Demangle, try_demangle};
1313
use xmas_elf::sections::SectionData;
1414
use xmas_elf::symbol_table::Entry;
1515

@@ -192,7 +192,6 @@ impl<'a> SymbolizeContext<'a> {
192192
})?;
193193
let addr2line = addr2line::Context::from_dwarf(dwarf)?;
194194

195-
#[expect(tail_expr_drop_order, reason = "")]
196195
Ok(Self {
197196
addr2line,
198197
elf,
@@ -226,7 +225,6 @@ impl<'a> SymbolizeContext<'a> {
226225
})
227226
.unwrap();
228227

229-
#[expect(tail_expr_drop_order, reason = "")]
230228
Ok(SymbolsIter {
231229
addr: probe,
232230
elf: &self.elf,

kernel/src/cmdline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub struct Cmdline {
2727
impl FromStr for Cmdline {
2828
type Err = Error;
2929

30-
#[expect(tail_expr_drop_order, reason = "")]
3130
fn from_str(s: &str) -> Result<Self, Self::Err> {
3231
let mut log = None;
3332

kernel/src/cpu_local.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ impl<T: Send> CpuLocal<T> {
120120
where
121121
F: FnOnce() -> T,
122122
{
123-
#[expect(tail_expr_drop_order, reason = "")]
124123
// Safety: value will be initialized by `create` if necessary
125-
unsafe {
126-
self.get_or_try(|| Ok::<T, ()>(create())).unwrap_unchecked()
127-
}
124+
unsafe { self.get_or_try(|| Ok::<T, ()>(create())).unwrap_unchecked() }
128125
}
129126

130127
/// Returns the element for the current cpu, or creates it if it doesn't
@@ -141,7 +138,6 @@ impl<T: Send> CpuLocal<T> {
141138
return Ok(val);
142139
}
143140

144-
#[expect(tail_expr_drop_order, reason = "")]
145141
Ok(self.insert(cpuid, create()?))
146142
}
147143

kernel/src/device_tree.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use core::{fmt, iter, mem, slice};
1212
use fallible_iterator::FallibleIterator;
1313
use fdt::{CellSizes, Error, Fdt, NodeName, StringList};
1414
use hashbrown::HashMap;
15-
use smallvec::{smallvec, SmallVec};
15+
use smallvec::{SmallVec, smallvec};
1616
use sync::OnceLock;
1717

1818
type Link<T> = Option<NonNull<T>>;
@@ -173,7 +173,6 @@ impl<'a> Device<'a> {
173173

174174
/// Matches the device `compatible` string against the given list of strings.
175175
pub fn is_compatible<'b>(&self, compats: impl IntoIterator<Item = &'b str>) -> bool {
176-
#[expect(tail_expr_drop_order, reason = "")]
177176
compats.into_iter().any(|c| self.compatible.contains(c))
178177
}
179178

@@ -490,7 +489,6 @@ pub fn init(fdt: &[u8]) -> crate::Result<&'static DeviceTree> {
490489
stack[depth] = Some(ptr);
491490
}
492491

493-
#[expect(tail_expr_drop_order, reason = "")]
494492
Ok(DeviceTreeInner { phandle2ptr, root })
495493
})
496494
})

kernel/src/main.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#![feature(new_range_api)]
1414
#![feature(debug_closure_helpers)]
1515
#![expect(internal_features, reason = "panic internals")]
16-
#![feature(std_internals, panic_can_unwind, fmt_internals)]
16+
#![feature(std_internals, panic_can_unwind, formatting_options)]
1717
#![feature(step_trait)]
1818
#![feature(box_into_inner)]
1919
#![feature(let_chains)]
@@ -23,7 +23,6 @@
2323
#![feature(if_let_guard)]
2424
#![feature(allocator_api)]
2525
#![expect(dead_code, reason = "TODO")] // TODO remove
26-
#![expect(edition_2024_expr_fragment_specifier, reason = "vetted")]
2726

2827
extern crate alloc;
2928

@@ -50,8 +49,8 @@ mod wasm;
5049

5150
use crate::device_tree::device_tree;
5251
use crate::error::Error;
53-
use crate::time::clock::Ticks;
5452
use crate::time::Instant;
53+
use crate::time::clock::Ticks;
5554
use crate::vm::bootstrap_alloc::BootstrapAllocator;
5655
use arrayvec::ArrayVec;
5756
use cfg_if::cfg_if;
@@ -63,8 +62,8 @@ use loader_api::{BootInfo, LoaderConfig, MemoryRegionKind};
6362
use rand::SeedableRng;
6463
use rand_chacha::ChaCha20Rng;
6564
use sync::Once;
66-
use vm::frame_alloc;
6765
use vm::PhysicalAddress;
66+
use vm::frame_alloc;
6867

6968
/// The size of the stack in pages
7069
pub const STACK_SIZE_PAGES: u32 = 256; // TODO find a lower more appropriate value

0 commit comments

Comments
 (0)