Skip to content

Commit 44b0e27

Browse files
committed
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: rust-lang/rust#117772 [1] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent c11d24c commit 44b0e27

15 files changed

+5
-27
lines changed

rust/kernel/alloc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ impl core::ops::Not for Flags {
4646
/// These are meant to be used in functions that can allocate memory.
4747
pub mod flags {
4848
use super::Flags;
49-
use crate::bindings;
5049

5150
/// Zeroes out the allocated memory.
5251
///

rust/kernel/alloc/allocator.rs

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use super::{flags::*, Flags};
66
use core::alloc::{GlobalAlloc, Layout};
77
use core::ptr;
88

9-
use crate::bindings;
10-
119
struct KernelAllocator;
1210

1311
/// Calls `krealloc` with a proper size to alloc a new object aligned to `new_layout`'s alignment.

rust/kernel/alloc/box_ext.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use super::{AllocError, Flags};
66
use alloc::boxed::Box;
77
use core::mem::MaybeUninit;
8-
use core::result::Result;
98

109
/// Extensions to [`Box`].
1110
pub trait BoxExt<T>: Sized {

rust/kernel/alloc/vec_ext.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use super::{AllocError, Flags};
66
use alloc::vec::Vec;
7-
use core::result::Result;
87

98
/// Extensions to [`Vec`].
109
pub trait VecExt<T>: Sized {

rust/kernel/error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{alloc::AllocError, str::CStr};
88

99
use alloc::alloc::LayoutError;
1010

11-
use core::convert::From;
1211
use core::fmt;
1312
use core::num::TryFromIntError;
1413
use core::str::Utf8Error;

rust/kernel/net/phy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//!
77
//! C headers: [`include/linux/phy.h`](srctree/include/linux/phy.h).
88
9-
use crate::{bindings, error::*, prelude::*, str::CStr, types::Opaque};
9+
use crate::{error::*, prelude::*, types::Opaque};
1010

1111
use core::marker::PhantomData;
1212

rust/kernel/print.rs

-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ use core::{
1313

1414
use crate::str::RawFormatter;
1515

16-
#[cfg(CONFIG_PRINTK)]
17-
use crate::bindings;
18-
1916
// Called from `vsprintf` with format specifier `%pA`.
2017
#[no_mangle]
2118
unsafe extern "C" fn rust_fmt_argument(
@@ -35,8 +32,6 @@ unsafe extern "C" fn rust_fmt_argument(
3532
/// Public but hidden since it should only be used from public macros.
3633
#[doc(hidden)]
3734
pub mod format_strings {
38-
use crate::bindings;
39-
4035
/// The length we copy from the `KERN_*` kernel prefixes.
4136
const LENGTH_PREFIX: usize = 2;
4237

rust/kernel/str.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ use alloc::vec::Vec;
77
use core::fmt::{self, Write};
88
use core::ops::{self, Deref, DerefMut, Index};
99

10-
use crate::{
11-
bindings,
12-
error::{code::*, Error},
13-
};
10+
use crate::error::{code::*, Error};
1411

1512
/// Byte string without UTF-8 validity guarantee.
1613
#[repr(transparent)]

rust/kernel/sync/arc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
1818
use crate::{
1919
alloc::{box_ext::BoxExt, AllocError, Flags},
20-
bindings,
2120
error::{self, Error},
2221
init::{self, InPlaceInit, Init, PinInit},
2322
try_init,

rust/kernel/sync/condvar.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
use super::{lock::Backend, lock::Guard, LockClassKey};
99
use crate::{
10-
bindings,
1110
init::PinInit,
1211
pin_init,
1312
str::CStr,

rust/kernel/sync/lock.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! spinlocks, raw spinlocks) to be provided with minimal effort.
77
88
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};
1010
use core::{cell::UnsafeCell, marker::PhantomData, marker::PhantomPinned};
1111
use macros::pin_data;
1212

rust/kernel/sync/lock/mutex.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//!
55
//! This module allows Rust code to use the kernel's `struct mutex`.
66
7-
use crate::bindings;
8-
97
/// Creates a [`Mutex`] initialiser with the given name and a newly-created lock class.
108
///
119
/// It uses the name if one is given, otherwise it generates one based on the file name and line

rust/kernel/sync/lock/spinlock.rs

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//!
55
//! This module allows Rust code to use the kernel's `spinlock_t`.
66
7-
use crate::bindings;
8-
97
/// Creates a [`SpinLock`] initialiser with the given name and a newly-created lock class.
108
///
119
/// It uses the name if one is given, otherwise it generates one based on the file name and line

rust/kernel/task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//!
55
//! C header: [`include/linux/sched.h`](srctree/include/linux/sched.h).
66
7-
use crate::{bindings, types::Opaque};
7+
use crate::types::Opaque;
88
use core::{
99
ffi::{c_int, c_long, c_uint},
1010
marker::PhantomData,

rust/kernel/workqueue.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@
133133
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
134134
135135
use crate::alloc::{AllocError, Flags};
136-
use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
137-
use alloc::boxed::Box;
136+
use crate::{prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
138137
use core::marker::PhantomData;
139-
use core::pin::Pin;
140138

141139
/// Creates a [`Work`] initialiser with the given name and a newly-created lock class.
142140
#[macro_export]

0 commit comments

Comments
 (0)