rust: kernel: remove redundant imports
authorMiguel Ojeda <ojeda@kernel.org>
Mon, 1 Apr 2024 21:23:02 +0000 (23:23 +0200)
committerMiguel Ojeda <ojeda@kernel.org>
Sun, 5 May 2024 17:22:25 +0000 (19:22 +0200)
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
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>
15 files changed:
rust/kernel/alloc.rs
rust/kernel/alloc/allocator.rs
rust/kernel/alloc/box_ext.rs
rust/kernel/alloc/vec_ext.rs
rust/kernel/error.rs
rust/kernel/net/phy.rs
rust/kernel/print.rs
rust/kernel/str.rs
rust/kernel/sync/arc.rs
rust/kernel/sync/condvar.rs
rust/kernel/sync/lock.rs
rust/kernel/sync/lock/mutex.rs
rust/kernel/sync/lock/spinlock.rs
rust/kernel/task.rs
rust/kernel/workqueue.rs

index f1c2c4aa22d2e74f0a6191526e94937a649e7522..531b5e471cb1404e16c5139fb4b2854619f982fb 100644 (file)
@@ -46,7 +46,6 @@ impl core::ops::Not for Flags {
 /// These are meant to be used in functions that can allocate memory.
 pub mod flags {
     use super::Flags;
-    use crate::bindings;
 
     /// Zeroes out the allocated memory.
     ///
index ff88bce04fd47dca529e125de961baa55ce65942..229642960cd162dcf9df1f75c4f3b35e77e545d0 100644 (file)
@@ -6,8 +6,6 @@ use super::{flags::*, Flags};
 use core::alloc::{GlobalAlloc, Layout};
 use core::ptr;
 
-use crate::bindings;
-
 struct KernelAllocator;
 
 /// Calls `krealloc` with a proper size to alloc a new object aligned to `new_layout`'s alignment.
index cdbb5ad166d9651dd9345053b6c04d9a367a0c18..829cb1c1cf9e69a516d6c74d0bdacdefb249e94e 100644 (file)
@@ -5,7 +5,6 @@
 use super::{AllocError, Flags};
 use alloc::boxed::Box;
 use core::mem::MaybeUninit;
-use core::result::Result;
 
 /// Extensions to [`Box`].
 pub trait BoxExt<T>: Sized {
index 6a916fcf8bf123618a700a74c444cf875d8c98ff..25025a36e250897e743131589cc8a6b416b622bc 100644 (file)
@@ -4,7 +4,6 @@
 
 use super::{AllocError, Flags};
 use alloc::vec::Vec;
-use core::result::Result;
 
 /// Extensions to [`Vec`].
 pub trait VecExt<T>: Sized {
index fc986bc24c6d68ecc5195b295573cd445bf9e8c8..55280ae9fe40e1532f23a35b5cfac2da2d6030b0 100644 (file)
@@ -8,7 +8,6 @@ use crate::{alloc::AllocError, str::CStr};
 
 use alloc::alloc::LayoutError;
 
-use core::convert::From;
 use core::fmt;
 use core::num::TryFromIntError;
 use core::str::Utf8Error;
index 96e09c6e8530b4d108e6a664e93ab41436c797dc..fba19165aa64823041c05ac215d3e3fb7af5d35b 100644 (file)
@@ -6,7 +6,7 @@
 //!
 //! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h).
 
-use crate::{bindings, error::*, prelude::*, str::CStr, types::Opaque};
+use crate::{error::*, prelude::*, types::Opaque};
 
 use core::marker::PhantomData;
 
index 9b13aca832c2df491858dc9952a6e4da3ce782a9..a78aa3514a0af0925913a9dbad1aec1c279db791 100644 (file)
@@ -13,9 +13,6 @@ use core::{
 
 use crate::str::RawFormatter;
 
-#[cfg(CONFIG_PRINTK)]
-use crate::bindings;
-
 // Called from `vsprintf` with format specifier `%pA`.
 #[no_mangle]
 unsafe extern "C" fn rust_fmt_argument(
@@ -35,8 +32,6 @@ unsafe extern "C" fn rust_fmt_argument(
 /// Public but hidden since it should only be used from public macros.
 #[doc(hidden)]
 pub mod format_strings {
-    use crate::bindings;
-
     /// The length we copy from the `KERN_*` kernel prefixes.
     const LENGTH_PREFIX: usize = 2;
 
index 27641c3e4df8001db6275aec1bbca471d5e435ff..bb8d4f41475b59627642d6a1b3834fb6ef3b9755 100644 (file)
@@ -7,10 +7,7 @@ use alloc::vec::Vec;
 use core::fmt::{self, Write};
 use core::ops::{self, Deref, DerefMut, Index};
 
-use crate::{
-    bindings,
-    error::{code::*, Error},
-};
+use crate::error::{code::*, Error};
 
 /// Byte string without UTF-8 validity guarantee.
 #[repr(transparent)]
index a65716ec24a6a6696a81d7132f8501fa4f5f0849..3673496c2363008e580ad0a33cdf30e2ff870aa0 100644 (file)
@@ -17,7 +17,6 @@
 
 use crate::{
     alloc::{box_ext::BoxExt, AllocError, Flags},
-    bindings,
     error::{self, Error},
     init::{self, InPlaceInit, Init, PinInit},
     try_init,
index ef6ffef0aa888bd2f3cb36d5a66ef37095683d92..2b306afbe56d9666136c6d69e7ba530977f6eacf 100644 (file)
@@ -7,7 +7,6 @@
 
 use super::{lock::Backend, lock::Guard, LockClassKey};
 use crate::{
-    bindings,
     init::PinInit,
     pin_init,
     str::CStr,
index 5b5c8efe427ae2fc215a9ac312282cc133fb07e2..f6c34ca4d819f81c9259515562d5ae8a0c4ffc57 100644 (file)
@@ -6,7 +6,7 @@
 //! spinlocks, raw spinlocks) to be provided with minimal effort.
 
 use super::LockClassKey;
-use crate::{bindings, init::PinInit, pin_init, str::CStr, types::Opaque, types::ScopeGuard};
+use crate::{init::PinInit, pin_init, str::CStr, types::Opaque, types::ScopeGuard};
 use core::{cell::UnsafeCell, marker::PhantomData, marker::PhantomPinned};
 use macros::pin_data;
 
index 93e1c982facfb1dfd6427c6621fc242aebaa4bd8..30632070ee670917ecfbd9b89d3a663a0cbe9374 100644 (file)
@@ -4,8 +4,6 @@
 //!
 //! This module allows Rust code to use the kernel's `struct mutex`.
 
-use crate::bindings;
-
 /// Creates a [`Mutex`] initialiser with the given name and a newly-created lock class.
 ///
 /// It uses the name if one is given, otherwise it generates one based on the file name and line
index 6e900807d3b7a271c85c3d58ffd760a25cf564fc..ea5c5bc1ce12ed704f01db985d8324e7bf23dae6 100644 (file)
@@ -4,8 +4,6 @@
 //!
 //! This module allows Rust code to use the kernel's `spinlock_t`.
 
-use crate::bindings;
-
 /// Creates a [`SpinLock`] initialiser with the given name and a newly-created lock class.
 ///
 /// It uses the name if one is given, otherwise it generates one based on the file name and line
index ca6e7e31d71c9d003ff80c7d2f2814ce47d176c6..55dff7e088bf5fc96cc45246cfcccbcbb663b3e2 100644 (file)
@@ -4,7 +4,7 @@
 //!
 //! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h).
 
-use crate::{bindings, types::Opaque};
+use crate::types::Opaque;
 use core::{
     ffi::{c_int, c_long, c_uint},
     marker::PhantomData,
index 22813b76861d0f00448d3fc7f8c87bb3cc9b8afe..1cec63a2aea8b0529216b723d9deeaece05a3830 100644 (file)
 //! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
 
 use crate::alloc::{AllocError, Flags};
-use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
-use alloc::boxed::Box;
+use crate::{prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
 use core::marker::PhantomData;
-use core::pin::Pin;
 
 /// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
 #[macro_export]