Deny some rustc lints

The unreachable_pub lint is commented out because it seems like a good
idea but fixing the errors it causes would cause too much churn for it
to be done in this commit.
This commit is contained in:
Oliver Hamlet
2025-04-23 00:16:08 +01:00
parent 724b8b55c1
commit 0e98c82b57
6 changed files with 52 additions and 42 deletions
+28 -16
View File
@@ -1,5 +1,8 @@
use std::path::{Path, PathBuf};
#[cfg(windows)]
use windows::Win32::Storage::FileSystem::BY_HANDLE_FILE_INFORMATION;
use crate::{GameType, game::GameCache, plugin::has_ascii_extension};
const BSA_FILE_EXTENSION: &str = "bsa";
@@ -126,11 +129,6 @@ fn find_associated_archives_with_arbitrary_suffixes(
#[cfg(windows)]
fn are_file_paths_equivalent(lhs: &Path, rhs: &Path) -> bool {
use std::fs::File;
use std::os::windows::io::AsRawHandle;
use windows::Win32::{
Foundation::HANDLE,
Storage::FileSystem::{BY_HANDLE_FILE_INFORMATION, GetFileInformationByHandle},
};
if lhs == rhs {
return true;
@@ -144,24 +142,38 @@ fn are_file_paths_equivalent(lhs: &Path, rhs: &Path) -> bool {
return false;
};
let mut lhs_info = BY_HANDLE_FILE_INFORMATION::default();
let mut rhs_info = BY_HANDLE_FILE_INFORMATION::default();
// SAFETY: This is safe because the file handles and the info struct pointers are all valid until this function exits.
unsafe {
if GetFileInformationByHandle(HANDLE(lhs_file.as_raw_handle()), &mut lhs_info).is_err() {
return false;
}
let Some(lhs_info) = get_file_info(&lhs_file) else {
return false;
};
if GetFileInformationByHandle(HANDLE(rhs_file.as_raw_handle()), &mut rhs_info).is_err() {
return false;
}
}
let Some(rhs_info) = get_file_info(&rhs_file) else {
return false;
};
lhs_info.dwVolumeSerialNumber == rhs_info.dwVolumeSerialNumber
&& lhs_info.nFileIndexHigh == rhs_info.nFileIndexHigh
&& lhs_info.nFileIndexLow == rhs_info.nFileIndexLow
}
#[cfg(windows)]
fn get_file_info(file: &std::fs::File) -> Option<BY_HANDLE_FILE_INFORMATION> {
use std::os::windows::io::AsRawHandle;
use windows::Win32::{Foundation::HANDLE, Storage::FileSystem::GetFileInformationByHandle};
let mut info = BY_HANDLE_FILE_INFORMATION::default();
// SAFETY: This is safe because the file handles and the info struct pointers are all valid until this function exits.
#[expect(
unsafe_code,
reason = "There is currently no way to get this data safely"
)]
unsafe {
GetFileInformationByHandle(HANDLE(file.as_raw_handle()), &mut info)
.is_ok()
.then_some(info)
}
}
#[cfg(not(windows))]
fn are_file_paths_equivalent(lhs: &Path, rhs: &Path) -> bool {
use std::os::unix::fs::MetadataExt;
-4
View File
@@ -602,8 +602,6 @@ plugins:
}
mod write_minimal_list {
use crate::tests::{BLANK_DIFFERENT_ESM, BLANK_ESM};
use super::*;
#[test]
@@ -964,8 +962,6 @@ plugins:
}
mod plugin_metadata {
use crate::tests::BLANK_ESM;
use super::*;
#[test]
+6 -20
View File
@@ -1176,11 +1176,6 @@ mod tests {
mod set_additional_data_paths {
use std::time::{Duration, SystemTime};
use crate::{
metadata::{File, PluginMetadata},
tests::{BLANK_ESM, BLANK_ESP},
};
use super::*;
#[test]
@@ -1274,9 +1269,7 @@ mod tests {
mod is_valid_plugin {
use super::*;
use crate::tests::{
BLANK_ESM, BLANK_MASTER_DEPENDENT_ESM, NON_ASCII_ESM, NON_PLUGIN_FILE,
};
use crate::tests::{NON_ASCII_ESM, NON_PLUGIN_FILE};
#[apply(all_game_types)]
fn should_return_true_for_a_valid_non_ascii_plugin(game_type: GameType) {
@@ -1310,7 +1303,7 @@ mod tests {
.unwrap();
let plugin = fixture.data_path().join("empty.omwscripts");
let _ = std::fs::File::create(&plugin).unwrap();
std::fs::File::create(&plugin).unwrap();
if game_type == GameType::OpenMW {
assert!(game.is_valid_plugin(&plugin));
@@ -1345,7 +1338,7 @@ mod tests {
.unwrap();
let empty_file_path = fixture.data_path().join("empty.esp");
let _ = std::fs::File::create(&empty_file_path).unwrap();
std::fs::File::create(&empty_file_path).unwrap();
assert!(!game.is_valid_plugin(&empty_file_path));
}
@@ -1416,7 +1409,7 @@ mod tests {
}
mod load_plugin_headers {
use crate::tests::{BLANK_DIFFERENT_ESM, BLANK_ESM, BLANK_ESP, NON_PLUGIN_FILE};
use crate::tests::NON_PLUGIN_FILE;
use super::*;
@@ -1517,10 +1510,7 @@ mod tests {
mod load_plugins {
use std::error::Error;
use crate::tests::{
BLANK_DIFFERENT_ESM, BLANK_ESM, BLANK_ESP, BLANK_FULL_ESM,
BLANK_MASTER_DEPENDENT_ESM,
};
use crate::tests::BLANK_FULL_ESM;
use super::*;
@@ -1692,8 +1682,6 @@ mod tests {
}
mod load_plugins_common {
use crate::tests::{BLANK_ESM, BLANK_MASTER_DEPENDENT_ESM};
use super::*;
#[apply(all_game_types)]
@@ -1896,7 +1884,7 @@ mod tests {
}
mod sort_plugins {
use crate::tests::{BLANK_DIFFERENT_ESP, BLANK_ESP, initial_load_order};
use crate::tests::initial_load_order;
use super::*;
@@ -1958,8 +1946,6 @@ mod tests {
}
mod is_plugin_active {
use crate::tests::BLANK_ESP;
use super::*;
#[test]
+16
View File
@@ -1,3 +1,19 @@
// Deny some rustc lints that are allow-by-default.
#![deny(
ambiguous_negative_literals,
impl_trait_overcaptures,
let_underscore_drop,
missing_copy_implementations,
missing_debug_implementations,
non_ascii_idents,
redundant_imports,
redundant_lifetimes,
trivial_casts,
trivial_numeric_casts,
unit_bindings,
// unreachable_pub,
unsafe_code
)]
#![deny(clippy::pedantic)]
// Allow a few clippy pedantic lints.
#![allow(clippy::doc_markdown)]
+1 -1
View File
@@ -1017,7 +1017,7 @@ mod tests {
mod emit_yaml {
use super::*;
use crate::metadata::{MessageType, TagSuggestion, emit};
use crate::metadata::emit;
#[test]
fn should_omit_group_if_not_set() {
+1 -1
View File
@@ -705,7 +705,7 @@ mod tests {
std::fs::copy(data_path.join(blank_esm(game_type)), &omwgame).unwrap();
std::fs::copy(data_path.join(BLANK_ESP), &omwaddon).unwrap();
let _ = File::create(&omwscripts).unwrap();
File::create(&omwscripts).unwrap();
assert!(
Plugin::new(