You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is no longer encouraged, and will stop working in the 2024 edition.
warning: creating a mutable reference to mutable static is discouraged
|
231 | let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY });
| ^^^^^^^^^^^^^^ 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
help: use `addr_of_mut!` instead to create a raw pointer
|
231 | unsafe { USB_ALLOCATOR = Some(UsbBus::new(usb, addr_of_mut!(EP_MEMORY))) };
| ~~~~~~~~~~~~~~~~~~~~~~~
There's always ways around this, such as &mut *addr_of_mut!(EP_MEMORY) or using MaybeUninit and as_mut_ptr() to get a 'static &mut - which gets you the same safety issues if you use the reference for anything else than intended but is not considered an error for now.
But seeing how the memory is shared with a hardware peripheral, even if the "only one &mut at a time" rule was upheld from the Rust perspective it kind of goes against the philosophy to have hardware write to the buffer at the same time. And I'm not sure if the "only one &mut" rule is even completely followed currently. A pointer would probably be a better idea.
As of rust-lang/rust#114447, it appears that the common pattern of
is no longer encouraged, and will stop working in the 2024 edition.
The examples still use this outdated pattern.
My understanding is that the "preferred" solution is to make
UsbBus::new
take a pointer rather than a reference, although I'm not 100% sure.The text was updated successfully, but these errors were encountered: