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

Conversation

ivq
Copy link

@ivq ivq commented Nov 25, 2023

Fixes #58

Copy link

@Tnze Tnze left a comment

Choose a reason for hiding this comment

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

I can confirm this fix the compiling error

@@ -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.

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.

Build failure on new toolchain
3 participants