Skip to content

Commit

Permalink
Merge pull request thesofproject#96 from Rust-for-Linux/rust-clean-cl…
Browse files Browse the repository at this point in the history
…ippy

Go clippy-free and a cleanup
  • Loading branch information
ojeda authored Feb 26, 2021
2 parents 57db449 + 2cd2b9a commit 0440a1c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 20 deletions.
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,15 @@ KBUILD_LDFLAGS :=
CLANG_FLAGS :=

ifeq ($(KBUILD_CLIPPY),1)
CLIPPY_QUIET_TAG := CLIPPY$(space)
RUSTC_OR_CLIPPY_QUIET := CLIPPY
RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER)
else
CLIPPY_QUIET_TAG :=
CLIPPY_DRIVER :=
RUSTC_OR_CLIPPY_QUIET := RUSTC
RUSTC_OR_CLIPPY = $(RUSTC)
endif
export CLIPPY_QUIET_TAG
export RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY

export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC CLIPPY_DRIVER BINDGEN
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC BINDGEN
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
Expand Down
11 changes: 6 additions & 5 deletions rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ $(objtree)/rust/exports_kernel_generated.h: $(objtree)/rust/kernel.o FORCE

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

quiet_cmd_rustc_library = RUSTC L $(if $(skip_clippy),,$(CLIPPY_QUIET_TAG))$@
quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
cmd_rustc_library = \
RUST_BINDINGS_FILE=$(abspath $(objtree)/rust/bindings_generated.rs) \
$(if $(skip_clippy),,$(CLIPPY_DRIVER)) $(RUSTC) $(rustc_flags) \
$(rustc_cross_flags) $(rustc_target_flags) \
$(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
$(rustc_flags) $(rustc_cross_flags) $(rustc_target_flags) \
--crate-type rlib --out-dir $(objtree)/rust/ -L $(objtree)/rust/ \
--crate-name $(patsubst %.o,%,$(notdir $@)) $<; \
mv $(objtree)/rust/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \
Expand Down
4 changes: 4 additions & 0 deletions rust/compiler_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#![compiler_builtins]
#![no_builtins]
#![no_std]
#![deny(clippy::complexity)]
#![deny(clippy::correctness)]
#![deny(clippy::perf)]
#![deny(clippy::style)]

macro_rules! define_panicking_intrinsics(
($reason: tt, { $($ident: ident, )* }) => {
Expand Down
8 changes: 4 additions & 4 deletions rust/kernel/file_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ impl<T: FileOperations> FileOperationsVtable<T> {
pub(crate) const VTABLE: bindings::file_operations = bindings::file_operations {
open: Some(open_callback::<T>),
release: Some(release_callback::<T>),
read: if let Some(_) = T::READ {
read: if T::READ.is_some() {
Some(read_callback::<T>)
} else {
None
},
write: if let Some(_) = T::WRITE {
write: if T::WRITE.is_some() {
Some(write_callback::<T>)
} else {
None
},
llseek: if let Some(_) = T::SEEK {
llseek: if T::SEEK.is_some() {
Some(llseek_callback::<T>)
} else {
None
Expand All @@ -184,7 +184,7 @@ impl<T: FileOperations> FileOperationsVtable<T> {
fasync: None,
flock: None,
flush: None,
fsync: if let Some(_) = T::FSYNC {
fsync: if T::FSYNC.is_some() {
Some(fsync_callback::<T>)
} else {
None
Expand Down
4 changes: 4 additions & 0 deletions rust/kernel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#![no_std]
#![feature(allocator_api, alloc_error_handler)]
#![deny(clippy::complexity)]
#![deny(clippy::correctness)]
#![deny(clippy::perf)]
#![deny(clippy::style)]

// Ensure conditional compilation based on the kernel configuration works;
// otherwise we may silently break things like initcall handling.
Expand Down
6 changes: 6 additions & 0 deletions rust/kernel/miscdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ impl Registration {
}
}

impl Default for Registration {
fn default() -> Self {
Self::new()
}
}

// SAFETY: The only method is `register()`, which requires a (pinned) mutable
// `Registration`, so it is safe to pass `&Registration` to multiple threads
// because it offers no interior mutability.
Expand Down
7 changes: 6 additions & 1 deletion rust/kernel/printk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub struct LogLineWriter {
pos: usize,
}

#[allow(clippy::new_without_default)]
impl LogLineWriter {
/// Creates a new [`LogLineWriter`].
pub fn new() -> LogLineWriter {
Expand All @@ -49,6 +48,12 @@ impl LogLineWriter {
}
}

impl Default for LogLineWriter {
fn default() -> Self {
Self::new()
}
}

impl fmt::Write for LogLineWriter {
fn write_str(&mut self, s: &str) -> fmt::Result {
let copy_len = cmp::min(LOG_LINE_MAX - self.pos, s.as_bytes().len());
Expand Down
10 changes: 7 additions & 3 deletions rust/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
//!
//! C header: [`include/linux/moduleparam.h`](../../../include/linux/moduleparam.h)
#![deny(clippy::complexity)]
#![deny(clippy::correctness)]
#![deny(clippy::perf)]
#![deny(clippy::style)]

use proc_macro::{token_stream, Delimiter, Group, TokenStream, TokenTree};

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

fn expect_end(it: &mut token_stream::IntoIter) {
if let None = it.next() {
} else {
if it.next().is_some() {
panic!("Expected end");
}
}
Expand Down Expand Up @@ -73,7 +77,7 @@ fn get_byte_string(it: &mut token_stream::IntoIter, expected_name: &str) -> Stri
let byte_string = get_literal(it, expected_name);

assert!(byte_string.starts_with("b\""));
assert!(byte_string.ends_with("\""));
assert!(byte_string.ends_with('\"'));

byte_string[2..byte_string.len() - 1].to_string()
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ $(obj)/%.lst: $(src)/%.c FORCE

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

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

0 comments on commit 0440a1c

Please sign in to comment.