Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rust: kernel: remove redundant imports

Rust's `unused_imports` lint covers both unused and redundant imports.
In the upcoming 1.78.0, the lint detects more cases of redundant imports
[1], e.g.:

error: the item `bindings` is imported redundantly
--> rust/kernel/print.rs:38:9
|
38 | use crate::bindings;
| ^^^^^^^^^^^^^^^ the item `bindings` is already defined by prelude

Most cases are `use crate::bindings`, plus a few other items like `Box`.
Thus clean them up.

Note that, in the `bindings` case, the message "defined by prelude"
above means the extern prelude, i.e. the `--extern` flags we pass.

Link: https://github.com/rust-lang/rust/pull/117772 [1]
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240401212303.537355-3-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

+5 -27
-1
rust/kernel/alloc.rs
··· 46 46 /// These are meant to be used in functions that can allocate memory. 47 47 pub mod flags { 48 48 use super::Flags; 49 - use crate::bindings; 50 49 51 50 /// Zeroes out the allocated memory. 52 51 ///
-2
rust/kernel/alloc/allocator.rs
··· 6 6 use core::alloc::{GlobalAlloc, Layout}; 7 7 use core::ptr; 8 8 9 - use crate::bindings; 10 - 11 9 struct KernelAllocator; 12 10 13 11 /// Calls `krealloc` with a proper size to alloc a new object aligned to `new_layout`'s alignment.
-1
rust/kernel/alloc/box_ext.rs
··· 5 5 use super::{AllocError, Flags}; 6 6 use alloc::boxed::Box; 7 7 use core::mem::MaybeUninit; 8 - use core::result::Result; 9 8 10 9 /// Extensions to [`Box`]. 11 10 pub trait BoxExt<T>: Sized {
-1
rust/kernel/alloc/vec_ext.rs
··· 4 4 5 5 use super::{AllocError, Flags}; 6 6 use alloc::vec::Vec; 7 - use core::result::Result; 8 7 9 8 /// Extensions to [`Vec`]. 10 9 pub trait VecExt<T>: Sized {
-1
rust/kernel/error.rs
··· 8 8 9 9 use alloc::alloc::LayoutError; 10 10 11 - use core::convert::From; 12 11 use core::fmt; 13 12 use core::num::TryFromIntError; 14 13 use core::str::Utf8Error;
+1 -1
rust/kernel/net/phy.rs
··· 6 6 //! 7 7 //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h). 8 8 9 - use crate::{bindings, error::*, prelude::*, str::CStr, types::Opaque}; 9 + use crate::{error::*, prelude::*, types::Opaque}; 10 10 11 11 use core::marker::PhantomData; 12 12
-5
rust/kernel/print.rs
··· 13 13 14 14 use crate::str::RawFormatter; 15 15 16 - #[cfg(CONFIG_PRINTK)] 17 - use crate::bindings; 18 - 19 16 // Called from `vsprintf` with format specifier `%pA`. 20 17 #[no_mangle] 21 18 unsafe extern "C" fn rust_fmt_argument( ··· 32 35 /// Public but hidden since it should only be used from public macros. 33 36 #[doc(hidden)] 34 37 pub mod format_strings { 35 - use crate::bindings; 36 - 37 38 /// The length we copy from the `KERN_*` kernel prefixes. 38 39 const LENGTH_PREFIX: usize = 2; 39 40
+1 -4
rust/kernel/str.rs
··· 7 7 use core::fmt::{self, Write}; 8 8 use core::ops::{self, Deref, DerefMut, Index}; 9 9 10 - use crate::{ 11 - bindings, 12 - error::{code::*, Error}, 13 - }; 10 + use crate::error::{code::*, Error}; 14 11 15 12 /// Byte string without UTF-8 validity guarantee. 16 13 #[repr(transparent)]
-1
rust/kernel/sync/arc.rs
··· 17 17 18 18 use crate::{ 19 19 alloc::{box_ext::BoxExt, AllocError, Flags}, 20 - bindings, 21 20 error::{self, Error}, 22 21 init::{self, InPlaceInit, Init, PinInit}, 23 22 try_init,
-1
rust/kernel/sync/condvar.rs
··· 7 7 8 8 use super::{lock::Backend, lock::Guard, LockClassKey}; 9 9 use crate::{ 10 - bindings, 11 10 init::PinInit, 12 11 pin_init, 13 12 str::CStr,
+1 -1
rust/kernel/sync/lock.rs
··· 6 6 //! spinlocks, raw spinlocks) to be provided with minimal effort. 7 7 8 8 use super::LockClassKey; 9 - use crate::{bindings, init::PinInit, pin_init, str::CStr, types::Opaque, types::ScopeGuard}; 9 + use crate::{init::PinInit, pin_init, str::CStr, types::Opaque, types::ScopeGuard}; 10 10 use core::{cell::UnsafeCell, marker::PhantomData, marker::PhantomPinned}; 11 11 use macros::pin_data; 12 12
-2
rust/kernel/sync/lock/mutex.rs
··· 4 4 //! 5 5 //! This module allows Rust code to use the kernel's `struct mutex`. 6 6 7 - use crate::bindings; 8 - 9 7 /// Creates a [`Mutex`] initialiser with the given name and a newly-created lock class. 10 8 /// 11 9 /// It uses the name if one is given, otherwise it generates one based on the file name and line
-2
rust/kernel/sync/lock/spinlock.rs
··· 4 4 //! 5 5 //! This module allows Rust code to use the kernel's `spinlock_t`. 6 6 7 - use crate::bindings; 8 - 9 7 /// Creates a [`SpinLock`] initialiser with the given name and a newly-created lock class. 10 8 /// 11 9 /// It uses the name if one is given, otherwise it generates one based on the file name and line
+1 -1
rust/kernel/task.rs
··· 4 4 //! 5 5 //! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h). 6 6 7 - use crate::{bindings, types::Opaque}; 7 + use crate::types::Opaque; 8 8 use core::{ 9 9 ffi::{c_int, c_long, c_uint}, 10 10 marker::PhantomData,
+1 -3
rust/kernel/workqueue.rs
··· 131 131 //! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h) 132 132 133 133 use crate::alloc::{AllocError, Flags}; 134 - use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque}; 135 - use alloc::boxed::Box; 134 + use crate::{prelude::*, sync::Arc, sync::LockClassKey, types::Opaque}; 136 135 use core::marker::PhantomData; 137 - use core::pin::Pin; 138 136 139 137 /// Creates a [`Work`] initialiser with the given name and a newly-created lock class. 140 138 #[macro_export]