Skip to content

Commit 37406df

Browse files
authored
Merge pull request #947 from kurtjd/add-unsafe-device-peripherals
Add unsafe block around `DEVICE_PERIPHERALS = true` in `Peripherals::steal()`
2 parents 87c2fc4 + a5ecffa commit 37406df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
- Change `feature(doc_auto_cfg)` to `feature(doc_cfg)` to allow nightly docs to build.
11+
- Add unsafe block around `DEVICE_PERIPHERALS = true` in `Peripherals::steal()`
12+
to support Rust 2024 edition.
13+
1014
## [v0.37.0] - 2025-08-14
1115

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

src/generate/device.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
5959
#![allow(non_camel_case_types)]
6060
#![allow(non_snake_case)]
6161
#![no_std]
62-
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
62+
#![cfg_attr(docsrs, feature(doc_cfg))]
6363
});
6464
}
6565

@@ -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)