[PATCH] rust: alloc: Fix unused import warning

Ethan D. Twardy posted 1 patch 1 year, 6 months ago
|
[PATCH] rust: alloc: Fix unused import warning
Posted by Ethan D. Twardy 1 year, 6 months ago
core::ptr is only used in code that's not compiled during test, which
causes rustc to emit the below warning while building the rusttest
target. Add a conditional attribute to match conditions at the usage
site.

warning: unused import: `core::ptr`
 --> rust/kernel/alloc/vec_ext.rs:7:5
  |
7 | use core::ptr;
  |     ^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Signed-off-by: Ethan D. Twardy <ethan.twardy@gmail.com>

diff --git a/rust/kernel/alloc/vec_ext.rs b/rust/kernel/alloc/vec_ext.rs
index e9a81052728a..96d7cbff96dd 100644
--- a/rust/kernel/alloc/vec_ext.rs
+++ b/rust/kernel/alloc/vec_ext.rs
@@ -4,6 +4,8 @@
 
 use super::{AllocError, Flags};
 use alloc::vec::Vec;
+
+#[cfg(not(any(test, testlib)))]
 use core::ptr;
 
 /// Extensions to [`Vec`].

base-commit: 39e6bf7394d852b17fb083a85fee5890b445908c
-- 
2.44.2
Re: [PATCH] rust: alloc: Fix unused import warning
Posted by Miguel Ojeda 1 year, 5 months ago
On Thu, Jun 20, 2024 at 4:11 AM Ethan D. Twardy <ethan.twardy@gmail.com> wrote:
>
> core::ptr is only used in code that's not compiled during test, which
> causes rustc to emit the below warning while building the rusttest
> target. Add a conditional attribute to match conditions at the usage
> site.

We have an alternative fix (that avoids conditional compilation) for
this one in the `rust-fixes` branch that I am planning to send to
Linus this week.

    https://lore.kernel.org/r/20240519210735.587323-1-ojeda@kernel.org

If that one does not fix the issue for you, please let me know!

Thanks!

Cheers,
Miguel