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

Use stablilized addr_of macro #50

Merged
merged 1 commit into from
Mar 8, 2021
Merged

Use stablilized addr_of macro #50

merged 1 commit into from
Mar 8, 2021

Conversation

fbq
Copy link
Contributor

@fbq fbq commented Mar 8, 2021

Since Rust 1.51.0, support for macro addr_of!() has been stabilized1,
and this provides a way to get a raw pointer without potential UB in
some cases.

Memoffset alreadly uses the feature at the pre-stablilized stage (the
macro was named as raw_const then). Therefore, switch to use the
stablilized version (and name) and remove the out-dated version, also
remove the related feature gate.

Signed-off-by: Boqun Feng boqun.feng@gmail.com

@RalfJung
Copy link
Collaborator

RalfJung commented Mar 8, 2021

Thanks for the PR!

I'm afraid this won't work, as CI shows, since the crate has to keep working with older versions of rustc. We'll have to do something similar to MaybeUninit, where build.rs detects the current Rust version and uses the proper code on newer compilers while using a (technically less correct but still functional) replacement on older compilers.

@fbq
Copy link
Contributor Author

fbq commented Mar 8, 2021

@RalfJung Thanks. I saw the problem and was struggling to find a solution. Your suggestion is very helpful, Let me look into it and send an updated version.

README.md Outdated
`memoffset` can make use of that feature to avoid what is technically Undefined Behavior.
Use the `unstable_raw` feature to enable this.
Since Rust 1.51.0, [a way to create raw pointers](https://github.com/rust-lang/rust/issues/73394) that avoids creating intermediate safe references
has been stablilized, now `memoffset` makes use of that feature to avoid what is technically Undefined Behavior.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can just remove this part of the readme; this is an internal cfg flag now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ;-)

Since Rust 1.51.0, support for macro addr_of! has been stabilized[1],
and this provides a way to get a raw pointer without potential UB in
some cases.

Memoffset alreadly uses the feature at the pre-stablilized stage (the
macro was named as raw_const! then). Therefore, switch to use the
stablilized version (and name) if Rust 1.51.0 and above is used,
otherwise use the original fallback version, which works in a less
technically correct way.

[1]: rust-lang/rust#72279

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
@RalfJung
Copy link
Collaborator

RalfJung commented Mar 8, 2021

Awesome, thanks a lot. :)

@RalfJung RalfJung merged commit 576166b into Gilnaa:master Mar 8, 2021
@RalfJung
Copy link
Collaborator

RalfJung commented Mar 8, 2021

@Gilnaa might be a good idea to make a new release with this MR when Rust 1.51 comes out. :)

@Gilnaa
Copy link
Owner

Gilnaa commented Mar 8, 2021

Sure :)
I'll put on a reminder

@est31
Copy link
Contributor

est31 commented Mar 25, 2021

Filed an issue for it: #51

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.

4 participants