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

object_subclass macro creates mutable reference to mutable static #1516

Closed
felinira opened this issue Sep 24, 2024 · 1 comment · Fixed by #1517
Closed

object_subclass macro creates mutable reference to mutable static #1516

felinira opened this issue Sep 24, 2024 · 1 comment · Fixed by #1517

Comments

@felinira
Copy link
Contributor

I stumbled upon this bit:

unsafe { ::std::ptr::NonNull::from(&mut DATA) }

which throws the following warning (which is then swallowed because it's coming from a macro invocation):

creating a mutable reference to mutable static is discouraged
for more information, see issue #114447 rust-lang/rust#114447
this will be a hard error in the 2024 edition

This will fail to compile in rust 2024 either way, so we need to deal with this before upgrading. However, this is creating a mutable temporary reference that is then converted into a pointer and subsequently dropped. We should use std::ptr::addr_of_mut!() instead, and also make sure we are actually using it correctly here.

@sdroege
Copy link
Member

sdroege commented Sep 24, 2024

Yes, this code is from before addr_of_mut! was stable :) You make a PR?

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 a pull request may close this issue.

2 participants