aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/macros/src
diff options
context:
space:
mode:
Diffstat (limited to 'cortex-m-rt/macros/src')
-rw-r--r--cortex-m-rt/macros/src/lib.rs45
1 files changed, 21 insertions, 24 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs
index 8f78551..0d29f55 100644
--- a/cortex-m-rt/macros/src/lib.rs
+++ b/cortex-m-rt/macros/src/lib.rs
@@ -114,20 +114,19 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
let vars = statics
.into_iter()
.map(|var| {
+ let attrs = var.attrs;
let ident = var.ident;
- // `let` can't shadow a `static mut` so we must give the `static` a different
- // name. We'll create a new name by appending an underscore to the original name
- // of the `static`.
- let mut ident_ = ident.to_string();
- ident_.push('_');
- let ident_ = Ident::new(&ident_, Span::call_site());
let ty = var.ty;
let expr = var.expr;
quote!(
- static mut #ident_: #ty = #expr;
#[allow(non_snake_case)]
- let #ident: &'static mut #ty = unsafe { &mut #ident_ };
+ let #ident: &'static mut #ty = unsafe {
+ #(#attrs)*
+ static mut #ident: #ty = #expr;
+
+ &mut #ident
+ };
)
}).collect::<Vec<_>>();
@@ -403,20 +402,19 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
let vars = statics
.into_iter()
.map(|var| {
+ let attrs = var.attrs;
let ident = var.ident;
- // `let` can't shadow a `static mut` so we must give the `static` a different
- // name. We'll create a new name by appending an underscore to the original name
- // of the `static`.
- let mut ident_ = ident.to_string();
- ident_.push('_');
- let ident_ = Ident::new(&ident_, Span::call_site());
let ty = var.ty;
let expr = var.expr;
quote!(
- static mut #ident_: #ty = #expr;
#[allow(non_snake_case)]
- let #ident: &mut #ty = unsafe { &mut #ident_ };
+ let #ident: &mut #ty = unsafe {
+ #(#attrs)*
+ static mut #ident: #ty = #expr;
+
+ &mut #ident
+ };
)
}).collect::<Vec<_>>();
@@ -548,20 +546,19 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
let vars = statics
.into_iter()
.map(|var| {
+ let attrs = var.attrs;
let ident = var.ident;
- // `let` can't shadow a `static mut` so we must give the `static` a different
- // name. We'll create a new name by appending an underscore to the original name
- // of the `static`.
- let mut ident_ = ident.to_string();
- ident_.push('_');
- let ident_ = Ident::new(&ident_, Span::call_site());
let ty = var.ty;
let expr = var.expr;
quote!(
- static mut #ident_: #ty = #expr;
#[allow(non_snake_case)]
- let #ident: &mut #ty = unsafe { &mut #ident_ };
+ let #ident: &mut #ty = unsafe {
+ #(#attrs)*
+ static mut #ident: #ty = #expr;
+
+ &mut #ident
+ };
)
}).collect::<Vec<_>>();