Fix clippy warnings

This commit is contained in:
Lucas Schwiderski 2025-04-21 23:13:36 +02:00
parent 38a023bea6
commit 3d05a2395e
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8
9 changed files with 25 additions and 34 deletions

View file

@ -34,7 +34,7 @@ glob = "0.3.0"
interprocess = "2.1.0" interprocess = "2.1.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
luajit2-sys = { path = "lib/luajit2-sys" } luajit2-sys = { path = "lib/luajit2-sys" }
minijinja = { version = "2.0.1", default-features = false } minijinja = { version = "2.0.1", default-features = false, features = ["serde"] }
nanorand = "0.7.0" nanorand = "0.7.0"
nexusmods = { path = "lib/nexusmods" } nexusmods = { path = "lib/nexusmods" }
notify = "8.0.0" notify = "8.0.0"

View file

@ -116,14 +116,14 @@ async fn patch_game_settings(state: Arc<ActionState>) -> Result<()> {
eyre::bail!("couldn't find 'boot_script' field"); eyre::bail!("couldn't find 'boot_script' field");
}; };
f.write_all(settings[0..i].as_bytes()).await?; f.write_all(&settings.as_bytes()[0..i]).await?;
f.write_all(b"boot_script = \"scripts/mod_main\"").await?; f.write_all(b"boot_script = \"scripts/mod_main\"").await?;
let Some(j) = settings[i..].find('\n') else { let Some(j) = settings[i..].find('\n') else {
eyre::bail!("couldn't find end of 'boot_script' field"); eyre::bail!("couldn't find end of 'boot_script' field");
}; };
f.write_all(settings[(i + j)..].as_bytes()).await?; f.write_all(&settings.as_bytes()[(i + j)..]).await?;
Ok(()) Ok(())
} }
@ -453,10 +453,7 @@ async fn build_bundles(state: Arc<ActionState>) -> Result<Vec<Bundle>> {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn patch_boot_bundle( async fn patch_boot_bundle(state: Arc<ActionState>, deployment_info: &str) -> Result<Vec<Bundle>> {
state: Arc<ActionState>,
deployment_info: &String,
) -> Result<Vec<Bundle>> {
let bundle_dir = Arc::new(state.game_dir.join("bundle")); let bundle_dir = Arc::new(state.game_dir.join("bundle"));
let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()))); let bundle_path = bundle_dir.join(format!("{:x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes())));
@ -590,11 +587,7 @@ fn build_deployment_data(
.map(|bundle| format!("{:x}", bundle.name().to_murmur64())) .map(|bundle| format!("{:x}", bundle.name().to_murmur64()))
.collect(), .collect(),
// TODO: // TODO:
mod_folders: mod_folders mod_folders: mod_folders.as_ref().to_vec(),
.as_ref()
.iter()
.map(|folder| folder.clone())
.collect(),
}; };
serde_sjson::to_string(&info).wrap_err("Failed to serizalize deployment data") serde_sjson::to_string(&info).wrap_err("Failed to serizalize deployment data")
} }

View file

@ -91,14 +91,14 @@ async fn patch_game_settings(state: Arc<ActionState>) -> Result<()> {
eyre::bail!("couldn't find 'boot_script' field"); eyre::bail!("couldn't find 'boot_script' field");
}; };
f.write_all(settings[0..i].as_bytes()).await?; f.write_all(&settings.as_bytes()[0..i]).await?;
f.write_all(b"boot_script = \"scripts/mod_main\"").await?; f.write_all(b"boot_script = \"scripts/mod_main\"").await?;
let Some(j) = settings[i..].find('\n') else { let Some(j) = settings[i..].find('\n') else {
eyre::bail!("couldn't find end of 'boot_script' field"); eyre::bail!("couldn't find end of 'boot_script' field");
}; };
f.write_all(settings[(i + j)..].as_bytes()).await?; f.write_all(&settings.as_bytes()[(i + j)..]).await?;
Ok(()) Ok(())
} }
@ -208,7 +208,7 @@ pub(crate) async fn reset_mod_deployment(state: ActionState) -> Result<()> {
for p in paths { for p in paths {
let path = bundle_dir.join(p); let path = bundle_dir.join(p);
let backup = bundle_dir.join(&format!("{}.bak", p)); let backup = bundle_dir.join(format!("{}.bak", p));
let res = async { let res = async {
tracing::debug!( tracing::debug!(

View file

@ -397,7 +397,7 @@ fn extract_legacy_mod<R: Read + Seek>(
tracing::trace!("Writing file '{}'", name.display()); tracing::trace!("Writing file '{}'", name.display());
let mut out = std::fs::OpenOptions::new() let mut out = std::fs::OpenOptions::new()
.write(true) .write(true)
.create(true) .truncate(true)
.open(&name) .open(&name)
.wrap_err_with(|| format!("Failed to open file '{}'", name.display()))?; .wrap_err_with(|| format!("Failed to open file '{}'", name.display()))?;

View file

@ -150,7 +150,7 @@ async fn parse_command_line_template(tmpl: &String) -> Result<CmdLine> {
String::from_utf8_unchecked(bytes.to_vec()) String::from_utf8_unchecked(bytes.to_vec())
}); });
while let Some(arg) = parsed.next() { for arg in parsed.by_ref() {
// Safety: See above. // Safety: See above.
cmd.arg(unsafe { String::from_utf8_unchecked(arg.to_vec()) }); cmd.arg(unsafe { String::from_utf8_unchecked(arg.to_vec()) });
} }

View file

@ -54,17 +54,11 @@ impl<'a> ShellParser<'a> {
} }
_ => {} _ => {}
}, },
ParserState::SingleQuote => match c { ParserState::SingleQuote => if c == b'\'' {
b'\'' => {
return Some(&self.bytes[start..(self.offset - 1)]); return Some(&self.bytes[start..(self.offset - 1)]);
}
_ => {}
}, },
ParserState::DoubleQuote => match c { ParserState::DoubleQuote => if c == b'"' {
b'"' => {
return Some(&self.bytes[start..(self.offset - 1)]); return Some(&self.bytes[start..(self.offset - 1)]);
}
_ => {}
}, },
} }
} }

