Remove redundant imports of items re-exported from prelude
Subsystems (9)
Gary Guo
reviewercover Remove redundant imports of items re-exported from prelude
We had a few occurrence of these redundant imports and up until now they're mostly checked by human reviews.
I have now implemented a new lint in klint, which is able to spot these and advice on using prelude imports instead. It caught a few existing cases that slip through the review. Thus, fix them.
Gary Guo (3):
gpu: nova-core: remove imports available via prelude
block: rnull: remove imports available via prelude
samples: rust: remove imports available via prelude
drivers/block/rnull/configfs.rs | 1 - drivers/block/rnull/rnull.rs | 3 --- drivers/gpu/nova-core/firmware/fwsec.rs | 1 - drivers/gpu/nova-core/firmware/gsp.rs | 12 +++++------- drivers/gpu/nova-core/firmware/riscv.rs | 2 -- drivers/gpu/nova-core/gsp/sequencer.rs | 8 +------- drivers/gpu/nova-core/sbuffer.rs | 5 +---- samples/rust/rust_driver_auxiliary.rs | 1 - samples/rust/rust_misc_device.rs | 2 -- samples/rust/rust_print_main.rs | 2 +- 10 files changed, 8 insertions(+), 29 deletions(-)
base-commit: a0c666c25aeefd16f4b088c6549a6fb6b65a8a1d
Signature · 1 line
2.51.2
Gary Guo
reviewerPATCH 1/3 gpu: nova-core: remove imports available via prelude
These imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.
--- drivers/gpu/nova-core/firmware/fwsec.rs | 1 - drivers/gpu/nova-core/firmware/gsp.rs | 12 +++++------- drivers/gpu/nova-core/firmware/riscv.rs | 2 -- drivers/gpu/nova-core/gsp/sequencer.rs | 8 +------- drivers/gpu/nova-core/sbuffer.rs | 5 +---- 5 files changed, 7 insertions(+), 21 deletions(-)
drivers/gpu/nova-core/firmware/fwsec.rs +0 -1
@@ -12,7 +12,6 @@use core::{ marker::PhantomData , - mem::size_of, ops::Deref ,// };
drivers/gpu/nova-core/firmware/gsp.rs +5 -7
@@ -1,7 +1,5 @@// SPDX-License-Identifier: GPL-2.0 -use core::mem::size_of_val; -use kernel::{ device, dma::{
@@ -34,11 +32,11 @@/// that scheme before nova-core becomes stable, which means this module will eventually be /// removed. mod elf { -use core::mem::size_of; - -use kernel::bindings; -use kernel::str::CStr ; -use kernel::transmute::FromBytes ; +use kernel::{ + bindings, + prelude::*, + transmute::FromBytes ,// + };/// Newtype to provide a [`FromBytes`] implementation. #[repr(transparent)]
drivers/gpu/nova-core/firmware/riscv.rs +0 -2
@@ -3,8 +3,6 @@//! Support for firmware binaries designed to run on a RISC-V core. Such firmwares files have a //! dedicated header. -use core::mem::size_of; -use kernel::{ device, firmware::Firmware ,
drivers/gpu/nova-core/gsp/sequencer.rs +1 -7
@@ -2,13 +2,7 @@//! GSP Sequencer implementation for Pre-hopper GSP boot sequence. -use core::{ - array, - mem::{ - size_of, - size_of_val,// - }, -}; +use core::array;use kernel::{ device,
drivers/gpu/nova-core/sbuffer.rs +1 -4
@@ -2,10 +2,7 @@use core::ops::Deref ; -use kernel::{ - alloc::KVec , - prelude::*,// -}; +use kernel::prelude::*;/// A buffer abstraction for discontiguous byte slices. ///
Signature · 1 line
2.51.2
Danilo Krummrich
maintainerRe: [PATCH 1/3] gpu: nova-core: remove imports available via prelude
Quoted 4 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>
I will pick this one up after -rc1 is out.
Re: [PATCH 1/3] gpu: nova-core: remove imports available via prelude
Quoted 1 line · Danilo Krummrich
I will pick this one up after -rc1 is out.
I just checked and there shouldn't be any conflicts, so if you want to pick this one up as well, please do. :)
Given that klint can do quite some convinient extra checks, should we consider making it an optional part of the build? Similar to what we do with clippy?
Re: [PATCH 1/3] gpu: nova-core: remove imports available via prelude
Quoted 5 lines · Danilo Krummrich
I just checked and there shouldn't be any conflicts, so if you want to pick this one up as well, please do. :)
Acked-by Danilo Krummrich <[email protected]>
Will, do thanks!
Quoted 2 lines
Given that klint can do quite some convinient extra checks, should we consider making it an optional part of the build? Similar to what we do with clippy?
Yeah, that is the goal (e.g. KLINT=1 or similar eventually).
But if someone wants to run it, it is already possible, IIUC Andreas already did the other day.
To make things easier for developers/maintainers, I asked Nathan the other day if we could have them in the LLVM+Rust kernel.org toolchains, and he was supportive on adding it there when Gary is ready, so it may be straightforward to set up in CIs! :)
(And later on, ideally, even on linux-next when we things are more settled)
Cheers,
Miguel
Miguel Ojeda
AppliedRe: [PATCH 1/3] gpu: nova-core: remove imports available via prelude
In reply to Gary GuoQuoted 5 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>
Applied to rust-next -- thanks everyone!
With this last one done, this series has all been applied.
Cheers,
Miguel
Gary Guo
reviewerPATCH 2/3 block: rnull: remove imports available via prelude
In reply to Gary GuoThese imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.
--- drivers/block/rnull/configfs.rs | 1 - drivers/block/rnull/rnull.rs | 3 --- 2 files changed, 4 deletions(-)
drivers/block/rnull/configfs.rs +0 -1
@@ -12,7 +12,6 @@ str::{kstrtobool_bytes, CString}, sync::Mutex, }; -use pin_init::PinInit ;pub (crate )fn subsystem () ->impl PinInit <kernel::configfs::Subsystem <Config >,Error > {let item_type =configfs_attrs! {
drivers/block/rnull/rnull.rs +0 -3
@@ -14,12 +14,9 @@ Operations, TagSet, }, }, - error::Result, - pr_info, prelude::*, sync::{aref::ARef, Arc}, }; -use pin_init::PinInit ;module! {type :NullBlkModule ,
Signature · 1 line
2.51.2
Re: [PATCH 2/3] block: rnull: remove imports available via prelude
Quoted 4 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>
Best regards,
Andreas Hindborg
Re: [PATCH 2/3] block: rnull: remove imports available via prelude
Quoted 2 lines · Andreas Hindborg
Acked-by Andreas Hindborg <[email protected]>
Is this for Jens or do you want me to pick it up?
Thanks!
Cheers,
Miguel
Andreas Hindborg
maintainerRe: [PATCH 2/3] block: rnull: remove imports available via prelude
Quoted 5 lines · Miguel Ojeda
Quoted 2 lines · Andreas Hindborg
Acked-by Andreas Hindborg <[email protected]>Is this for Jens or do you want me to pick it up?
I think Jens is supposed to pick the block patches.
Best regards,
Andreas Hindborg
Gary Guo
reviewerPATCH 3/3 samples: rust: remove imports available via prelude
In reply to Gary GuoThese imports are already in scope by importing kernel::prelude::* and does not need to be imported separately.
--- samples/rust/rust_driver_auxiliary.rs | 1 - samples/rust/rust_misc_device.rs | 2 -- samples/rust/rust_print_main.rs | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-)
samples/rust/rust_driver_auxiliary.rs +0 -1
@@ -18,7 +18,6 @@ };use core::any::TypeId ; -use pin_init::PinInit ;const MODULE_NAME : &CStr = <LocalModule as kernel::ModuleMetadata >::NAME ;const AUXILIARY_NAME : &CStr =c"auxiliary" ;
samples/rust/rust_misc_device.rs +0 -2
@@ -95,8 +95,6 @@//! } //! ``` -use core::pin::Pin ; -use kernel::{ device::Device , fs::{File ,Kiocb },
samples/rust/rust_print_main.rs +1 -1
@@ -101,7 +101,7 @@ fn drop(&mut self) { }mod trace { -use kernel::ffi::c_int; +use kernel::prelude::*; kernel::declare_trace! {/// # Safety
Signature · 1 line
2.51.2
Re: [PATCH 3/3] samples: rust: remove imports available via prelude
Quoted 1 line · Gary Guo
samples/rust/rust_driver_auxiliary.rs | 1 -
Re: [PATCH 3/3] samples: rust: remove imports available via prelude
In reply to Gary GuoQuoted 4 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>
Re: [PATCH 3/3] samples: rust: remove imports available via prelude
In reply to Gary GuoQuoted 2 lines · Gary Guo
samples/rust/rust_misc_device.rs | 2 --
If Greg/Arnd don't say otherwise, I will eventually pick this patch including the file above, given it is trivial.
Cheers,
Miguel
Re: [PATCH 3/3] samples: rust: remove imports available via prelude
Quoted 6 lines · Miguel Ojeda
Quoted 2 lines · Gary Guo
samples/rust/rust_misc_device.rs | 2 --If Greg/Arnd don't say otherwise, I will eventually pick this patch including the file above, given it is trivial.
No objection from me:
Re: [PATCH 3/3] samples: rust: remove imports available via prelude
In reply to Gary GuoQuoted 5 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>
Applied (this one only) to rust-next -- thanks everyone!
Cheers,
Miguel
Re: [PATCH 3/3] samples: rust: remove imports available via prelude
Quoted 8 lines · Miguel Ojeda
Quoted 5 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>Applied (this one only) to
rust-next-- thanks everyone!
Having my klint setup running now (many thanks Gary!) on today's rust-next [1] I still get
error: this item is available via prelude
--> samples/rust/rust_driver_auxiliary.rs:12:5
| 12 | error::Error, | ^^^^^^^^^^^^ |
= help: import with kernel::prelude::* instead
= note: -D klint::not-using-prelude implied by -D warnings = help: to override -D warnings add#[allow(klint::not_using_prelude)]
error: aborting due to 1 previous error
Somehow dropping this was not part of this patch. Not sure why ...
Best regards
Dirk
[1] HEAD is 08afcc38a64c ("Merge patch series "Add support for print exactly once"")
Gary Guo
reviewerRe: [PATCH 3/3] samples: rust: remove imports available via prelude
Quoted 24 lines · Dirk Behme
Quoted 8 lines · Miguel Ojeda
Quoted 5 lines · Gary Guo
These imports are already in scope by importing
kernel::prelude::*and does not need to be imported separately.Signed-off-by Gary Guo <[email protected]>Applied (this one only) to
rust-next-- thanks everyone!Having my klint setup running now (many thanks Gary!) on today's rust-next [1] I still get
error: this item is available via prelude
-->samples/rust/rust_driver_auxiliary.rs:12:5|12 |
error::Error,
| ^^^^^^^^^^^^
|
= help: import withkernel::prelude::*instead
= note:-D klint::not-using-preludeimplied by-D warnings= help: to override-D warningsadd#[allow(klint::not_using_prelude)]
Quoted 3 lines
error: aborting due to 1 previous error
Somehow dropping this was not part of this patch. Not sure why ...
It was already dropped in
https://lore.kernel.org/rust-for-linux/[email protected]/
Best,
Gary
Quoted 7 lines
Best regards
Dirk
[1] HEAD is
08afcc38a64c("Merge patch series "Add support for print exactly once"")
Quoted 9 lines · Gary Guo
We had a few occurrence of these redundant imports and up until now they're mostly checked by human reviews.
I have now implemented a new lint in klint, which is able to spot these and advice on using prelude imports instead. It caught a few existing cases that slip through the review. Thus, fix them.
This is great news, thanks Gary.
If others give Acked-bys, I can pick these all, but it may be easier to pick them independently (for that, the print sample should be split in principle, but it is so small that Acked-bys may work better for that last patch).
Cheers,
Miguel
Re: (subset) [PATCH 0/3] Remove redundant imports of items re-exported from prelude
In reply to Gary GuoQuoted 8 lines · Gary Guo
We had a few occurrence of these redundant imports and up until now they're mostly checked by human reviews.
I have now implemented a new lint in klint, which is able to spot these and advice on using prelude imports instead. It caught a few existing cases that slip through the review. Thus, fix them.
[...]
Applied, thanks!
[2/3] block: rnull: remove imports available via prelude
commit: b2b2ce870651db659247f34636e6243b4547e8af
Best regards,
Signature · 1 line
Jens Axboe