Skip to contentSkip to conversation

rust: alloc: Fix unused import warning

PATCH In review Ethan D. Twardy 2 participants 2 messages Jun 20, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: alloc: Fix unused import warning

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

rust/kernel/alloc/vec_ext.rs +2 -0
index e9a81052728a..96d7cbff96dd 100644
@@ -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

Signature · 1 line
2.44.2
#1 lore raw
Quoted 5 lines · Ethan D. Twardy

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/[email protected]

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

Thanks!

Cheers,
Miguel