From f102430bf7d742d8ca0dea6a6058b2b816fe02ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 11 Apr 2024 13:14:35 +0200 Subject: [PATCH] singleton: don't forward visibility --- cortex-m/CHANGELOG.md | 2 +- cortex-m/src/macros.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cortex-m/CHANGELOG.md b/cortex-m/CHANGELOG.md index 3cb7ebd2..85efc02f 100644 --- a/cortex-m/CHANGELOG.md +++ b/cortex-m/CHANGELOG.md @@ -24,7 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added the ability to name the statics generated by `singleton!()` for better debuggability (#364, #380). - Added `critical-section-single-core` feature which provides an implementation for the `critical_section` crate for single-core systems, based on disabling all interrupts. (#447) - Added support for `embedded-hal` version 1 delay traits, requiring rust 1.60. -- `singleton!()` now forwards attributes and visibility (#521). +- `singleton!()` now forwards attributes (#522). ### Fixed - Fixed `singleton!()` statics sometimes ending up in `.data` instead of `.bss` (#364, #380). diff --git a/cortex-m/src/macros.rs b/cortex-m/src/macros.rs index 4413f6d9..9e8f2552 100644 --- a/cortex-m/src/macros.rs +++ b/cortex-m/src/macros.rs @@ -64,13 +64,13 @@ macro_rules! iprintln { /// ``` #[macro_export] macro_rules! singleton { - ($(#[$meta:meta])* $vis:vis $name:ident: $ty:ty = $expr:expr) => { + ($(#[$meta:meta])* $name:ident: $ty:ty = $expr:expr) => { $crate::_export::critical_section::with(|_| { // this is a tuple of a MaybeUninit and a bool because using an Option here is // problematic: Due to niche-optimization, an Option could end up producing a non-zero // initializer value which would move the entire static from `.bss` into `.data`... $(#[$meta])* - $vis static mut $name: (::core::mem::MaybeUninit<$ty>, bool) = + static mut $name: (::core::mem::MaybeUninit<$ty>, bool) = (::core::mem::MaybeUninit::uninit(), false); #[allow(unsafe_code)] @@ -89,8 +89,8 @@ macro_rules! singleton { } }) }; - (: $ty:ty = $expr:expr) => { - $crate::singleton!(VAR: $ty = $expr) + ($(#[$meta:meta])* : $ty:ty = $expr:expr) => { + $crate::singleton!($(#[$meta])* VAR: $ty = $expr) }; } @@ -121,8 +121,9 @@ const CPASS: () = (); /// use cortex_m::singleton; /// /// fn foo() { -/// // check that attributes and visibility are forwarded -/// singleton!(#[link_section = ".bss"] pub(crate) FOO: u8 = 0); +/// // check that attributes are forwarded +/// singleton!(#[link_section = ".bss"] FOO: u8 = 0); +/// singleton!(#[link_section = ".bss"]: u8 = 1); /// } /// ``` #[allow(dead_code)]