Skip to content

Commit 302e275

Browse files
committed
Go clippy-clean for the rust/* crates and enforce it
This covers the default clippy warnings. Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 57db449 commit 302e275

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

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
}

0 commit comments

Comments
 (0)