Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c2040dc
tests: check that enums cannot derive `Zeroable`
BennoLossin Oct 11, 2025
aaad64c
tests: ensure the guards cannot be accessed
BennoLossin Oct 20, 2025
4a14fbe
tests: ensure that the data cannot be accessed
BennoLossin Oct 20, 2025
40a9926
tests: add new test case to underscore
BennoLossin Oct 22, 2025
2dc65fd
tests: add `MaybeZeroable` expansion test with generics
BennoLossin Jan 7, 2026
69cbb23
remove `try_` versions of the initializer macros
BennoLossin Oct 20, 2025
cd0e0c5
allow the crate to refer to itself as `pin-init` in doc tests
BennoLossin Oct 20, 2025
2622944
add `syn` dependency and remove `proc-macro[2]` and `quote` workarounds
BennoLossin Oct 11, 2025
9c2ed72
internal: add utility API for syn error handling
BennoLossin Jan 9, 2026
fd5d533
rewrite `derive(Zeroable)` and `derive(MaybeZeroable)` using `syn`
BennoLossin Oct 11, 2025
bee4112
rewrite the `#[pinned_drop]` attribute macro using `syn`
BennoLossin Oct 11, 2025
7e258db
rewrite `#[pin_data]` using `syn`
BennoLossin Oct 12, 2025
7539dd3
add `?Sized` bounds to traits in `#[pin_data]` macro
BennoLossin Oct 16, 2025
36ee8ea
rewrite the initializer macros using `syn`
BennoLossin Oct 17, 2025
a4687b3
add `#[default_error(<type>)]` attribute to initializer macros
BennoLossin Oct 22, 2025
6edf8d3
internal: init: add support for attributes on initializer fields
BennoLossin Dec 23, 2025
07d039a
tests: add test to check cfgs working correctly
BennoLossin Dec 23, 2025
61919f0
internal: init: add escape hatch for referencing initialized fields
BennoLossin Dec 23, 2025
f992b8b
tests: ensure that `#[disable_initialized_field_access]` does not emi…
BennoLossin Dec 23, 2025
3495122
tests: track the diagnostics of packed structs and field accessors
BennoLossin Dec 23, 2025
437e27c
tests: update prettyplease to support modern expressions
BennoLossin Dec 23, 2025
e70781f
tests: track no_field_access expansion
BennoLossin Dec 23, 2025
6963673
internal: init: simplify Zeroable safety check
BennoLossin Jan 10, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `[pin_]init_scope` functions to run arbitrary code inside of an initializer.
- `&'static mut MaybeUninit<T>` now implements `InPlaceWrite`. This enables users to use external
allocation mechanisms such as `static_cell`.
- Rewrote all proc-macros using `syn`.

### Changed

Expand All @@ -21,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
code at that point.
- Make the `[try_][pin_]init!` macros expose initialized fields via a `let`
binding as `&mut T` or `Pin<&mut T>` for later fields.
- `derive([Maybe]Zeroable)` now support tuple structs

## [0.0.10] - 2025-08-19

Expand Down
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ libc = "0.2"
trybuild = { version = "1.0", features = ["diff"] }
macrotest = "1.0"
# needed for macrotest, have to enable verbatim feature to be able to format `&raw` expressions.
prettyplease = { version = "0.2", features = ["verbatim"] }
prettyplease = { version = "0.2.37", features = ["verbatim"] }

[lints.rust]
non_ascii_idents = "deny"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct DriverData {

impl DriverData {
fn new() -> impl PinInit<Self, Error> {
try_pin_init!(Self {
pin_init!(Self {
status <- CMutex::new(0),
buffer: Box::init(pin_init::init_zeroed())?,
}? Error)
Expand Down
19 changes: 9 additions & 10 deletions examples/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use core::{
cell::Cell,
convert::Infallible,
marker::PhantomPinned,
pin::Pin,
ptr::{self, NonNull},
Expand All @@ -31,31 +30,31 @@ pub struct ListHead {

impl ListHead {
#[inline]
pub fn new() -> impl PinInit<Self, Infallible> {
try_pin_init!(&this in Self {
pub fn new() -> impl PinInit<Self> {
pin_init!(&this in Self {
next: unsafe { Link::new_unchecked(this) },
prev: unsafe { Link::new_unchecked(this) },
pin: PhantomPinned,
}? Infallible)
})
}

#[inline]
#[allow(dead_code)]
pub fn insert_next(list: &ListHead) -> impl PinInit<Self, Infallible> + '_ {
try_pin_init!(&this in Self {
pub fn insert_next(list: &ListHead) -> impl PinInit<Self> + '_ {
pin_init!(&this in Self {
prev: list.next.prev().replace(unsafe { Link::new_unchecked(this)}),
next: list.next.replace(unsafe { Link::new_unchecked(this)}),
pin: PhantomPinned,
}? Infallible)
})
}

#[inline]
pub fn insert_prev(list: &ListHead) -> impl PinInit<Self, Infallible> + '_ {
try_pin_init!(&this in Self {
pub fn insert_prev(list: &ListHead) -> impl PinInit<Self> + '_ {
pin_init!(&this in Self {
next: list.prev.next().replace(unsafe { Link::new_unchecked(this)}),
prev: list.prev.replace(unsafe { Link::new_unchecked(this)}),
pin: PhantomPinned,
}? Infallible)
})
}

#[inline]
Expand Down
10 changes: 5 additions & 5 deletions examples/pthread_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ mod pthread_mtx {
// SAFETY: mutex has been initialized
unsafe { pin_init_from_closure(init) }
}
try_pin_init!(Self {
data: UnsafeCell::new(data),
raw <- init_raw(),
pin: PhantomPinned,
}? Error)
pin_init!(Self {
data: UnsafeCell::new(data),
raw <- init_raw(),
pin: PhantomPinned,
}? Error)
}

#[allow(dead_code)]
Expand Down
16 changes: 14 additions & 2 deletions internal/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proc-macro = true
[dependencies]
quote = "1.0"
proc-macro2 = "1.0"
syn = { version = "2.0.86", features = ["full", "parsing", "visit-mut"] }

[build-dependencies]
rustc_version = "0.4"
Expand Down
30 changes: 30 additions & 0 deletions internal/src/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::fmt::Display;

use proc_macro2::TokenStream;
use syn::{spanned::Spanned, Error};

pub(crate) struct DiagCtxt(TokenStream);
pub(crate) struct ErrorGuaranteed(());

impl DiagCtxt {
pub(crate) fn error(&mut self, span: impl Spanned, msg: impl Display) -> ErrorGuaranteed {
let error = Error::new(span.span(), msg);
self.0.extend(error.into_compile_error());
ErrorGuaranteed(())
}

pub(crate) fn with(
fun: impl FnOnce(&mut DiagCtxt) -> Result<TokenStream, ErrorGuaranteed>,
) -> TokenStream {
let mut dcx = Self(TokenStream::new());
match fun(&mut dcx) {
Ok(mut stream) => {
stream.extend(dcx.0);
stream
}
Err(ErrorGuaranteed(())) => dcx.0,
}
}
}
152 changes: 0 additions & 152 deletions internal/src/helpers.rs

This file was deleted.

Loading