Skip to content

Commit e7ca4fb

Browse files
committed
Add unsafe block around DEVICE_PERIPHERALS
1 parent 87c2fc4 commit e7ca4fb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Add unsafe block around `DEVICE_PERIPHERALS = true` in `Peripherals::steal()`
11+
to support Rust 2024 edition.
12+
1013
## [v0.37.0] - 2025-08-14
1114

1215
- Fix new `mismatched-lifetime-syntaxes` lint warnings

src/generate/device.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
301301
quote!(#[no_mangle])
302302
};
303303

304+
let set_device_peripherals_true = if config.edition >= RustEdition::E2024 {
305+
quote!(unsafe { DEVICE_PERIPHERALS = true })
306+
} else {
307+
quote!(DEVICE_PERIPHERALS = true;)
308+
};
309+
304310
out.extend(quote! {
305311
// NOTE `no_mangle` is used here to prevent linking different minor versions of the device
306312
// crate as that would let you `take` the device peripherals more than once (one per minor
@@ -339,7 +345,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
339345
/// Each of the returned peripherals must be used at most once.
340346
#[inline]
341347
pub unsafe fn steal() -> Self {
342-
DEVICE_PERIPHERALS = true;
348+
#set_device_peripherals_true
343349

344350
Peripherals {
345351
#exprs

0 commit comments

Comments
 (0)