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 <dakr@kernel.org>
Closes: https://lore.kernel.org/nova-gpu/DLQXWXRP3P1J.28SLFOJJQ2EDK@kernel.org/
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
Tested-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Link: https://patch.msgid.link/20260928-dev-pin-init-sync-v1-1-e591c8e9cf0e@garyguo.net
Signed-off-by: Gary Guo <gary@garyguo.net>
This commit is contained in:
Gary Guo 2026-09-28 18:32:19 +01:00
parent 95593ed361
commit 158e85db33

View File

@ -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!(),
};