Re: [PATCH 1/4] rust: add projection infrastructure
From: Gary Guo
Date: Sun Feb 22 2026 - 05:53:20 EST
On 2026-02-22 00:57, Benno Lossin wrote:
On Sat Feb 14, 2026 at 6:33 AM CET, Gary Guo wrote:
+#[macro_export]
+macro_rules! project_pointer {
+ (@gen $ptr:ident, ) => {};
+ // Field projection. `$field` needs to be `tt` to support tuple index like `.0`.
+ (@gen $ptr:ident, .$field:tt $($rest:tt)*) => {
+ // SAFETY: the provided closure always return in bounds pointer.
+ let $ptr = unsafe {
+ $crate::projection::ProjectField::proj($ptr, #[inline(always)] |ptr| {
By the way, how does this avoid `#![feature(stmt_expr_attributes)]`?
I don't know how, but attributes on closures passed direclty to functions has been stable
for basically ~forever. A quick check says that this is available since Rust 1.11.
Best,
Gary
Cheers,
Benno
+ // SAFETY: `$field` is in bounds, and no implicit `Deref` is possible (if the
+ // type implements `Deref`, Rust cannot infer the generic parameter `DEREF`).
+ &raw mut (*ptr).$field
+ })
+ };
+ $crate::project_pointer!(@gen $ptr, $($rest)*)
+ };