Skip to content

Commit 0569939

Browse files
authored
Address even more clippy lints (theseus-os#805)
Satisfies and enables the following: * `blocks_in_if_conditions` * `comparison-chain` * `declare_interior_mutable_const` * `fn_to_numeric_cast` * `comparison_chain`
1 parent 8052fb0 commit 0569939

File tree

8 files changed

+25
-19
lines changed

8 files changed

+25
-19
lines changed

applications/deps/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,17 @@ fn find_crate(crate_name: &str) -> Result<(StrRef, StrongCrateRef), String> {
406406
fn find_section(section_name: &str) -> Result<StrongSectionRef, String> {
407407
let namespace = get_my_current_namespace();
408408
let matching_symbols = namespace.find_symbols_starting_with(section_name);
409-
if matching_symbols.len() == 1 {
410-
return matching_symbols[0].1.upgrade()
411-
.ok_or_else(|| format!("Found matching symbol name but couldn't get reference to section"));
412-
} else if matching_symbols.len() > 1 {
413-
return Err(matching_symbols.into_iter().map(|(k, _v)| k).collect::<Vec<String>>().join("\n"));
414-
} else {
415-
// continue on
409+
match matching_symbols.len() {
410+
1 => return matching_symbols[0].1
411+
.upgrade()
412+
.ok_or_else(|| format!("Found matching symbol name but couldn't get reference to section")),
413+
2.. => return Err(matching_symbols
414+
.into_iter()
415+
.map(|(k, _v)| k)
416+
.collect::<Vec<String>>()
417+
.join("\n")
418+
),
419+
_ => { /* no matches, continue on */ },
416420
}
417421

418422
// If it wasn't a global section in the symbol map, then we need to find its containing crate

kernel/deferred_interrupt_tasks/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub enum InterruptRegistrationError {
6868
/// the interrupt handler at the given `existing_handler_address`.
6969
IrqInUse {
7070
irq: u8,
71-
existing_handler_address: u64
71+
existing_handler_address: usize
7272
},
7373
/// The given error occurred when spawning the deferred interrupt task.
7474
SpawnError(&'static str),

kernel/frame_allocator/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
//! We don't need to do so until we actually run out of address space or until
1919
//! a requested address is in a chunk that needs to be merged.
2020
21+
#![allow(clippy::blocks_in_if_conditions)]
2122
#![no_std]
2223

2324
extern crate alloc;

kernel/interrupts/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ fn _enable_pic() {
197197
/// # Return
198198
/// * `Ok(())` if successfully registered, or
199199
/// * `Err(existing_handler_address)` if the given `interrupt_num` was already in use.
200-
pub fn register_interrupt(interrupt_num: u8, func: HandlerFunc) -> Result<(), u64> {
200+
pub fn register_interrupt(interrupt_num: u8, func: HandlerFunc) -> Result<(), usize> {
201201
let mut idt = IDT.lock();
202202

203203
// If the existing handler stored in the IDT is either missing (has an address of `0`)
204204
// or is the default handler, that signifies the interrupt number is available.
205205
let idt_entry = &mut idt[interrupt_num as usize];
206-
let existing_handler_addr = idt_entry.handler_addr().as_u64();
207-
if existing_handler_addr == 0 || existing_handler_addr == unimplemented_interrupt_handler as u64 {
206+
let existing_handler_addr = idt_entry.handler_addr().as_u64() as usize;
207+
if existing_handler_addr == 0 || existing_handler_addr == unimplemented_interrupt_handler as usize {
208208
idt_entry.set_handler_fn(func);
209209
Ok(())
210210
} else {
@@ -225,7 +225,7 @@ pub fn register_msi_interrupt(func: HandlerFunc) -> Result<u8, &'static str> {
225225
// try to find an unused interrupt number in the IDT
226226
let interrupt_num = idt.slice(32..=255)
227227
.iter()
228-
.rposition(|&entry| entry.handler_addr().as_u64() == unimplemented_interrupt_handler as u64)
228+
.rposition(|&entry| entry.handler_addr().as_u64() as usize == unimplemented_interrupt_handler as usize)
229229
.map(|entry| entry + 32)
230230
.ok_or("register_msi_interrupt: no available interrupt handlers (BUG: IDT is full?)")?;
231231

@@ -253,7 +253,7 @@ pub fn deregister_interrupt(interrupt_num: u8, func: HandlerFunc) -> Result<(),
253253

254254
// check if the handler stored is the same as the one provided
255255
// this is to make sure no other application can deregister your interrupt
256-
if idt[interrupt_num as usize].handler_addr().as_u64() == func as u64 {
256+
if idt[interrupt_num as usize].handler_addr().as_u64() as usize == func as usize {
257257
idt[interrupt_num as usize].set_handler_fn(unimplemented_interrupt_handler);
258258
Ok(())
259259
}

kernel/mod_mgmt/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(clippy::blocks_in_if_conditions)]
12
#![no_std]
23
#![feature(let_chains)]
34

kernel/pit_clock/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn enable_interrupts(freq_hertz: u32) -> Result<(), &'static str> {
4848
// Register the interrupt handler
4949
match interrupts::register_interrupt(PIT_CHANNEL_0_IRQ, pit_timer_handler) {
5050
Ok(_) => { /* success, do nothing */}
51-
Err(handler) if handler == pit_timer_handler as u64 => { /* already registered, do nothing */ }
51+
Err(handler) if handler == pit_timer_handler as usize => { /* already registered, do nothing */ }
5252
Err(_other) => return Err(" PIT clock IRQ was already in use; sharing IRQs is currently unsupported"),
5353
}
5454

kernel/serial_port/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl SerialPort {
204204
};
205205
}
206206
Err(InterruptRegistrationError::IrqInUse { irq, existing_handler_address }) => {
207-
if existing_handler_address != interrupt_handler as u64 {
207+
if existing_handler_address != interrupt_handler as usize {
208208
error!("Failed to register interrupt handler at IRQ {:#X} for serial port {:#X}. \
209209
Existing interrupt handler was a different handler, at address {:#X}.",
210210
irq, base_port, existing_handler_address,

lints.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ zst-offset
169169
assertions-on-constants
170170
assign-op-pattern
171171
disallowed-names
172-
# blocks-in-if-conditions
172+
blocks-in-if-conditions
173173
bool-assert-comparison
174174
borrow-interior-mutable-const
175175
builtin-type-shadow
@@ -180,9 +180,9 @@ cmp-null
180180
collapsible-else-if
181181
collapsible-if
182182
collapsible-match
183-
# comparison-chain
183+
comparison-chain
184184
comparison-to-empty
185-
# declare-interior-mutable-const
185+
declare-interior-mutable-const
186186
disallowed-methods
187187
disallowed-types
188188
double-must-use
@@ -192,7 +192,7 @@ enum-variant-names
192192
err-expect
193193
excessive-precision
194194
field-reassign-with-default
195-
# fn-to-numeric-cast
195+
fn-to-numeric-cast
196196
fn-to-numeric-cast-with-truncation
197197
for-kv-map
198198
# from-over-into

0 commit comments

Comments
 (0)