Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow static_mut_refs lint in macro expansions #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jannic
Copy link
Member

@jannic jannic commented Oct 12, 2024

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.

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.
rust-embedded#411 for discussion.
@jannic jannic requested a review from a team as a code owner October 12, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant