From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38AFB19CC28; Sun, 7 Sep 2025 01:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757210229; cv=none; b=IP1TNBocPxSzKKkozKJYjjIfjmLStjRyMYdLMecjPShxj7yEUEJSHFlgDKB96CgkZsrFrufDhqwtAMRp4Wr7s9YbUzqwtIcsRHqgTrDSBhQMiWatTSXyx8zXCZrTFfsjenUBxjsyBv9s54V3K3rNO5C+uEymb5QuhPC2bggWqMU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757210229; c=relaxed/simple; bh=HIANAWEJTSk4h6jVR+naSmXE055aF+gsPiBbfQucI+g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FFNEOMpQJGW4zEhHTQUVvce6NUmW4gWzG38sJ6sWH1KrgAudOYBQFY9GRTcQ5e+t6QlK1CkdHD9wIaTxVKknLQ9l9TzhXMZdZcmfXfxB58nj1lPzBkbfqqpzOSvTCt/dOaJTjqGHlY1at+QsnoMIj0D1sI3h1K0fEg9do2p4vck= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aNfE7ZGW; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aNfE7ZGW" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-81076e81a23so322438585a.3; Sat, 06 Sep 2025 18:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757210227; x=1757815027; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=6Ubqm0cemNSwa00R4M8gX2Nj2LvSr0FhtjEjZFitZIs=; b=aNfE7ZGWsaaksQ7bUqg0YDez2CfbNcqTCLqk92iUgub95tew6vqqMOwJA59iufrmf+ skl34d0H8bW7Qnfs1tgwqu5u8aBWYjFV0J7IMS4+5IRBQb4usT3LIlKyS3bjU1gbSD7o kDVRvRBMXJpkPXJDLa+k4lcWssd2hjtYHLj0zOoWhGcfRtcOW3nx9Z77nljrJPczHqAH Qoax6PU9VUI2cWaDT9eLNQ1r0oCNwB0s5WQGhIMPbZyG4GWYzX5qZeurqeL7O3VHoTWw 29XKIEssKj6a4BeW0kVwHcjW14ZebayzrLJh9ldFfTm2MQeZWrxk35wuvKjl7DGEZe+Y rrdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757210227; x=1757815027; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6Ubqm0cemNSwa00R4M8gX2Nj2LvSr0FhtjEjZFitZIs=; b=Uvh7/i2RTtfwarDtOwCABl5+tsMwBGf3MQa2irXkVmOLEYAfdgiJN9Bhp0yl/4DigZ UK7icG80wvi/+bAIuTUyLQ3zpP4WqZ36r1ORm7tkYTY/mC4BT+z5EM47DgecymYq7f1y AndfV+dXEVQRpFHWos6i02ymGV1KZDbK4XYNguJvP3dsjcATIegF9gF/ho3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Zp60cXzhq31btTZ8hzpeQ== X-Received: by 2002:a05:620a:ab04:b0:813:de67:afff with SMTP id af79cd13be357-813de67b39cmr299305885a.46.1757210227039; Sat, 06 Sep 2025 18:57:07 -0700 (PDT) Received: from fauth-a2-smtp.messagingengine.com (fauth-a2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-4b48f501690sm74875171cf.0.2025.09.06.18.57.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Sep 2025 18:57:06 -0700 (PDT) Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfauth.phl.internal (Postfix) with ESMTP id C37BFF40066; Sat, 6 Sep 2025 21:57:05 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Sat, 06 Sep 2025 21:57:05 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddufeefkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhnucfh vghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrthhtvg hrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveeiudffiedv necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqh hunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieegqddu jeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvg drnhgrmhgvpdhnsggprhgtphhtthhopedukedpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtohepuggrkhhrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlohhsshhinheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohepohhjvggurgeskhgvrhhnvghlrdhorhhgpdhr tghpthhtoheprghlvgigrdhgrgihnhhorhesghhmrghilhdrtghomhdprhgtphhtthhope hgrghrhiesghgrrhihghhuohdrnhgvthdprhgtphhtthhopegsjhhorhhnfegpghhhsehp rhhothhonhhmrghilhdrtghomhdprhgtphhtthhopegrrdhhihhnuggsohhrgheskhgvrh hnvghlrdhorhhgpdhrtghpthhtoheprghlihgtvghrhihhlhesghhoohhglhgvrdgtohhm pdhrtghpthhtohepthhmghhrohhsshesuhhmihgthhdrvgguuh X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 Sep 2025 21:57:05 -0400 (EDT) Date: Sat, 6 Sep 2025 18:57:04 -0700 From: Boqun Feng To: Danilo Krummrich Cc: Benno Lossin , Miguel Ojeda , Alex Gaynor , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Trevor Gross , Fiona Behrens , Alban Kurti , Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Krzysztof =?iso-8859-1?Q?Wilczy=B4nski?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rust: pin-init: add references to previously initialized fields Message-ID: References: <20250905140047.3325945-1-lossin@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sat, Sep 06, 2025 at 12:52:22PM +0200, Danilo Krummrich wrote: > On Fri Sep 5, 2025 at 7:44 PM CEST, Boqun Feng wrote: > > On Fri, Sep 05, 2025 at 07:18:25PM +0200, Benno Lossin wrote: > > [...] > >> index 606946ff4d7f..1ac0b06fa3b3 100644 > >> --- a/samples/rust/rust_driver_pci.rs > >> +++ b/samples/rust/rust_driver_pci.rs > >> @@ -78,8 +78,8 @@ fn probe(pdev: &pci::Device, info: &Self::IdInfo) -> Result > >> > >> let drvdata = KBox::pin_init( > >> try_pin_init!(Self { > >> - pdev: pdev.into(), > >> bar <- pdev.iomap_region_sized::<{ Regs::END }>(0, c_str!("rust_driver_pci")), > >> + pdev: pdev.into(), > > > > Ok, this example is good enough for me to express the concern here: the > > variable shadowing behavior seems not straightforward (maybe because in > > normal Rust initalization expression, no binding is created for > > previous variables, neither do we have a `let` here). > > > > Would the future inplace initialization have the similar behavior? I > > asked because a natural resolution is adding a special syntax like: > > > > let a = ..; > > > > try_pin_init!(Self { > > b: a, > > let a = a.into(); // create the new binding here. > > c: a, // <- use the previous initalized `a`. > > } > > Can you please clarify the example? I'm a bit confused that this is not a field > of Self, so currently this can just be written as: > Oh, I could have been more clear: `a` is a field of `Self`, and the `let` part initalizes it. > try_pin_init!(Self { > b: a, > c: a.into, > }) > > Of course assuming that a is Clone, as the code above does as well. > > So, if we are concerned by the variable shadowing, which I'm less concerned > about, maybe we can do this: I'm not that concerned to block this, but it does look to me like we are inventing a new way (and even a different syntax because normal Rust initialization doesn't create new bindings) to create binding, so I think I should bring it up. > > // The "original" `a` and `b`. > let a: A = ...; > let b: B = ...; > > try_pin_init!(Self { > a, // Initialize the field only. > let b <- b, // Initialize the field and create a `&B` named `b`. > c: a.into(), // That's the "original" `a`. > d <- D::new(b), // Not the original `b`, but the pin-init one. > }) This looks good to me as well. But I'm curious what the syntax would be like in the in-place placement language feature in the future. Regards, Boqun