Skip to content

Commit b706b5e

Browse files
committed
fix: 修复重构后的 clippy 检查
- 调整路径解析、布尔判断和范围判断写法 - 派生 TimeZoneInformation 默认值实现 - 集中允许 Win32 hook 模块的 FFI 与未使用辅助项告警
1 parent bcf0dc7 commit b706b5e

12 files changed

Lines changed: 34 additions & 38 deletions

File tree

src/aime/mod.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ fn aime_port() -> u32 {
256256

257257
pub fn load_config(config: &Config, base_dir: impl AsRef<Path>) -> AimeConfig {
258258
let path = config.get_string_alias(&[("Aime", "aime_path"), ("aime", "aimePath")], "aime.txt");
259-
let aime_path = Path::new(&path)
260-
.is_absolute()
261-
.then(|| PathBuf::from(&path))
262-
.unwrap_or_else(|| base_dir.as_ref().join(path));
259+
let aime_path = if Path::new(&path).is_absolute() {
260+
PathBuf::from(&path)
261+
} else {
262+
base_dir.as_ref().join(path)
263+
};
263264
let authdata_path = resolve_path(
264265
base_dir.as_ref(),
265266
&config.get_string_alias(
@@ -275,10 +276,11 @@ pub fn load_config(config: &Config, base_dir: impl AsRef<Path>) -> AimeConfig {
275276
&[("Aime", "felica_path"), ("aime", "felicaPath")],
276277
"felica.txt",
277278
);
278-
let felica_path = Path::new(&felica_path)
279-
.is_absolute()
280-
.then(|| PathBuf::from(&felica_path))
281-
.unwrap_or_else(|| base_dir.as_ref().join(felica_path));
279+
let felica_path = if Path::new(&felica_path).is_absolute() {
280+
PathBuf::from(&felica_path)
281+
} else {
282+
base_dir.as_ref().join(felica_path)
283+
};
282284

283285
AimeConfig {
284286
enable: config.get_bool_alias(&[("Aime", "enable"), ("aime", "enable")], true),
@@ -318,10 +320,11 @@ fn dll_path(config: &Config, upper: &str, lower: &str) -> String {
318320
}
319321

320322
fn resolve_path(base_dir: impl AsRef<Path>, path: &str) -> PathBuf {
321-
Path::new(path)
322-
.is_absolute()
323-
.then(|| PathBuf::from(path))
324-
.unwrap_or_else(|| base_dir.as_ref().join(path))
323+
if Path::new(path).is_absolute() {
324+
PathBuf::from(path)
325+
} else {
326+
base_dir.as_ref().join(path)
327+
}
325328
}
326329

327330
pub fn vfd_set_text(text: &[u8], state: &AimeIoVfdState) {

src/iohook/uart.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn uart_init(port_no: u32) {
113113
}
114114

115115
pub fn is_uart_handle(handle: usize) -> bool {
116-
if handle >= FAKE_HANDLE_BASE && handle < FAKE_HANDLE_BASE + 0x10000 {
116+
if (FAKE_HANDLE_BASE..FAKE_HANDLE_BASE + 0x10000).contains(&handle) {
117117
return true;
118118
}
119119
HANDLE_PORTS
@@ -336,7 +336,7 @@ fn fake_handle(port_no: u32) -> usize {
336336
}
337337

338338
fn port_from_handle(handle: usize) -> Option<u32> {
339-
if handle >= FAKE_HANDLE_BASE && handle < FAKE_HANDLE_BASE + 0x10000 {
339+
if (FAKE_HANDLE_BASE..FAKE_HANDLE_BASE + 0x10000).contains(&handle) {
340340
return Some((handle & 0xFFFF) as u32);
341341
}
342342
HANDLE_PORTS.lock().ok()?.get(&handle).copied()

src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
#![allow(non_snake_case, clippy::manual_c_str_literals)]
1+
#![allow(
2+
non_snake_case,
3+
dead_code,
4+
clashing_extern_declarations,
5+
clippy::manual_c_str_literals,
6+
clippy::module_inception,
7+
clippy::too_many_arguments
8+
)]
29

310
mod aime;
411
mod autoplay;

src/platform/amvideo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::platform::winapi;
66
use crate::util::api::Api;
77

88
pub fn init(api: &Api, config: &Config) {
9-
if config.get_bool("AMVideo", "enable", true) == false {
9+
if !config.get_bool("AMVideo", "enable", true) {
1010
return;
1111
}
1212

src/platform/clock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum TimezoneMode {
3333
}
3434

3535
pub fn init(api: &Api, config: &Config) {
36-
if config.get_bool("Clock", "enable", true) == false {
36+
if !config.get_bool("Clock", "enable", true) {
3737
return;
3838
}
3939

src/platform/dvd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::platform::vfs;
33
use crate::util::api::Api;
44

55
pub fn init(api: &Api, config: &Config) {
6-
if config.get_bool("DVD", "enable", true) == false {
6+
if !config.get_bool("DVD", "enable", true) {
77
return;
88
}
99

src/platform/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct MiscConfig {
1919
}
2020

2121
pub fn init(api: &Api, config: &Config) {
22-
if config.get_bool("Misc", "enable", true) == false {
22+
if !config.get_bool("Misc", "enable", true) {
2323
return;
2424
}
2525

src/platform/pcbid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ static mut ORIG_GET_COMPUTER_NAME_A: Option<GetComputerNameAFn> = None;
1010
static SERIAL_NO: OnceCell<String> = OnceCell::new();
1111

1212
pub fn init(api: &Api, config: &Config) {
13-
if config.get_bool("PCBID", "enable", true) == false {
13+
if !config.get_bool("PCBID", "enable", true) {
1414
return;
1515
}
1616

src/platform/reg_hook.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ unsafe fn write_value(
502502
}
503503

504504
fn resolve_key_id(parent: usize, subkey: *const u16) -> Option<usize> {
505-
let subkey = unsafe { winapi::wide_to_string(subkey) }.unwrap_or_default();
505+
let subkey = winapi::wide_to_string(subkey).unwrap_or_default();
506506
let (root, path) = resolve_candidate(parent, &subkey)?;
507507
KEYS.lock()
508508
.ok()?

src/platform/system.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::util::api::Api;
66
const SYSFILE_NAME: &str = "sysfile.dat";
77

88
pub fn init(api: &Api, config: &Config) {
9-
if config.get_bool("System", "enable", true) == false {
9+
if !config.get_bool("System", "enable", true) {
1010
return;
1111
}
1212

0 commit comments

Comments
 (0)