Skip to contentSkip to conversation

rust_binder: clean Clippy `mem-replace-with-default` warning

PATCH In review Miguel Ojeda 3 participants 3 messages Oct 12, 2025 – Oct 19, 2025

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust_binder: clean Clippy `mem-replace-with-default` warning

Starting with Rust 1.87.0, Clippy reports:

      CLIPPY     drivers/android/binder/rust_binder_main.o
    error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take`
       --> drivers/android/binder/node.rs:690:32
        |
    690 |             _unused_capacity = mem::replace(&mut inner.freeze_list, KVVec::new());
        |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut inner.freeze_list)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
        = note: `-D clippy::mem-replace-with-default` implied by `-D warnings`
        = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]`

Thus clean it up as suggested.

Fixes eafedbc7c050 ("rust_binder: add Rust Binder driver")
---
 drivers/android/binder/node.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/android/binder/node.rs +1 -1
index ade895ef791e..08d362deaf61 100644
@@ -687,7 +687,7 @@ pub(crate) fn remove_freeze_listener(&self, p: &Arc<Process>) {
             );
         }
         if inner.freeze_list.is_empty() {
-            _unused_capacity = mem::replace(&mut inner.freeze_list, KVVec::new());
+            _unused_capacity = mem::take(&mut inner.freeze_list);
         }
     }
 

base-commit: 8765f467912ff0d4832eeaf26ae573792da877e7

Signature · 1 line
2.51.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Miguel Ojeda

Starting with Rust 1.87.0, Clippy reports:

      CLIPPY     drivers/android/binder/rust_binder_main.o
    error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take`
       --> drivers/android/binder/node.rs:690:32
        |
    690 |             _unused_capacity = mem::replace(&mut inner.freeze_list, KVVec::new());
        |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut inner.freeze_list)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
        = note: `-D clippy::mem-replace-with-default` implied by `-D warnings`
        = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]`
Quoted 4 lines

Thus clean it up as suggested.

Fixes eafedbc7c050 ("rust_binder: add Rust Binder driver")

Thanks. I guess I never got around to making use of commit 47d8101924b5 ("rust: vec: impl Default for Vec with any allocator").

#2 lore raw
In reply to Miguel Ojeda
Quoted 14 lines · Miguel Ojeda

Starting with Rust 1.87.0, Clippy reports:

      CLIPPY     drivers/android/binder/rust_binder_main.o
    error: replacing a value of type `T` with `T::default()` is better expressed using `core::mem::take`
       --> drivers/android/binder/node.rs:690:32
        |
    690 |             _unused_capacity = mem::replace(&mut inner.freeze_list, KVVec::new());
        |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `core::mem::take(&mut inner.freeze_list)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
        = note: `-D clippy::mem-replace-with-default` implied by `-D warnings`
        = help: to override `-D warnings` add `#[allow(clippy::mem_replace_with_default)]`
Quoted 4 lines

Thus clean it up as suggested.

Fixes eafedbc7c050 ("rust_binder: add Rust Binder driver")

For completeness: this is a duplicate (from myself!) of

    https://lore.kernel.org/all/[email protected]/

which Greg already applied as commit 7e69a24b6b35 ("rust_binder: clean clippy::mem_replace_with_default warning"), in -next for a few days.

It would be nice to get it to Linus soon, so that Clippy builds are clean.

Thanks!

Cheers,
Miguel