mirror of
https://github.com/encounter/nod-rs.git
synced 2025-06-11 17:13:40 +00:00
clippy fixes
This commit is contained in:
parent
38183e4258
commit
56db78207a
@ -324,9 +324,8 @@ impl Preloader {
|
||||
}
|
||||
}
|
||||
|
||||
fn map_poisoned<T>(_: std::sync::PoisonError<T>) -> io::Error {
|
||||
io::Error::new(io::ErrorKind::Other, "Mutex poisoned")
|
||||
}
|
||||
#[inline]
|
||||
fn map_poisoned<T>(_: std::sync::PoisonError<T>) -> io::Error { io::Error::other("Mutex poisoned") }
|
||||
|
||||
pub struct SectorGroupLoader {
|
||||
io: Box<dyn BlockReader>,
|
||||
|
@ -215,23 +215,14 @@ pub(crate) fn check_block(
|
||||
p.has_hashes && start_sector >= p.data_start_sector && end_sector < p.data_end_sector
|
||||
}) {
|
||||
if input_position % SECTOR_SIZE as u64 != 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Partition block not aligned to sector boundary",
|
||||
));
|
||||
return Err(io::Error::other("Partition block not aligned to sector boundary"));
|
||||
}
|
||||
if buf.len() % SECTOR_SIZE != 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Partition block not a multiple of sector size",
|
||||
));
|
||||
return Err(io::Error::other("Partition block not a multiple of sector size"));
|
||||
}
|
||||
let block = if partition.has_encryption {
|
||||
if decrypted_block.len() < buf.len() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Decrypted block buffer too small",
|
||||
));
|
||||
return Err(io::Error::other("Decrypted block buffer too small"));
|
||||
}
|
||||
for i in 0..buf.len() / SECTOR_SIZE {
|
||||
decrypt_sector_b2b(
|
||||
|
@ -191,15 +191,12 @@ impl Block {
|
||||
/// Returns an error if the block does not contain the specified sector.
|
||||
pub fn ensure_contains(&self, sector: u32) -> io::Result<()> {
|
||||
if !self.contains(sector) {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"Sector {} not in block range {}-{}",
|
||||
sector,
|
||||
self.sector,
|
||||
self.sector + self.count
|
||||
),
|
||||
));
|
||||
return Err(io::Error::other(format!(
|
||||
"Sector {} not in block range {}-{}",
|
||||
sector,
|
||||
self.sector,
|
||||
self.sector + self.count
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ impl FileCallbackTGC {
|
||||
|
||||
impl FileCallback for FileCallbackTGC {
|
||||
fn read_file(&mut self, out: &mut [u8], name: &str, offset: u64) -> io::Result<()> {
|
||||
let fst = Fst::new(&self.fst).map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
let fst = Fst::new(&self.fst).map_err(io::Error::other)?;
|
||||
let (_, node) = fst.find(name).ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::NotFound, format!("File not found in FST: {}", name))
|
||||
})?;
|
||||
|
@ -939,7 +939,7 @@ impl BlockReader for BlockReaderWIA {
|
||||
decompressed.copy_to_slice(&mut out[..info.size as usize]);
|
||||
}
|
||||
if !decompressed.is_empty() {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Failed to consume all group data"));
|
||||
return Err(io::Error::other("Failed to consume all group data"));
|
||||
}
|
||||
|
||||
// Read first 0x80 bytes from disc header
|
||||
@ -1112,10 +1112,7 @@ impl BlockProcessor for BlockProcessorWIA {
|
||||
self.raw_data.as_ref(),
|
||||
)
|
||||
.ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Couldn't find partition or raw data for group {}", group_idx),
|
||||
)
|
||||
io::Error::other(format!("Couldn't find partition or raw data for group {}", group_idx))
|
||||
})?;
|
||||
|
||||
self.inner.seek(SeekFrom::Start(info.sector as u64 * SECTOR_SIZE as u64))?;
|
||||
@ -1126,10 +1123,7 @@ impl BlockProcessor for BlockProcessorWIA {
|
||||
let chunk_size = self.disc.chunk_size.get() as u64;
|
||||
let (mut group_data, hash_exception_data) = if info.in_partition {
|
||||
if info.size % SECTOR_DATA_SIZE as u32 != 0 {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Partition group size not aligned to sector",
|
||||
));
|
||||
return Err(io::Error::other("Partition group size not aligned to sector"));
|
||||
}
|
||||
|
||||
let mut buf = BytesMut::zeroed(info.size as usize);
|
||||
@ -1198,9 +1192,11 @@ impl BlockProcessor for BlockProcessorWIA {
|
||||
let mut buf = BytesMut::with_capacity(hash_exception_data.len() + group_data.len());
|
||||
buf.put_slice(hash_exception_data.as_ref());
|
||||
buf.put_slice(group_data.as_ref());
|
||||
if self.compressor.compress(buf.as_ref()).map_err(|e| {
|
||||
io::Error::new(io::ErrorKind::Other, format!("Failed to compress group: {}", e))
|
||||
})? {
|
||||
if self
|
||||
.compressor
|
||||
.compress(buf.as_ref())
|
||||
.map_err(|e| io::Error::other(format!("Failed to compress group: {}", e)))?
|
||||
{
|
||||
let compressed_size = self.compressor.buffer.len() as u32;
|
||||
// For WIA, we must always store compressed data.
|
||||
// For RVZ, only store compressed data if it's smaller than uncompressed.
|
||||
@ -1220,15 +1216,12 @@ impl BlockProcessor for BlockProcessorWIA {
|
||||
});
|
||||
}
|
||||
} else if !is_rvz {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"Failed to compress group {}: len {}, capacity {}",
|
||||
group_idx,
|
||||
self.compressor.buffer.len(),
|
||||
self.compressor.buffer.capacity()
|
||||
),
|
||||
));
|
||||
return Err(io::Error::other(format!(
|
||||
"Failed to compress group {}: len {}, capacity {}",
|
||||
group_idx,
|
||||
self.compressor.buffer.len(),
|
||||
self.compressor.buffer.capacity()
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,10 +332,7 @@ impl Compressor {
|
||||
}
|
||||
}
|
||||
#[allow(unreachable_patterns)] // if compression is disabled
|
||||
_ => Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Unsupported compression: {:?}", self.kind),
|
||||
)),
|
||||
_ => Err(io::Error::other(format!("Unsupported compression: {:?}", self.kind))),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -507,7 +504,6 @@ mod zstd_util {
|
||||
use std::io;
|
||||
|
||||
pub fn map_error_code(code: usize) -> io::Error {
|
||||
let msg = zstd_safe::get_error_name(code);
|
||||
io::Error::new(io::ErrorKind::Other, msg.to_string())
|
||||
io::Error::other(zstd_safe::get_error_name(code))
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ impl LaggedFibonacci {
|
||||
// Instead of doing the "shift by 18 instead of 16" oddity when actually outputting the data,
|
||||
// we can do the shifting (and byteswapping) at this point to make the output code simpler.
|
||||
for x in self.buffer.iter_mut() {
|
||||
*x = ((*x & 0xFF00FFFF) | (*x >> 2 & 0x00FF0000)).to_be();
|
||||
*x = ((*x & 0xFF00FFFF) | ((*x >> 2) & 0x00FF0000)).to_be();
|
||||
}
|
||||
for _ in 0..4 {
|
||||
self.forward();
|
||||
@ -74,7 +74,7 @@ impl LaggedFibonacci {
|
||||
*v = (*v >> 1) | (n & 0x80000000);
|
||||
}
|
||||
}
|
||||
out[16] ^= out[0] >> 9 ^ out[16] << 23;
|
||||
out[16] ^= (out[0] >> 9) ^ (out[16] << 23);
|
||||
}
|
||||
|
||||
/// Same as [`generate_seed`], but ensures the resulting seed is big-endian.
|
||||
|
@ -623,7 +623,7 @@ impl FileCallback for PartitionFileReader {
|
||||
"sys/apploader.img" => self.meta.raw_apploader.as_ref(),
|
||||
"sys/main.dol" => self.meta.raw_dol.as_ref(),
|
||||
path => {
|
||||
let fst = self.meta.fst().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
let fst = self.meta.fst().map_err(io::Error::other)?;
|
||||
let Some((_, node)) = fst.find(path) else {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::NotFound,
|
||||
|
Loading…
x
Reference in New Issue
Block a user