Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shared references of mutable static warnings #3841

@valexandru

Description

@valexandru

While compiling tock with the latest nightly version of rust, nightly-2024-02-08, I encounter 25 warnings regarding the usage of shared references of mutable static in folders such as arch/, kernel/, chips/ and boards/ as it can be seen bellow:

warning: shared reference of mutable static is discouraged
   --> kernel/src/deferred_call.rs:145:28
    |
145 |         let ctr = unsafe { &CTR };
    |                            ^^^^ shared reference of mutable static
    |
    = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
    = note: reference of mutable static is a hard error from 2024 edition
    = note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
    = note: `#[warn(static_mut_ref)]` on by default
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
    |
145 |         let ctr = unsafe { addr_of!(CTR) };

If I understand correctly, for the moment this is just a warning, but it will soon become a compile error. We will need some workarounds for this.

Todo

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions