Skip to content

Commit 0440a1c

Browse files
authored
Merge pull request #96 from Rust-for-Linux/rust-clean-clippy
Go clippy-free and a cleanup
2 parents 57db449 + 2cd2b9a commit 0440a1c

File tree

9 files changed

+45
-20
lines changed

9 files changed

+45
-20
lines changed

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,15 @@ KBUILD_LDFLAGS :=
525525
CLANG_FLAGS :=
526526

527527
ifeq ($(KBUILD_CLIPPY),1)
528-
CLIPPY_QUIET_TAG := CLIPPY$(space)
528+
RUSTC_OR_CLIPPY_QUIET := CLIPPY
529+
RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER)
529530
else
530-
CLIPPY_QUIET_TAG :=
531-
CLIPPY_DRIVER :=
531+
RUSTC_OR_CLIPPY_QUIET := RUSTC
532+
RUSTC_OR_CLIPPY = $(RUSTC)
532533
endif
533-
export CLIPPY_QUIET_TAG
534+
export RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY
534535

535-
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC CLIPPY_DRIVER BINDGEN
536+
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC BINDGEN
536537
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
537538
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
538539
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD

rust/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ $(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE
9090

9191
# `-Cpanic=unwind -Cforce-unwind-tables=y` overrides `rustc_flags` in order to
9292
# avoid the https://github.com/rust-lang/rust/issues/82320 rustc crash.
93-
quiet_cmd_rustc_procmacro = RUSTC P $(CLIPPY_QUIET_TAG)$@
93+
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
9494
cmd_rustc_procmacro = \
95-
$(CLIPPY_DRIVER) $(RUSTC) $(rustc_flags) --emit=dep-info,link --extern proc_macro \
95+
$(RUSTC_OR_CLIPPY) $(rustc_flags) \
96+
--emit=dep-info,link --extern proc_macro \
9697
-Cpanic=unwind -Cforce-unwind-tables=y \
9798
--crate-type proc-macro --out-dir $(objtree)/rust/ \
9899
--crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \
@@ -102,11 +103,11 @@ quiet_cmd_rustc_procmacro = RUSTC P $(CLIPPY_QUIET_TAG)$@
102103
$(objtree)/rust/libmodule.so: $(srctree)/rust/module.rs FORCE
103104
$(call if_changed_dep,rustc_procmacro)
104105

105-
quiet_cmd_rustc_library = RUSTC L $(if $(skip_clippy),,$(CLIPPY_QUIET_TAG))$@
106+
quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
106107
cmd_rustc_library = \
107108
RUST_BINDINGS_FILE=$(abspath $(objtree)/rust/bindings_generated.rs) \
108-
$(if $(skip_clippy),,$(CLIPPY_DRIVER)) $(RUSTC) $(rustc_flags) \
109-
$(rustc_cross_flags) $(rustc_target_flags) \
109+
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
110+
$(rustc_flags) $(rustc_cross_flags) $(rustc_target_flags) \
110111
--crate-type rlib --out-dir $(objtree)/rust/ -L $(objtree)/rust/ \
111112
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \
112113
mv $(objtree)/rust/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \

rust/compiler_builtins.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#![compiler_builtins]
2626
#![no_builtins]
2727
#![no_std]
28+
#![deny(clippy::complexity)]
29+
#![deny(clippy::correctness)]
30+
#![deny(clippy::perf)]
31+
#![deny(clippy::style)]
2832

2933
macro_rules! define_panicking_intrinsics(
3034
($reason: tt, { $($ident: ident, )* }) => {

rust/kernel/file_operations.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ impl<T: FileOperations> FileOperationsVtable<T> {
160160
pub(crate) const VTABLE: bindings::file_operations = bindings::file_operations {
161161
open: Some(open_callback::<T>),
162162
release: Some(release_callback::<T>),
163-
read: if let Some(_) = T::READ {
163+
read: if T::READ.is_some() {
164164
Some(read_callback::<T>)
165165
} else {
166166
None
167167
},
168-
write: if let Some(_) = T::WRITE {
168+
write: if T::WRITE.is_some() {
169169
Some(write_callback::<T>)
170170
} else {
171171
None
172172
},
173-
llseek: if let Some(_) = T::SEEK {
173+
llseek: if T::SEEK.is_some() {
174174
Some(llseek_callback::<T>)
175175
} else {
176176
None
@@ -184,7 +184,7 @@ impl<T: FileOperations> FileOperationsVtable<T> {
184184
fasync: None,
185185
flock: None,
186186
flush: None,
187-
fsync: if let Some(_) = T::FSYNC {
187+
fsync: if T::FSYNC.is_some() {
188188
Some(fsync_callback::<T>)
189189
} else {
190190
None

rust/kernel/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
1414
#![no_std]
1515
#![feature(allocator_api, alloc_error_handler)]
16+
#![deny(clippy::complexity)]
17+
#![deny(clippy::correctness)]
18+
#![deny(clippy::perf)]
19+
#![deny(clippy::style)]
1620

1721
// Ensure conditional compilation based on the kernel configuration works;
1822
// otherwise we may silently break things like initcall handling.

rust/kernel/miscdev.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ impl Registration {
7373
}
7474
}
7575

76+
impl Default for Registration {
77+
fn default() -> Self {
78+
Self::new()
79+
}
80+
}
81+
7682
// SAFETY: The only method is `register()`, which requires a (pinned) mutable
7783
// `Registration`, so it is safe to pass `&Registration` to multiple threads
7884
// because it offers no interior mutability.

rust/kernel/printk.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub struct LogLineWriter {
3333
pos: usize,
3434
}
3535

36-
#[allow(clippy::new_without_default)]
3736
impl LogLineWriter {
3837
/// Creates a new [`LogLineWriter`].
3938
pub fn new() -> LogLineWriter {
@@ -49,6 +48,12 @@ impl LogLineWriter {
4948
}
5049
}
5150

51+
impl Default for LogLineWriter {
52+
fn default() -> Self {
53+
Self::new()
54+
}
55+
}
56+
5257
impl fmt::Write for LogLineWriter {
5358
fn write_str(&mut self, s: &str) -> fmt::Result {
5459
let copy_len = cmp::min(LOG_LINE_MAX - self.pos, s.as_bytes().len());

rust/module.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
//!
55
//! C header: [`include/linux/moduleparam.h`](../../../include/linux/moduleparam.h)
66
7+
#![deny(clippy::complexity)]
8+
#![deny(clippy::correctness)]
9+
#![deny(clippy::perf)]
10+
#![deny(clippy::style)]
11+
712
use proc_macro::{token_stream, Delimiter, Group, TokenStream, TokenTree};
813

914
fn expect_ident(it: &mut token_stream::IntoIter) -> String {
@@ -39,8 +44,7 @@ fn expect_group(it: &mut token_stream::IntoIter) -> Group {
3944
}
4045

4146
fn expect_end(it: &mut token_stream::IntoIter) {
42-
if let None = it.next() {
43-
} else {
47+
if it.next().is_some() {
4448
panic!("Expected end");
4549
}
4650
}
@@ -73,7 +77,7 @@ fn get_byte_string(it: &mut token_stream::IntoIter, expected_name: &str) -> Stri
7377
let byte_string = get_literal(it, expected_name);
7478

7579
assert!(byte_string.starts_with("b\""));
76-
assert!(byte_string.ends_with("\""));
80+
assert!(byte_string.ends_with('\"'));
7781

7882
byte_string[2..byte_string.len() - 1].to_string()
7983
}

scripts/Makefile.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ $(obj)/%.lst: $(src)/%.c FORCE
301301

302302
rustc_cross_flags := --target=$(srctree)/arch/$(SRCARCH)/rust/target.json
303303

304-
quiet_cmd_rustc_o_rs = RUSTC $(CLIPPY_QUIET_TAG)$(quiet_modtag) $@
304+
quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
305305
cmd_rustc_o_rs = \
306306
RUST_MODFILE=$(modfile) \
307-
$(CLIPPY_DRIVER) $(RUSTC) $(rustc_flags) $(rustc_cross_flags) \
307+
$(RUSTC_OR_CLIPPY) $(rustc_flags) $(rustc_cross_flags) \
308308
--extern alloc --extern kernel \
309309
--crate-type rlib --out-dir $(obj) -L $(objtree)/rust/ \
310310
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \

0 commit comments

Comments
 (0)