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

Make AtomicRef::new const fn #2

Merged
merged 10 commits into from
Nov 1, 2020
Merged

Make AtomicRef::new const fn #2

merged 10 commits into from
Nov 1, 2020

Conversation

yvt
Copy link
Contributor

@yvt yvt commented Jun 7, 2020

Turns AtomicRef::new into const fn, making it callable in constant contexts. This currently requires the use of a nightly-only feature, so it's feature-gated by the Cargo feature nightly. This can be removed in the future when this unstable feature is stabilized.

Raises the minimum supported Rust version to 1.32.0 (regardless of the nightly feature).
As of 5e5a057, this PR raises the minimum supported Rust version to 1.46.0.

This PR depends on #1.

yvt added 6 commits June 7, 2020 14:42
Raises the minimum supported Rust version to 1.32.0.
Requires the following unstable features:

 - `const_fn` for constructing `PhantomData<&mut _>`
   <rust-lang/rust#57563>
 - `const_if_match` for using `match` in a user-defined `const fn`
   <rust-lang/rust#49146>
@mystor
Copy link
Owner

mystor commented Jun 7, 2020

This feature is on-route to being stabilized in the near future (rust-lang/rust#72437). It might be nice to avoid the nightly feature here by waiting for that feature to be stabilized first, and releasing a 0.2.0 which requires that rustc version, and gets rid of unnecessary APIs like static_atomic_ref!.

If you need const constructors right now, it might be easier to add:

const fn null() -> Self {
    AtomicRef {
        data: AtomicPtr::new(ptr::null_mut()),
        _marker: PhantomData,
    }
}

const fn from(r: &'a T) -> Self {
    AtomicRef {
        data: AtomicPtr::new(r as *const T as *mut T),
        _marker: PhantomData,
    }
}

@yvt
Copy link
Contributor Author

yvt commented Oct 31, 2020

I added commits that got rid of nightly feature since const_if_match was stabilized in 1.46.0.

@yvt yvt changed the title Make AtomicRef::new const fn (nightly-only) Make AtomicRef::new const fn Oct 31, 2020
src/lib.rs Outdated Show resolved Hide resolved
These reexports are no longer necessary since we removed the
`static_atomic_ref` macro in 7b6f17e.
Copy link
Owner

@mystor mystor left a comment

Choose a reason for hiding this comment

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

Thanks!

@mystor mystor merged commit 681aafa into mystor:master Nov 1, 2020
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.

2 participants