-
Notifications
You must be signed in to change notification settings - Fork 102
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
Remove references to static mut
#483
Remove references to static mut
#483
Conversation
835136f
to
a40ffdd
Compare
I re-tested the following examples and they are still working:
I'm going to tag a few of the original authors by their examples below. If you still have access to some suitable hardware it would be really awesome if you can re-test these examples in the next week or two(!)
|
Hi! Thanks for doing this - I'm traveling this week, but I'll test it as soon as I'm back to my hardware |
@richardeoin thanks again for all the work you do maintaining this! I tested examples/serial-dma.rs on an ST NUCLEO-H743ZI2 board and it worked, I checked the transmitted data. I also tested examples/spi-dma-rtic.rs on the same board and checked the transmitted data. Well the first few bytes at least, I had to decode manually because my scope's SPI decoder wasn't working. It's been a while. Rather than doing |
Can confirm |
Creating a mutable reference like
|
rust/#114447 made `&mut MY_STATIC_MUT` a warning, with the intention of disallowing it entirely in the 2024 edition. We never used this in the crate itself, but it is used in many examples. This commit removes these references from the examples. In general the new approach is to change `static mut` of type `X` to type `MaybeUninit<X>`. These can then cleanly be accessed with [`MY_STATIC_MUT.write()`](https://doc.rust-lang.org/core/mem/union.MaybeUninit.html#method.write) followed by [`MY_STATIC_MUT.assume_init_mut()`](https://doc.rust-lang.org/core/mem/union.MaybeUninit.html#method.assume_init_mut). Where we need to cast a `MaybeUninit<[X; N]>` to a `[MaybeUninit<X>; N]` in order to initialise it element-by-element, the `&mut *ptr::addr_of_mut!(MY_STATIC_MUT)` construction is still used. After initialisation, we can then access it with `MY_STATIC_MUT.assume_init_mut()`. In a few DMA Examples we were taking a reference `&mut TARGET_BUFFER` without initialising TARGET_BUFFER. This commit changes this to `TARGET_BUFFER.assume_init_mut()` *without* initialising `TARGET_BUFFER`. This was and remains UB. * USB Examples: `static mut EP_MEMORY` now has type `MaybeUninit<[u32; 1024]>` * Ethernet Examples: `static mut DES_RING` now has type `MaybeUninit<ethernet::DesRing<4, 4>>`
a40ffdd
to
01f9d21
Compare
Rebased onto master |
Confirmed |
rust/#114447 made
&mut MY_STATIC_MUT
a warning, with the intention of disallowing it entirely in the 2024 edition. We never used this in the crate itself, but it is used in many examples.This commit removes these references from the examples. In general the new approach is to change
static mut
of typeX
to typeMaybeUninit<X>
. These can then cleanly be accessed withMY_STATIC_MUT.write()
followed byMY_STATIC_MUT.assume_init_mut()
.Where we need to cast a (reference to a)
MaybeUninit<[X; N]>
to a[MaybeUninit<X>; N]
in order to initialise it element-by-element, the&mut *ptr::addr_of_mut!(MY_STATIC_MUT)
construction is still used. After initialisation, we can then access it withMY_STATIC_MUT.assume_init_mut()
.In a few DMA Examples we were taking a reference
&mut TARGET_BUFFER
without initialising TARGET_BUFFER. This commit changes this toTARGET_BUFFER.assume_init_mut()
without initialisingTARGET_BUFFER
. This was and remains UB.static mut EP_MEMORY
now has typeMaybeUninit<[u32; 1024]>
static mut DES_RING
now has typeMaybeUninit<ethernet::DesRing<4, 4>>