Skip to content

internal: init: allow reborrow of Pin<&mut T> bindings - #180

Merged
nbdd0121 merged 1 commit into
mainfrom
dev/mut
Sep 30, 2026
Merged

nbdd0121 merged 1 commit into
mainfrom
dev/mut

Conversation

@nbdd0121

Copy link
Copy Markdown
Member

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

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>
Signed-off-by: Gary Guo <gary@garyguo.net>
Tested-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Alexandre Courbot <acourbot@nvidia.com>
@nbdd0121
nbdd0121 merged commit 3db80cc into main Sep 30, 2026
55 checks passed
@nbdd0121
nbdd0121 deleted the dev/mut branch October 12, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant