Skip to content

Commit

Permalink
remove unstable_const feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 26, 2024
1 parent a04cfb1 commit 637b30a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 62 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ jobs:
# with backwards compatibility workarounds.
run: cargo test --lib

nightly:
name: Test Suite (nightly features)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
- name: Run cargo test
# `--lib` prevents doctests from being run.
# This is due to `unstable_const` requiring extra `feature(...)` directives
# which the doctests do not have.
run: cargo test --all-features --lib

miri:
name: Test Suite (Miri)
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Clarify documentation about macro indirection
- Added changelog
- Turn the crate into a thin stdlib wrapper on rustc>=1.77
- Remove `unstable_offset_of`
- Remove `unstable_offset_of` and `unstable_const`; they are not needed any more on recent nightlies

## v0.9.0 (18/05/2023)
### Added
Expand Down
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@ autocfg = "1"

[dev-dependencies]
doc-comment = "0.3"

[features]
default = []
unstable_const = []
36 changes: 3 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,7 @@ fn main() {
```

## Usage in constants ##
`memoffset` has support for compile-time `offset_of!` on rust>=1.65, or on older nightly compilers.
`memoffset` has support for compile-time `offset_of!` on rust>=1.65.

### Usage on stable Rust ###
Constant evaluation is automatically enabled and available on stable compilers starting with rustc 1.65.

This is an incomplete implementation with one caveat:
Due to dependence on [`#![feature(const_refs_to_cell)]`](https://github.com/rust-lang/rust/issues/80384), you cannot get the offset of a `Cell` field in a const-context on a rustc version less than 1.77.

### Usage on somewhat recent nightlies ###

If you're using a nightly that does not yet have `core::mem::offset_of!()` and you require the ability to get the offset of a `Cell`,
you'll have to enable the `unstable_const` cargo feature, as well as enabling `const_refs_to_cell` in your crate root.

Do note that `unstable_const` is an unstable feature that is set to be removed in a future version of `memoffset`.

Cargo.toml:
```toml
[dependencies.memoffset]
version = "0.9"
features = ["unstable_const"]
```

Your crate root: (`lib.rs`/`main.rs`)
```rust,ignore
#![feature(const_refs_to_cell)]
```

### Usage on older nightlies ###
In order to use it on an older nightly compiler, you must enable the `unstable_const` crate feature and several compiler features.

Your crate root: (`lib.rs`/`main.rs`)
```rust,ignore
#![feature(const_ptr_offset_from, const_refs_to_cell)]
```
On versions below 1.77, this is an incomplete implementation with one caveat:
Due to dependence on [`#![feature(const_refs_to_cell)]`](https://github.com/rust-lang/rust/issues/80384), you cannot get the offset of a `Cell` field in a const-context.
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
//! ```
#![no_std]
#![cfg_attr(
all(feature = "unstable_const", not(stable_const)),
feature(const_ptr_offset_from)
)]
#![cfg_attr(feature = "unstable_const", feature(const_refs_to_cell))]

#[macro_use]
#[cfg(doctests)]
Expand Down
10 changes: 5 additions & 5 deletions src/offset_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! _memoffset__let_base_ptr {
}

/// Macro to compute the distance between two pointers.
#[cfg(any(feature = "unstable_const", stable_const))]
#[cfg(stable_const)]
#[macro_export]
#[doc(hidden)]
macro_rules! _memoffset_offset_from_unsafe {
Expand All @@ -58,7 +58,7 @@ macro_rules! _memoffset_offset_from_unsafe {
unsafe { (field as *const u8).offset_from(base as *const u8) as usize }
}};
}
#[cfg(not(any(feature = "unstable_const", stable_const)))]
#[cfg(not(stable_const))]
#[macro_export]
#[doc(hidden)]
macro_rules! _memoffset_offset_from_unsafe {
Expand Down Expand Up @@ -368,7 +368,7 @@ mod tests {
assert_eq!(f_ptr as usize + 0, raw_field_union!(f_ptr, Foo, c) as usize);
}

#[cfg(any(feature = "unstable_const", stable_offset_of, stable_const))]
#[cfg(any(stable_offset_of, stable_const))]
#[test]
fn const_offset() {
#[repr(C)]
Expand All @@ -381,7 +381,7 @@ mod tests {
assert_eq!([0; offset_of!(Foo, b)].len(), 4);
}

#[cfg(feature = "unstable_const")]
#[cfg(stable_offset_of)]
#[test]
fn const_offset_interior_mutable() {
#[repr(C)]
Expand All @@ -393,7 +393,7 @@ mod tests {
assert_eq!([0; offset_of!(Foo, b)].len(), 4);
}

#[cfg(any(feature = "unstable_const", stable_offset_of, stable_const))]
#[cfg(any(stable_offset_of, stable_const))]
#[test]
fn const_fn_offset() {
const fn test_fn() -> usize {
Expand Down

0 comments on commit 637b30a

Please sign in to comment.