From 158e85db3375c4b0b66223dee7aae16f2357aada Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 28 Sep 2026 18:32:19 +0100 Subject: [PATCH] rust: pin-init: internal: init: allow reborrow of `Pin<&mut T>` bindings 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 Closes: https://lore.kernel.org/nova-gpu/DLQXWXRP3P1J.28SLFOJJQ2EDK@kernel.org/ Reviewed-by: Alexandre Courbot Tested-by: Danilo Krummrich Reviewed-by: Danilo Krummrich Link: https://patch.msgid.link/20260928-dev-pin-init-sync-v1-1-e591c8e9cf0e@garyguo.net Signed-off-by: Gary Guo --- 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, 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!(), };