View file

@ -237,7 +237,7 @@ impl Bundle {
// Ceiling division (or division toward infinity) to calculate // Ceiling division (or division toward infinity) to calculate
// the number of chunks required to fit the unpacked data. // the number of chunks required to fit the unpacked data.
let num_chunks = (unpacked_data.len() + CHUNK_SIZE - 1) / CHUNK_SIZE; let num_chunks = unpacked_data.len().div_ceil(CHUNK_SIZE);
tracing::trace!(num_chunks); tracing::trace!(num_chunks);
w.write_u32(num_chunks as u32)?; w.write_u32(num_chunks as u32)?;

View file

@ -125,7 +125,7 @@ pub fn compile(name: impl Into<IdString64>, code: impl AsRef<str>) -> Result<Bun
tracing::trace!( tracing::trace!(
"Compiling '{}', {} bytes of code", "Compiling '{}', {} bytes of code",
name.display(), name.display(),
code.as_bytes().len() code.len()
); );
let bytecode = unsafe { let bytecode = unsafe {
@ -156,10 +156,10 @@ pub fn compile(name: impl Into<IdString64>, code: impl AsRef<str>) -> Result<Bun
} }
_ => unreachable!(), _ => unreachable!(),
} }
lua::lua_setglobal(state, b"fn\0".as_ptr() as _); lua::lua_setglobal(state, c"fn".as_ptr());
let run = b"return string.dump(fn, false)\0"; let run = c"return string.dump(fn, false)";
match lua::luaL_loadstring(state, run.as_ptr() as _) as u32 { match lua::luaL_loadstring(state, run.as_ptr()) as u32 {
lua::LUA_OK => {} lua::LUA_OK => {}
lua::LUA_ERRSYNTAX => { lua::LUA_ERRSYNTAX => {
let err = lua::lua_tostring(state, -1); let err = lua::lua_tostring(state, -1);

View file

@ -28,10 +28,14 @@ impl Language {
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
pub struct Strings(HashMap<String, HashMap<Language, String>>); pub struct Strings(HashMap<String, HashMap<Language, String>>);
#[inline(always)]
fn read_string<R>(r: R) -> Result<String> fn read_string<R>(r: R) -> Result<String>
where where
R: Read, R: Read,
{ {
// We can safely ignore the warning here, as all data is already in memory, and no additional
// `BufReader` should be needed.
#[allow(clippy::unbuffered_bytes)]
r.bytes() r.bytes()
.take_while(|b| b.as_ref().map(|b| *b != 0).unwrap_or(false)) .take_while(|b| b.as_ref().map(|b| *b != 0).unwrap_or(false))
.map(|b| b.map_err(Report::new)) .map(|b| b.map_err(Report::new))
@ -41,7 +45,7 @@ where
impl Strings { impl Strings {
#[tracing::instrument(skip_all, fields(languages = variants.len()))] #[tracing::instrument(skip_all, fields(languages = variants.len()))]
pub fn from_variants(ctx: &crate::Context, variants: &Vec<BundleFileVariant>) -> Result<Self> { pub fn from_variants(ctx: &crate::Context, variants: &[BundleFileVariant]) -> Result<Self> {
let mut map: HashMap<String, HashMap<Language, String>> = HashMap::new(); let mut map: HashMap<String, HashMap<Language, String>> = HashMap::new();
for (i, variant) in variants.iter().enumerate() { for (i, variant) in variants.iter().enumerate() {
@ -76,7 +80,7 @@ impl Strings {
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub fn decompile(ctx: &crate::Context, variants: &Vec<BundleFileVariant>) -> Result<Vec<UserFile>> { pub fn decompile(ctx: &crate::Context, variants: &[BundleFileVariant]) -> Result<Vec<UserFile>> {
let strings = Strings::from_variants(ctx, variants)?; let strings = Strings::from_variants(ctx, variants)?;
let content = strings.to_sjson()?; let content = strings.to_sjson()?;