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

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

jannic
Copy link
Member

@jannic jannic commented Oct 12, 2024

On nightly beta, 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
@adamgreig
Copy link
Member

Thanks. I think it makes sense to allow the lint for now, since it's otherwise hard for the user to do anything about.

@adamgreig adamgreig added this pull request to the merge queue Oct 18, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 18, 2024
@adamgreig adamgreig added this pull request to the merge queue Oct 18, 2024
Merged via the queue into rust-embedded:master with commit 6a324a8 Oct 18, 2024
11 checks passed
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.

2 participants