Skip to content

Commit ef8d073

Browse files
committed
Implement PinInitable for UnsafePinned behind feature flag.
Add the `unsafe-pinned` feature which gates the `PinInitable` implementation of the `core::pin::UnsafePinned` struct. For now this is just a cargo feature, but once `core::pin::UnsafePinned` is stable a config flag can be added to allow the usage of this implementation in the linux kernel. Signed-off-by: Christian Schrefl <chrisi.schrefl@gmail.com>
1 parent f0349ab commit ef8d073

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ jobs:
123123
- uses: dtolnay/rust-toolchain@stable
124124
- run: cargo install cargo-hack
125125
- run: git config user.name "github-runner" && git config user.email "<>"
126-
- run: git rebase --exec 'cargo hack --clean-per-run --feature-powerset --exclude-features alloc --exclude-features default --version-range 1.82.. --clean-per-version check --locked' --exec 'cargo clean' --root
126+
- run: git rebase --exec 'cargo hack --clean-per-run --feature-powerset --exclude-features alloc --exclude-features default --exclude-features unsafe-pinned --version-range 1.82.. --clean-per-version check --locked' --exec 'cargo clean' --root
127127
nightly-msrv:
128128
runs-on: ubuntu-latest
129129
steps:
@@ -137,7 +137,7 @@ jobs:
137137
- run: cargo install cargo-hack
138138
- run: cargo install cargo-expand
139139
- run: git config user.name "github-runner" && git config user.email "<>"
140-
- run: git rebase --exec 'cargo hack --clean-per-run --feature-powerset --version-range 1.78.. --clean-per-version check --locked' --exec 'cargo clean' --root
140+
- run: git rebase --exec 'cargo hack --clean-per-run --feature-powerset --exclude-features unsafe-pinned --version-range 1.78.. --clean-per-version check --locked' --exec 'cargo clean' --root
141141
env:
142142
RUSTC_BOOTSTRAP: 1
143143
os-check:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pin-init-internal = { path = "./internal", version = "=0.0.5" }
2121
default = ["std", "alloc"]
2222
std = []
2323
alloc = []
24+
unsafe-pinned = []
2425

2526
[build-dependencies]
2627
rustc_version = "0.4"

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,3 +1549,12 @@ impl<T> PinInitable<T> for UnsafeCell<T> {
15491549
unsafe { cast_pin_init(value_init) }
15501550
}
15511551
}
1552+
1553+
#[cfg(feature = "unsafe-pinned")]
1554+
impl<T> PinInitable<T> for core::pin::UnsafePinned<T> {
1555+
fn pin_init<E>(init: impl PinInit<T, E>) -> impl PinInit<Self, E> {
1556+
// SAFETY:
1557+
// `UnsafePinned<T>` has a compatible layout to `T`.
1558+
unsafe { cast_pin_init(init) }
1559+
}
1560+
}

0 commit comments

Comments
 (0)