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

Removed use of static mut. #85

Merged
merged 1 commit into from
Mar 14, 2024
Merged

Removed use of static mut. #85

merged 1 commit into from
Mar 14, 2024

Conversation

jonathanpallant
Copy link
Member

@jonathanpallant jonathanpallant commented Mar 11, 2024

Remove static mut values, our references to which were going to cause a warning in the next Rust release.

Uses the grounded crate, and a custom wrapper to make an !Sync type Sync.

Closes: #84

Use the grounded crate to provide an unsafe cell containing a type that is maybe initialised.
@jonathanpallant
Copy link
Member Author

Now works on beta:

$ cargo +beta build
    Finished dev [optimized + debuginfo] target(s) in 0.04s
$ rustc +beta --version
rustc 1.77.0-beta.7 (339fb6965 2024-03-06)

It used to fail:

$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ cargo +beta build
   Compiling dk v0.0.0 (/Users/jonathan/Documents/ferrous-systems/rust-exercises/nrf52-code/boards/dk)
error: creating a mutable reference to mutable static is discouraged
   --> /Users/jonathan/Documents/ferrous-systems/rust-exercises/nrf52-code/boards/dk/src/lib.rs:277:36
    |
277 |         ep0in: unsafe { Ep0In::new(&mut EP0IN_BUF) },
    |                                    ^^^^^^^^^^^^^^ mutable reference to mutable static
    |
    = note: for more information, see issue #114447 </~https://github.com/rust-lang/rust/issues/114447>
    = note: this will be a hard error in the 2024 edition
    = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
note: the lint level is defined here
   --> /Users/jonathan/Documents/ferrous-systems/rust-exercises/nrf52-code/boards/dk/src/lib.rs:6:9
    |
6   | #![deny(warnings)]
    |         ^^^^^^^^
    = note: `#[deny(static_mut_refs)]` implied by `#[deny(warnings)]`
help: use `addr_of_mut!` instead to create a raw pointer
    |
277 |         ep0in: unsafe { Ep0In::new(addr_of_mut!(EP0IN_BUF)) },
    |                                    ~~~~~~~~~~~~~~~~~~~~~~~

error: could not compile `dk` (lib) due to 1 previous errorusb-app git:(main)

@miguelraz
Copy link
Contributor

I got 5 working builds with cargo +beta build. 🎉

@miguelraz
Copy link
Contributor

miguelraz commented Mar 13, 2024

Writing this for posterity:
I spent a chunk of my morning debugging this build because I kept getting a

error[E0463]: can't find crate for `core`
  |
  = note: the `thumbv7em-none-eabihf` target may not be installed
  = help: consider downloading the target with `rustup target add thumbv7em-none-eabihf`

error[E0463]: can't find crate for `compiler_builtins`

series of errors when building the hal-app BUT I do have a thumb7em-none-eabihf target installed, just not on beta!

The fix was to switch to beta, then add the target, and everything built.

Pretty sure I should file an issue that some diagnostic or another should come up and suggest doing that - it was not obvious targets are dependent on rustup tool by default from the error message.

@jonathanpallant
Copy link
Member Author

I'll ask on the project Zulip about that - I suspect the issue is that rustc doesn't know how it was invoked, and so it can't tell you what rustup arguments to use.

@jonathanpallant jonathanpallant merged commit afe7263 into main Mar 14, 2024
2 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.

Note: use of static mut is a warning in 1.77
2 participants