Skip to content

Commit c5d24f8

Browse files
bors[bot]japaric
andcommitted
Merge #140
140: entry/exception/interrupt: improvements to the `static mut` transformation r=therealprof a=japaric see individual commits for details Co-authored-by: Jorge Aparicio <[email protected]>
2 parents ac9c053 + 0180258 commit c5d24f8

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

cortex-m-rt/macros/src/lib.rs

+21-24
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,19 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
113113
let vars = statics
114114
.into_iter()
115115
.map(|var| {
116+
let attrs = var.attrs;
116117
let ident = var.ident;
117-
// `let` can't shadow a `static mut` so we must give the `static` a different
118-
// name. We'll create a new name by appending an underscore to the original name
119-
// of the `static`.
120-
let mut ident_ = ident.to_string();
121-
ident_.push('_');
122-
let ident_ = Ident::new(&ident_, Span::call_site());
123118
let ty = var.ty;
124119
let expr = var.expr;
125120

126121
quote!(
127-
static mut #ident_: #ty = #expr;
128122
#[allow(non_snake_case)]
129-
let #ident: &'static mut #ty = unsafe { &mut #ident_ };
123+
let #ident: &'static mut #ty = unsafe {
124+
#(#attrs)*
125+
static mut #ident: #ty = #expr;
126+
127+
&mut #ident
128+
};
130129
)
131130
}).collect::<Vec<_>>();
132131

@@ -401,20 +400,19 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
401400
let vars = statics
402401
.into_iter()
403402
.map(|var| {
403+
let attrs = var.attrs;
404404
let ident = var.ident;
405-
// `let` can't shadow a `static mut` so we must give the `static` a different
406-
// name. We'll create a new name by appending an underscore to the original name
407-
// of the `static`.
408-
let mut ident_ = ident.to_string();
409-
ident_.push('_');
410-
let ident_ = Ident::new(&ident_, Span::call_site());
411405
let ty = var.ty;
412406
let expr = var.expr;
413407

414408
quote!(
415-
static mut #ident_: #ty = #expr;
416409
#[allow(non_snake_case)]
417-
let #ident: &mut #ty = unsafe { &mut #ident_ };
410+
let #ident: &mut #ty = unsafe {
411+
#(#attrs)*
412+
static mut #ident: #ty = #expr;
413+
414+
&mut #ident
415+
};
418416
)
419417
}).collect::<Vec<_>>();
420418

@@ -545,20 +543,19 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
545543
let vars = statics
546544
.into_iter()
547545
.map(|var| {
546+
let attrs = var.attrs;
548547
let ident = var.ident;
549-
// `let` can't shadow a `static mut` so we must give the `static` a different
550-
// name. We'll create a new name by appending an underscore to the original name
551-
// of the `static`.
552-
let mut ident_ = ident.to_string();
553-
ident_.push('_');
554-
let ident_ = Ident::new(&ident_, Span::call_site());
555548
let ty = var.ty;
556549
let expr = var.expr;
557550

558551
quote!(
559-
static mut #ident_: #ty = #expr;
560552
#[allow(non_snake_case)]
561-
let #ident: &mut #ty = unsafe { &mut #ident_ };
553+
let #ident: &mut #ty = unsafe {
554+
#(#attrs)*
555+
static mut #ident: #ty = #expr;
556+
557+
&mut #ident
558+
};
562559
)
563560
}).collect::<Vec<_>>();
564561

0 commit comments

Comments
 (0)