Skip to contentSkip to conversation

rust: avoid unused import warning in `rusttest`

PATCH Applied Miguel Ojeda 4 participants 4 messages May 19, 2024 – Jun 11, 2024

Subsystems (2)
lore
Share & tools
lore

Miguel Ojeda

author maintainer
#0 lore raw

PATCH 1/1 rust: avoid unused import warning in `rusttest`

When compiling for the rusttest target, the core::ptr import is unused since its only use happens in the reserve() method which is not compiled in that target:

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

Thus clean it.

Fixes 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
---
 rust/kernel/alloc/vec_ext.rs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
rust/kernel/alloc/vec_ext.rs +5 -2
index e9a81052728a..1297a4be32e8 100644
@@ -4,7 +4,6 @@
 
 use super::{AllocError, Flags};
 use alloc::vec::Vec;
-use core::ptr;
 
 /// Extensions to [`Vec`].
 pub trait VecExt<T>: Sized {
@@ -141,7 +140,11 @@ fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>
         // `krealloc_aligned`. A `Vec<T>`'s `ptr` value is not guaranteed to be NULL and might be
         // dangling after being created with `Vec::new`. Instead, we can rely on `Vec<T>`'s capacity
         // to be zero if no memory has been allocated yet.
-        let ptr = if cap == 0 { ptr::null_mut() } else { old_ptr };
+        let ptr = if cap == 0 {
+            core::ptr::null_mut()
+        } else {
+            old_ptr
+        };
 
         // SAFETY: `ptr` is valid because it's either NULL or comes from a previous call to
         // `krealloc_aligned`. We also verified that the type is not a ZST.

base-commit: 97ab3e8eec0ce79d9e265e6c9e4c480492180409

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

When compiling for the rusttest target, the core::ptr import is unused since its only use happens in the reserve() method which is not compiled in that target:

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

Thus clean it.

Fixes 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Miguel Ojeda
Quoted 12 lines · Miguel Ojeda

When compiling for the rusttest target, the core::ptr import is unused since its only use happens in the reserve() method which is not compiled in that target:

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

Thus clean it.

Fixes 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
Quoted 34 lines
---
 rust/kernel/alloc/vec_ext.rs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
rust/kernel/alloc/vec_ext.rs +5 -2
index e9a81052728a..1297a4be32e8 100644
@@ -4,7 +4,6 @@
 
 use super::{AllocError, Flags};
 use alloc::vec::Vec;
-use core::ptr;
 
 /// Extensions to [`Vec`].
 pub trait VecExt<T>: Sized {
@@ -141,7 +140,11 @@ fn reserve(&mut self, additional: usize, flags: Flags) -> Result<(), AllocError>
         // `krealloc_aligned`. A `Vec<T>`'s `ptr` value is not guaranteed to be NULL and might be
         // dangling after being created with `Vec::new`. Instead, we can rely on `Vec<T>`'s capacity
         // to be zero if no memory has been allocated yet.
-        let ptr = if cap == 0 { ptr::null_mut() } else { old_ptr };
+        let ptr = if cap == 0 {
+            core::ptr::null_mut()
+        } else {
+            old_ptr
+        };
 
         // SAFETY: `ptr` is valid because it's either NULL or comes from a previous call to
         // `krealloc_aligned`. We also verified that the type is not a ZST.

base-commit: 97ab3e8eec0ce79d9e265e6c9e4c480492180409

Signature · 1 line
2.45.1
Applied
#3 lore raw
In reply to Miguel Ojeda
Quoted 13 lines · Miguel Ojeda

When compiling for the rusttest target, the core::ptr import is unused since its only use happens in the reserve() method which is not compiled in that target:

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

Thus clean it.

Fixes 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")

Applied to rust-fixes -- thanks everyone!

Cheers,
Miguel