From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.95.126 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796132682; b=kn60gPw6HRWJ7C7cSeUwO8zHNUfi959+TZeCQw90iLWbRXxAG87+PUrlmI8JBBDyl97Y 4uTiujPtzd0waSCC9wqPlOvUa5mmBB7rgqk1HGBETfR7tZMRQj8RcbEJi6C0ft/gxdCDy iRn3ME1RYjlSzOH7Z7eSKVfHAsQ8T0Wyd+g/Whx1O+nFLpD6+HFjzNYjRGU7MivmsAdg7 azAGs2fmVLo87MBtdP5HtSvJih4ZPIL9h0AWZ0r8Kw6N2gNq9F2Jea6H76R1VWX77j1Fx QqgZEEpQz+2UxIao0DbnSqhchWmXfl84VsQanQYNZr9kn4MKD0jnWWMHmJkUKGtPtsA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796132682; h=DMARC-Filter:DKIM-Signature:Received:Received: Content-Transfer-Encoding:Content-Type:Date:Message-Id:From:To:Cc: Subject:X-Mailer:References:In-Reply-To:X-ClientProxiedBy: MIME-Version:X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=4a2ri2hudZnKeQJe/lqy5/G/mX/1srsTlugu30GF8Vg=; b=gU9EOgZSeh6ekRmOMlmbgHik1PHuz1zgSkWXEzrUQVtZRN5W0kN4MLgwPwQtzikR4VMS X/BSW6SVjAZg6n++hx1WBTZM2gqhfQNX2wiUFZEgRsVEdPZ/EPGaQk3YQ5Jn4z2VBwqIu KwRIDw6eXz117lupANlp4bJau1/lfUSq2GvBarE8V3LxnftzSjvVUxaImywYCz/bq0Gbp nHF5YvMkHUvVk5K06g/XXKm50KLwIieElWboh9erd82ugiQhbR7g9sRSFTvKrYH5aB7rn L/kuQZ77fBmc1Rn8R+ut9ey/3ai1r8rEOmDRHtpeJsau3u6nxyzCgUZbdOZ3T2LxRSg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=TuJntxwh; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.95.126 Received: from LO2P265CU024.outbound.protection.outlook.com (mail-uksouthazon11021126.outbound.protection.outlook.com [52.101.95.126]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC0BF606A32E; Tue, 1 Dec 2026 13:44:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC0BF606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=garyguo.net header.i=@garyguo.net header.a=rsa-sha256 header.s=selector1 header.b=TuJntxwh ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XcBVRGQQxEhHGMfVwdWWPFurjePtf9AizObmCJA2xRB47iJiF9mOd2MO8WbTvh5Te3OmYYmhwN43xyOQuclm95KiSV7EQ/JCYow/t8SUQwvXtlFN8SByOl2DTN6ULkJejgc6k69mt0KJdf5+8XhP5q1SJXJtRdEua/muvmyG1y8oe6BaNo8wE1ZBLDyo2TFY52JCG4+vVrdFIinYz794fAD9QukUzc7fmNO9aWfyuqmxvaeQAcYokO5VtV5vy0Jnw/io6+sDRjqFCLKb8IlA1T4HvceOA/vjKrWZGXyhws+JSNmdu+GTj2K0JegYU6JnUJ02VcDPGbgHtRKpSkhOSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4a2ri2hudZnKeQJe/lqy5/G/mX/1srsTlugu30GF8Vg=; b=fPD2mJIBXC4ftI7RBAByInWlqpp/R0+6LNVyEhl8BKQkHipKZpoZtPZ9oZCJ0gj+Dd89WEPS8nPUuk9rMyNcR+dzqa9KHUG0mSyE1DNvMzmA9HqgCRr498S+O91/e0JglCxACr2IQsxF0m5Inaec4BwYNUJYsr5nuRg1rTKIQmarBhFgEubUm+hOFEFitEc/0TDmThaD5N8HibkkLRv9xJPb4hU88TqGErSnQQ+qVROZavFyP030kDPV7GZkEmtnddv92hfUW/8QcXzH3CcPj3G6mr2XMWUOXPy5dkbP0ldsk9FLLfHBHLm6aeXiSXbrhsoo3wcFrPle6J4kVxGXtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4a2ri2hudZnKeQJe/lqy5/G/mX/1srsTlugu30GF8Vg=; b=TuJntxwhMuKSSXFCOa3ckwUxtlF8Cc6DvCjn+OaOgAZHHsgDLYEkpVs5ra5YRLg4tBFRzT2POBOWPej8stOptVrqWYJsOKJPod0TNip5eWQjWHab556BIPvBCI0E24cye5YpSP0iw/mgTkz/p/soFq3FYwZfwn5Q7O/7TfS7wz8= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1cb::9) by CWLP265MB5425.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1c6::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Tue, 1 Dec 2026 13:44:36 +0000 Received: from CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM ([fe80::55f6:f98b:7fad:c6e3]) by CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM ([fe80::55f6:f98b:7fad:c6e3%2]) with mapi id 15.21.0662.012; Tue, 1 Dec 2026 13:44:36 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 13:44:35 +0000 Message-Id: From: "Gary Guo" To: , "Gary Guo" , "Benno Lossin" , "Miguel Ojeda" , "Boqun Feng" , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , "Andreas Hindborg" , "Alice Ryhl" , "Trevor Gross" , "Danilo Krummrich" , "Daniel Almeida" , "Tamir Duberstein" , "Alexandre Courbot" , =?utf-8?q?Onur_=C3=96zkan?= Cc: , , "Gary Guo" Subject: Re: [PATCH] rust: pin-init: document self-referential feature X-Mailer: aerc 0.22.0 References: <20261124-dev-pin-init-doc-v1-1-dd0a3eda9018@garyguo.net> <771a56496a50fc1e8bed77b45b3aa77feedca77d.camel@mailbox.org> In-Reply-To: <771a56496a50fc1e8bed77b45b3aa77feedca77d.camel@mailbox.org> X-ClientProxiedBy: LO2P123CA0107.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:139::22) To CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:1cb::9) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CWLP265MB6051:EE_|CWLP265MB5425:EE_ X-MS-Office365-Filtering-Correlation-Id: 661eba16-6ebf-4fe4-342b-08df4fb13d09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|1800799024|10070799003|7416014|376014|921020|10067099003|56012099006|261102123227099003|261026121527099003|261021121427099003|261022075727099003|18002099003|22082099003|4143699003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: wpmg2hzAhtA4qnai/EKt0sxYrbCl0TGFBrLJZcWCLip2iDRgKNXHNoHEY13NOMV3LzE0fMPEiTw1fo0C3gZxs3aqgSKweuh0AIArfvZ/YP1bkn6Gd9sheHp+hDxgxT1VZhizLKHp72PRpC+Bmycpxoiy4zq8OnRXDrdhxrDv8EeHq4WwhdSI37+Kz93S0Hualn/TrLFUlLa5stlnWQJVdWuR1d3SB3OMgshNINZlplxSz/mLjV6FW7Pv8jHgPD261xRkUBD81ZpiG8pbGHSVZVdrUajBAIYpA1hclDYdlYbkOwv1hyYb+mdXsVtHTEoz3uMm2IOZtjPAsBnKJSEudCSATd0myw4RDmGz9yGs2BRhPGEZ5fFFp3M7u8t+ZQrYNGqOIyuqouB912t4KfRfS0XHkxwqXeVmMgorTGodV/SBL3j9E/KSvy3dRFf01/5njdWH2WDeKpyvPYkLjbecOtIRJ2APOt5vpiW0YQ5EAi51wAG2l/G5r/Ai8MEbyrMl1c+fvZe9/AFkdZSMXxbctQgQqHCfi8/mFvFrrqkA3ga0gzSmpoL8wVROpj6GcGc2dNfuRDUzhN31S48YIuUfkEOrPbgMaTS3fPuUsEiAjCzJxMqGqpEFqnj70hvKV1GZ3wzL94y7v2h0TroxUo6IOLJiXERF4KXghIxHWL0kUy2Pg0YaY3WNt6whzt+gXUaX2CXDB19PsF7ajFFut5ptJQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(1800799024)(10070799003)(7416014)(376014)(921020)(10067099003)(56012099006)(261102123227099003)(261026121527099003)(261021121427099003)(261022075727099003)(18002099003)(22082099003)(4143699003)(6133799003)(3023799007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?azFvYUNNTnBoVGlGWCtNdEovOGlZL1ZkZE0zVkduSkVXT2M1eUNBbW1qeFJv?= =?utf-8?B?M3JnT3J5d2Yyb1BCYVFCRlZKUmpndTRnNXRLcG1hQW9mY3BJczZQam1wQUFT?= =?utf-8?B?aWFLZTZoWjBJTVFOdDduWmk3V0Y3YitVTk8xVGE0YWRVN3NPSmpiZnNQajFp?= =?utf-8?B?S3FVRENWZzlSV0l4OVVYV0RxRlBBdnlrbE5uSjZwOTVpNzFlVDFpR1djbEZK?= =?utf-8?B?bXRocCtrQUhTVUpMM1cwR1g4dnBTT2t0ajVxcEl2bWtCSjhWSDArOEJvc1hy?= =?utf-8?B?eUdYbElmUXdaeXlQVktMQU1tZm9GRVg3TVE3VTJCclNBQ3ZGYkR5UWEwM2tP?= =?utf-8?B?UXpMSVFUcjR2TmJ3bkJBeXZ4NGtlM3MxUmw2VVViYX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2dqOStuSW5zSDBQK2taOXlE?= =?utf-8?B?c0xCZjhocmdveXNUaEhIaFcybmx1VE50YmZsSFdKNjJWOVlQcStSWUNiTHpC?= =?utf-8?B?M2ZEbWhhb0tzcjN6VmZ5dGF0aGNXR0tlZ0lsbVVsZ2oxc3YzKzVlUT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 661eba16-6ebf-4fe4-342b-08df4fb13d09 X-MS-Exchange-CrossTenant-AuthSource: CWLP265MB6051.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 13:44:36.4337 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cXj4MatYltxcgk5pQF5TGqGN0dzo/xM5/zsLqtbxCIL8kE8EBeKov6Rd4lf0zxyrgcoTSI5ALveVHtvTKi2CEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB5425 On Thu Nov 26, 2026 at 9:56 AM GMT, Philipp Stanner wrote: > On Tue, 2026-11-24 at 22:16 +0000, Gary Guo wrote: >> From: Gary Guo >>=20 >> Add a section to the documentation of `#[pin_data]` macro about >> the safe self-referential creation feature. > > Thx for writing this, that's very useful. I read through it. Just some > comments below: > >> +/// Here the field `part` captures the field lifetime `'msg` and thereb= y borrows the field `msg`. >> +/// A field may only borrow from fields declared after it: fields are d= ropped in declaration >> +/// order, so the borrowing field is then always dropped before the fie= ld it borrows. Structs >> +/// with borrowed fields or captured lifetimes do not implement `Unpin`= . > > Unpin is something the user would have to implement for his struct, > isn't it? So are you saying here that the macros do not generate Unpin? > Why's that mentioned, do you expect anyone to need / expect to have > Unpin? If you use `pin_data`, an `Unpin` implementation is controlled by `pin_data= `. I reckon this is also under-documented, but most users won't need to know any= way (unless they manually implement `Unpin` and hit a duplicate implementation errror). Typically, if all fields are `Unpin`, then the struct will be `Unp= in` despite use of `#[pin_data]`. For self-referential struct, `pin_data` generates a never-satisfied implementation and thus effectively never implement `Unpin` but also block = user from implementing it. This is true even if all fields are `Unpin`. E.g. struct Foo { y: &'x u32, x: u32, } all fields are `Unpin` but `Foo: !Unpin`. I'd probably not expand it out because most users won't need to care. > >> +/// ## Mutable Borrows >> +/// >> +/// A field is only shared-borrowed by default. To also allow `&mut` bo= rrows, mark the borrowed > > I think the English-bros say "To also allow *for* =E2=80=A6" > >> +/// field with `#[borrowed(mut)]`: >> +/// >> +/// ``` >> +/// # use pin_init::*; >> +/// #[pin_data] >> +/// struct MutSelfRef { >> +///=C2=A0=C2=A0=C2=A0=C2=A0 part: &'mut_msg mut str, >> +///=C2=A0=C2=A0=C2=A0=C2=A0 #[borrowed(mut)] >> +///=C2=A0=C2=A0=C2=A0=C2=A0 mut_msg: String, >> +/// } >> +/// >> +/// stack_pin_init!(let foo =3D pin_init!(MutSelfRef { >> +///=C2=A0=C2=A0=C2=A0=C2=A0 mut_msg: "hello world".to_owned(), >> +///=C2=A0=C2=A0=C2=A0=C2=A0 part: &mut mut_msg[..5], >> +/// })); >> +/// foo.as_mut().with_project(|proj| proj.part.make_ascii_uppercase()); >> +/// assert_eq!(*foo.part(), "HELLO"); > > Is #[borrowed(mut)] basically a better alternative to UnsafeCell? For some use cases perhaps, although `#[borrowed(mut)]` would make the fiel= d disappear from all `&self` and `Pin<&mut Self>` so you can only access it v= ia the mutable reference that is created during initialization. If it fits you= r use cases then it's a good replacement, but no generally true. > >> +/// ## Existential Lifetimes >> +/// >> +/// A field lifetime ties a borrow to a specific field. Sometimes a fie= ld should instead borrow >> +/// from something outside the struct that merely outlives one of the s= truct's lifetime >> +/// parameters. >>=20 > > "the struct's lifetime parameters" =3D=3D "the struct's members' lifetime > parameters" ? The current wording is correct. Struct have generic parameters, and it can either be lifetime parameter, type parameter or const parameter. Members do= n't have parameters. > > > It doesn't get fully clear to me why you mention "sometimes should > instead borrow from sth outside the struct". You seem to be referring > to "normal" structs that borrow something with a normal lifetime. So it > reads as if you fear that users might use self-referencial structs when > really their struct should just borrow something from the outside.. why > do you mention that, when would the user borrow something that the > struct already has which shouldn't be in there? No this feature is somewhat independent of self-referential borrow. You can= have a struct that just borrow from outside the struct only, but use the `exists= ` feature: struct Foo<'a> where exists<'inv>: 'a { foo: Mutex<&'inv ()>, } This is similar to struct Foo<'a> { foo: Mutex<&'a ()>, } However the existential lifetime causes the struct to be covariant over `'a= ` and not invariant. This becomes part of self-referential series because they're= both erased lifetimes and the implementation are remarkably similar (and shares almost all the code). > > >> +/// ## Projections and Accessors >> +/// >> +/// Since field lifetimes are not parameters of the struct, borrows of = the struct cannot carry > > s/parameters/members ? > >> +/// them. This macro therefore generates several methods for accessing = the fields: >> +/// >> +/// - `project(self: Pin<&mut Self>)` =E2=80=94 the pin projection: `#[= pin]` fields are projected as >> +///=C2=A0=C2=A0 `Pin<&mut T>`, all other fields as `&mut T`. Fields tha= t capture a field lifetime covariantly >> +///=C2=A0=C2=A0 are only projected as (possibly pinned) shared referenc= es; fields with invariant field >> +///=C2=A0=C2=A0 lifetime capture are omitted entirely. > > Means all self-referential fields are invisible? I would maybe mention > that project() should be the preferred accessor for users. Depend on what you mean by preferred? If `project()` works then yes it is t= he best. But many cases you do need to use `with_project()`/`with_project_ref(= )` or the accessor methods so there's no single recommendation possible. > >> +/// - `with_project(self: Pin<&mut Self>, f)` =E2=80=94 calls `f` with = a projection in which every >> +///=C2=A0=C2=A0 visible field has its actual field lifetime, so even in= variant captures are visible. >> +/// - `with_project_ref(self: Pin<&Self>, f)` =E2=80=94 the shared vers= ion of `with_project`. > > Thus, the user only wants these two if he needs to access self- > referential fields? If you never access self-referential fields then you just need `project()` = (or directly access the field), which is why these methods didn't exist before = the pin-init self-ref series. > > >> +/// >> +/// For all projections, shared borrow fields are only accessible with = shared references, and >> +/// mutably borrowed fields are omitted (they are only accessible throu= gh the fields that borrow >> +/// them). >> +/// >> +/// Every field (except those borrowed mutably) that captures field lif= etimes also gets an accessor >> +/// method, >>=20 > > Are you refering to my_struct.member(), or to > my_struct.with_member(|member| {=E2=80=A6 ) ? It's literally the next sentence? > >> because they cannot be directly accessed. `fn field(&self)` is generate= d if all of its >> +/// captures are covariant, otherwise `fn with_field(&self, f)` is gene= rated where `f` is called >> +/// with the field at its captured lifetimes. >> +/// >> +/// ``` >> +/// # use pin_init::*; >> +/// # #[pin_data] >> +/// # struct SelfRef { >> +/// #=C2=A0=C2=A0=C2=A0=C2=A0 part: &'msg str, >> +/// #=C2=A0=C2=A0=C2=A0=C2=A0 msg: String, >> +/// # } >> +/// # stack_pin_init!(let foo =3D pin_init!(SelfRef { >> +/// #=C2=A0=C2=A0=C2=A0=C2=A0 msg: "hello world".to_owned(), >> +/// #=C2=A0=C2=A0=C2=A0=C2=A0 part: &msg[..5], >> +/// # })); >> +/// foo.as_mut().with_project(|proj| { >> +///=C2=A0=C2=A0=C2=A0=C2=A0 *proj.part =3D &proj.msg[6..]; >> +/// }); >> +/// assert_eq!(*foo.part(), "world"); >> +/// foo.as_ref().with_project_ref(|proj| { >> +///=C2=A0=C2=A0=C2=A0=C2=A0 assert_eq!(*proj.part, "world"); >> +/// }); > > So if you need one field only you would do: > > foo.as_ref().with_part(|part| { > pr_info("{}", part); > }); Ah I didn't include an example of invariant capture in the example above. I should spell it out (and perhaps add comment in the doc code block too). Best, Gary