Skip to content

Commit fb688b1

Browse files
committed
Allow static_mut_refs lint in macro expansions
On nightly, the static_mut_refs lint defaults to warn. With some of our examples using `#[deny(warnings)]`, this leads to the following error: ``` error: creating a mutable reference to mutable static is discouraged --> cortex-m-rt/examples/entry-static.rs:15:16 | 15 | static mut COUNT: u32 = 0; | ^^^^^ mutable reference to mutable static | = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html> = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives ``` With edition 2024, the lint will probably default to deny. (https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html) To avoid that, set #[allow(static_mut_refs)] locally in the macro expansion. This only silences the warning and doesn't answer the underlying question if we want to do that transform at all. See eg. #411 for discussion.
1 parent 57ce011 commit fb688b1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
103103
#[doc(hidden)]
104104
#[export_name = "main"]
105105
pub unsafe extern "C" fn #tramp_ident() {
106+
#[allow(static_mut_refs)]
106107
#ident(
107108
#(#resource_args),*
108109
)
@@ -500,6 +501,7 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream {
500501
#[doc(hidden)]
501502
#[export_name = #ident_s]
502503
pub unsafe extern "C" fn #tramp_ident() {
504+
#[allow(static_mut_refs)]
503505
#ident(
504506
#(#resource_args),*
505507
)
@@ -614,6 +616,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream {
614616
#[doc(hidden)]
615617
#[export_name = #ident_s]
616618
pub unsafe extern "C" fn #tramp_ident() {
619+
#[allow(static_mut_refs)]
617620
#ident(
618621
#(#resource_args),*
619622
)

0 commit comments

Comments
 (0)