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

Fix build error that assigning to &T is undefined behavior #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
//! let received = block!(rx.read()).unwrap();
//! ```

use core::cell::UnsafeCell;
use core::marker::PhantomData;
use core::ptr;

Expand Down Expand Up @@ -419,7 +420,7 @@ impl<USART: UsartX> crate::hal::serial::Write<u8> for Tx<USART> {
// NOTE(unsafe) atomic write to stateless register
// NOTE(write_volatile) 8-bit write that's not possible through the svd2rust API
unsafe {
ptr::write_volatile(&(*USART::ptr()).data as *const _ as *mut _, byte)
ptr::write_volatile(UnsafeCell::raw_get(&(*USART::ptr()).data as *const _ as _), byte);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is the creation of a reference, but creating a reference here is useless, it's not required, using the addr_of_mut! macro should create a pointer to be field without a reference:

Suggested change
ptr::write_volatile(UnsafeCell::raw_get(&(*USART::ptr()).data as *const _ as _), byte);
ptr::write_volatile(addr_of_mut!((*USART::ptr()).data), byte);

Note that the lint is best-effort, it can be defeated, and I think that's one of the pattern.

}
Ok(())
} else {
Expand Down
Loading