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>
This commit is contained in:
@@ -46,7 +46,6 @@ impl core::ops::Not for Flags {
|
|||||||
/// These are meant to be used in functions that can allocate memory.
|
/// These are meant to be used in functions that can allocate memory.
|
||||||
pub mod flags {
|
pub mod flags {
|
||||||
use super::Flags;
|
use super::Flags;
|
||||||
use crate::bindings;
|
|
||||||
|
|
||||||
/// Zeroes out the allocated memory.
|
/// Zeroes out the allocated memory.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ use super::{flags::*, Flags};
|
|||||||
use core::alloc::{GlobalAlloc, Layout};
|
use core::alloc::{GlobalAlloc, Layout};
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
|
||||||
use crate::bindings;
|
|
||||||
|
|
||||||
struct KernelAllocator;
|
struct KernelAllocator;
|
||||||
|
|
||||||
/// Calls `krealloc` with a proper size to alloc a new object aligned to `new_layout`'s alignment.
|
/// Calls `krealloc` with a proper size to alloc a new object aligned to `new_layout`'s alignment.
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
use super::{AllocError, Flags};
|
use super::{AllocError, Flags};
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
use core::result::Result;
|
|
||||||
|
|
||||||
/// Extensions to [`Box`].
|
/// Extensions to [`Box`].
|
||||||
pub trait BoxExt<T>: Sized {
|
pub trait BoxExt<T>: Sized {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use super::{AllocError, Flags};
|
use super::{AllocError, Flags};
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
use core::result::Result;
|
|
||||||
|
|
||||||
/// Extensions to [`Vec`].
|
/// Extensions to [`Vec`].
|
||||||
pub trait VecExt<T>: Sized {
|
pub trait VecExt<T>: Sized {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use crate::{alloc::AllocError, str::CStr};
|
|||||||
|
|
||||||
use alloc::alloc::LayoutError;
|
use alloc::alloc::LayoutError;
|
||||||
|
|
||||||
use core::convert::From;
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::num::TryFromIntError;
|
use core::num::TryFromIntError;
|
||||||
use core::str::Utf8Error;
|
use core::str::Utf8Error;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
//!
|
//!
|
||||||
//! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h).
|
//! 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;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,6 @@ use core::{
|
|||||||
|
|
||||||
use crate::str::RawFormatter;
|
use crate::str::RawFormatter;
|
||||||
|
|
||||||
#[cfg(CONFIG_PRINTK)]
|
|
||||||
use crate::bindings;
|
|
||||||
|
|
||||||
// Called from `vsprintf` with format specifier `%pA`.
|
// Called from `vsprintf` with format specifier `%pA`.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
unsafe extern "C" fn rust_fmt_argument(
|
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.
|
/// Public but hidden since it should only be used from public macros.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod format_strings {
|
pub mod format_strings {
|
||||||
use crate::bindings;
|
|
||||||
|
|
||||||
/// The length we copy from the `KERN_*` kernel prefixes.
|
/// The length we copy from the `KERN_*` kernel prefixes.
|
||||||
const LENGTH_PREFIX: usize = 2;
|
const LENGTH_PREFIX: usize = 2;
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -7,10 +7,7 @@ use alloc::vec::Vec;
|
|||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
use core::ops::{self, Deref, DerefMut, Index};
|
use core::ops::{self, Deref, DerefMut, Index};
|
||||||
|
|
||||||
use crate::{
|
use crate::error::{code::*, Error};
|
||||||
bindings,
|
|
||||||
error::{code::*, Error},
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Byte string without UTF-8 validity guarantee.
|
/// Byte string without UTF-8 validity guarantee.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
alloc::{box_ext::BoxExt, AllocError, Flags},
|
alloc::{box_ext::BoxExt, AllocError, Flags},
|
||||||
bindings,
|
|
||||||
error::{self, Error},
|
error::{self, Error},
|
||||||
init::{self, InPlaceInit, Init, PinInit},
|
init::{self, InPlaceInit, Init, PinInit},
|
||||||
try_init,
|
try_init,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
use super::{lock::Backend, lock::Guard, LockClassKey};
|
use super::{lock::Backend, lock::Guard, LockClassKey};
|
||||||
use crate::{
|
use crate::{
|
||||||
bindings,
|
|
||||||
init::PinInit,
|
init::PinInit,
|
||||||
pin_init,
|
pin_init,
|
||||||
str::CStr,
|
str::CStr,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
//! spinlocks, raw spinlocks) to be provided with minimal effort.
|
//! spinlocks, raw spinlocks) to be provided with minimal effort.
|
||||||
|
|
||||||
use super::LockClassKey;
|
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 core::{cell::UnsafeCell, marker::PhantomData, marker::PhantomPinned};
|
||||||
use macros::pin_data;
|
use macros::pin_data;
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
//!
|
//!
|
||||||
//! This module allows Rust code to use the kernel's `struct mutex`.
|
//! 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.
|
/// 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
|
/// It uses the name if one is given, otherwise it generates one based on the file name and line
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
//!
|
//!
|
||||||
//! This module allows Rust code to use the kernel's `spinlock_t`.
|
//! 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.
|
/// 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
|
/// It uses the name if one is given, otherwise it generates one based on the file name and line
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
//!
|
//!
|
||||||
//! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h).
|
//! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h).
|
||||||
|
|
||||||
use crate::{bindings, types::Opaque};
|
use crate::types::Opaque;
|
||||||
use core::{
|
use core::{
|
||||||
ffi::{c_int, c_long, c_uint},
|
ffi::{c_int, c_long, c_uint},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
|
|||||||
@@ -131,10 +131,8 @@
|
|||||||
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
|
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
|
||||||
|
|
||||||
use crate::alloc::{AllocError, Flags};
|
use crate::alloc::{AllocError, Flags};
|
||||||
use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
|
use crate::{prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
|
||||||
use alloc::boxed::Box;
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use core::pin::Pin;
|
|
||||||
|
|
||||||
/// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
|
/// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|||||||
Reference in New Issue
Block a user