All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: "Benno Lossin" <lossin@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Gary Guo <gary@garyguo.net>
Subject: [PATCH 1/3] rust: pin-init: internal: init: allow reborrow of `Pin<&mut T>` bindings
Date: Mon, 28 Sep 2026 18:32:19 +0100	[thread overview]
Message-ID: <20260928-dev-pin-init-sync-v1-1-e591c8e9cf0e@garyguo.net> (raw)
In-Reply-To: <20260928-dev-pin-init-sync-v1-0-e591c8e9cf0e@garyguo.net>

Use `let mut` for created bindings of initialized field, so `Pin<&mut T>`
bindings may be reborrowed in subsequent initializers or code blocks.

Without `let mut`, attempt to reborrow can produce error (and also a
confusing fix):

    error[E0596]: cannot borrow `gpu` as mutable, as it is not declared as mutable
       --> drivers/gpu/nova-core/driver.rs:129:17
        |
    129 |                 gpu.as_mut().run_selftests(pdev);
        |                 ^^^ cannot borrow as mutable
        |
    help: consider changing this to be mutable                                                                                                                                                                                  |
    119 |             mut gpu <- Gpu::new(
        |             +++

    error: aborting due to 1 previous error

Reported-by: Danilo Krummrich <dakr@kernel.org>
Closes: https://lore.kernel.org/nova-gpu/DLQXWXRP3P1J.28SLFOJJQ2EDK@kernel.org/
Signed-off-by: Gary Guo <gary@garyguo.net>
---
 rust/pin-init/internal/src/init.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/rust/pin-init/internal/src/init.rs b/rust/pin-init/internal/src/init.rs
index c5b5a0ce5c4e..4e77c7af86f9 100644
--- a/rust/pin-init/internal/src/init.rs
+++ b/rust/pin-init/internal/src/init.rs
@@ -446,7 +446,8 @@ fn init_fields(fields: &Punctuated<InitializerField, Token![,]>, pinned: bool) -
                 // Allow `non_snake_case` since the same warning is going to be reported for the
                 // struct field.
                 #[allow(unused_variables, non_snake_case)]
-                let #ident = #guard.let_binding();
+                // Include `mut` so that `Pin<&mut T>` bindings can be reborrowed via `.as_mut()`.
+                let mut #ident = #guard.let_binding();
             },
             Member::Unnamed(_) => quote!(),
         };

-- 
2.54.0


  reply	other threads:[~2026-09-28 17:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-28 17:32 [PATCH 0/3] rust: pin-init: upstream synchronization for 7.4 Gary Guo
2026-09-28 17:32 ` Gary Guo [this message]
2026-09-29 19:17   ` [PATCH 1/3] rust: pin-init: internal: init: allow reborrow of `Pin<&mut T>` bindings Danilo Krummrich
2026-09-30  0:33   ` Alexandre Courbot
2026-09-28 17:32 ` [PATCH 2/3] rust: pin-init: internal: init: improve diagnostics from field checks Gary Guo
2026-09-28 17:32 ` [PATCH 3/3] rust: pin-init: internal: init: use span of `<-` or `:` for the init/write call Gary Guo
2026-09-30 15:38 ` [PATCH 0/3] rust: pin-init: upstream synchronization for 7.4 Gary Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260928-dev-pin-init-sync-v1-1-e591c8e9cf0e@garyguo.net \
    --to=gary@garyguo.net \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.