From 74e819c678ead4fab618805fa9e1fdb3c312b8ae Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Thu, 17 Jul 2025 16:34:18 +0800 Subject: [PATCH] chore: cargo clippy --- src/env.rs | 6 ++++++ src/eval/jit/compile.rs | 5 ++--- src/eval/jit/helpers.rs | 4 ++-- src/eval/jit/mod.rs | 10 ++++++++-- src/eval/mod.rs | 22 +++++++++++----------- src/ir/ctx.rs | 6 ++++++ src/ir/mod.rs | 31 ++++++++++++++----------------- src/ir/utils.rs | 14 +++++++------- src/ty/internal/list.rs | 2 +- 9 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/env.rs b/src/env.rs index 8447ecb..db65d7f 100644 --- a/src/env.rs +++ b/src/env.rs @@ -13,6 +13,12 @@ pub struct Env { args: Vec, } +impl Default for Env { + fn default() -> Self { + Self::new() + } +} + impl Env { pub fn new() -> Self { Self { diff --git a/src/eval/jit/compile.rs b/src/eval/jit/compile.rs index 7538f9d..865d1d5 100644 --- a/src/eval/jit/compile.rs +++ b/src/eval/jit/compile.rs @@ -1,7 +1,6 @@ -use cranelift::codegen::ir::{self, BlockCall, StackSlot, ValueListPool}; +use cranelift::codegen::ir::{self, StackSlot}; use cranelift::prelude::*; -use crate::eval::Evaluate; use crate::ir::*; use crate::ty::common as c; use crate::ty::internal::Value; @@ -493,7 +492,7 @@ impl JITCompile for Const { } Int(x) => { let tag = ctx.builder.ins().iconst(types::I64, Value::INT as i64); - let val = ctx.builder.ins().iconst(types::I64, x as i64); + let val = ctx.builder.ins().iconst(types::I64, x); ctx.builder.ins().stack_store(tag, slot, 0); ctx.builder.ins().stack_store(val, slot, 8); } diff --git a/src/eval/jit/helpers.rs b/src/eval/jit/helpers.rs index fa3e427..8a2357d 100644 --- a/src/eval/jit/helpers.rs +++ b/src/eval/jit/helpers.rs @@ -21,12 +21,12 @@ pub extern "C" fn helper_call( // TODO: Error Handling let args = core::ptr::slice_from_raw_parts_mut(args_ptr, args_len); let args = unsafe { Box::from_raw(args) }; - func.call(args.into_iter().map(Value::from).collect(), engine, env) + func.call(args.into_iter().collect(), engine, env) .unwrap(); } pub extern "C" fn helper_lookup_arg(env: &Env, level: usize, ret: &mut MaybeUninit) { - ret.write(env.lookup_arg(level as usize)); + ret.write(env.lookup_arg(level)); } pub extern "C" fn helper_lookup( diff --git a/src/eval/jit/mod.rs b/src/eval/jit/mod.rs index 5f6719b..ea1f68b 100644 --- a/src/eval/jit/mod.rs +++ b/src/eval/jit/mod.rs @@ -348,13 +348,19 @@ pub struct JITCompiler { dbg: FuncId, } +impl Default for JITCompiler { + fn default() -> Self { + Self::new() + } +} + impl JITCompiler { pub fn new() -> Self { let mut flag_builder = settings::builder(); flag_builder.set("use_colocated_libcalls", "false").unwrap(); flag_builder.set("is_pic", "false").unwrap(); let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| { - panic!("host machine is not supported: {}", msg); + panic!("host machine is not supported: {msg}"); }); let isa = isa_builder .finish(settings::Flags::new(flag_builder)) @@ -650,7 +656,7 @@ impl JITCompiler { let strings = ctx.strings; if cfg!(debug_assertions) { - println!("{:?}", ir); + println!("{ir:?}"); println!("{}", func.display()); } self.ctx.func = func; diff --git a/src/eval/mod.rs b/src/eval/mod.rs index d80b30a..c4bc551 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -42,8 +42,8 @@ impl Evaluate for ir::List { .items .iter() .map(|val| { - let eval_result = val.eval(engine, env); - eval_result + + val.eval(engine, env) }) .collect::>>()?; let result = Value::List(List::from(items)).ok(); @@ -186,12 +186,12 @@ impl Evaluate for ir::If { let mut cond = self.cond.eval(engine, env)?; cond.force(engine, env)?; let cond = cond.unwrap_bool(); - let result = if cond { + + if cond { self.consq.eval(engine, env) } else { self.alter.eval(engine, env) - }; - result + } } } @@ -284,13 +284,13 @@ impl Evaluate for ir::Const { impl Evaluate for ir::Var { fn eval(&self, _: &mut Engine, env: &mut Env) -> Result { - let result = env.lookup_with(&self.sym).ok_or_else(|| { + + env.lookup_with(&self.sym).ok_or_else(|| { Error::EvalError(format!( "variable {} not found", Symbol::from(self.sym.clone()) )) - }); - result + }) } } @@ -315,12 +315,12 @@ impl Evaluate for ir::Thunk { impl Evaluate for ir::MaybeThunk { fn eval(&self, engine: &mut Engine, env: &mut Env) -> Result { - let result = match self { + + match self { ir::MaybeThunk::Const(cnst) => cnst.eval(engine, env), ir::MaybeThunk::String(string) => string.eval(engine, env), ir::MaybeThunk::Thunk(thunk) => thunk.eval(engine, env), - }; - result + } } } diff --git a/src/ir/ctx.rs b/src/ir/ctx.rs index 5479018..37490cc 100644 --- a/src/ir/ctx.rs +++ b/src/ir/ctx.rs @@ -136,6 +136,12 @@ impl<'a, 'env> Env<'a, 'env> { } } +impl Default for DowngradeContext { + fn default() -> Self { + Self::new() + } +} + impl DowngradeContext { pub fn new() -> Self { DowngradeContext { diff --git a/src/ir/mod.rs b/src/ir/mod.rs index 01c1836..fe1a998 100644 --- a/src/ir/mod.rs +++ b/src/ir/mod.rs @@ -200,7 +200,6 @@ impl Attrs { mut path: impl Iterator, name: Attr, value: Ir, - ctx: &mut DowngradeContext, ) -> Result<()> { if let Some(attr) = path.next() { match attr { @@ -222,13 +221,13 @@ impl Attrs { Symbol::from(ident) )) }) - .and_then(|attrs: &mut Attrs| attrs._insert(path, name, value, ctx)), + .and_then(|attrs: &mut Attrs| attrs._insert(path, name, value)), Attr::Strs(string) => { let mut attrs = Attrs { stcs: HashMap::new(), dyns: Vec::new(), }; - attrs._insert(path, name, value, ctx)?; + attrs._insert(path, name, value)?; self.dyns.push(DynAttr(string.ir(), attrs.ir())); Ok(()) } @@ -237,7 +236,7 @@ impl Attrs { stcs: HashMap::new(), dyns: Vec::new(), }; - attrs._insert(path, name, value, ctx)?; + attrs._insert(path, name, value)?; self.dyns.push(DynAttr(dynamic, attrs.ir())); Ok(()) } @@ -263,10 +262,10 @@ impl Attrs { } } - pub fn insert(&mut self, path: Vec, value: Ir, ctx: &mut DowngradeContext) -> Result<()> { + pub fn insert(&mut self, path: Vec, value: Ir) -> Result<()> { let mut path = path.into_iter(); let name = path.next_back().unwrap(); - self._insert(path, name, value, ctx) + self._insert(path, name, value) } fn _has_attr(&self, mut path: std::slice::Iter, name: Attr) -> Option { @@ -310,7 +309,7 @@ impl Attrs { .map(|res| Some(res.clone())) .map_or_else( || { - if self.dyns.len() > 0 { + if !self.dyns.is_empty() { Ok(None) } else { Err(Error::DowngradeError(format!( @@ -556,7 +555,7 @@ impl Downgrade for ast::Path { .parts() .map(|part| match part { ast::InterpolPart::Literal(lit) => Str { - val: lit.to_string().into(), + val: lit.to_string(), } .ir() .ok(), @@ -600,7 +599,7 @@ impl Downgrade for ast::Str { .normalized_parts() .into_iter() .map(|part| match part { - ast::InterpolPart::Literal(lit) => Str { val: lit.into() }.ir().ok(), + ast::InterpolPart::Literal(lit) => Str { val: lit }.ir().ok(), ast::InterpolPart::Interpolation(interpol) => { interpol.expr().unwrap().downgrade(ctx) } @@ -639,7 +638,7 @@ impl Downgrade for ast::Literal { ast::LiteralKind::Integer(int) => Const::from(int.value().unwrap()).ir(), ast::LiteralKind::Float(float) => Const::from(float.value().unwrap()).ir(), ast::LiteralKind::Uri(uri) => Str { - val: uri.to_string().into(), + val: uri.to_string(), } .ir(), } @@ -671,7 +670,7 @@ impl Str { impl Downgrade for ast::Ident { fn downgrade(self, _: &mut DowngradeContext) -> Result { - let sym = self.ident_token().unwrap().to_string().into(); + let sym = self.ident_token().unwrap().to_string(); Var { sym }.ir().ok() } } @@ -1061,14 +1060,12 @@ impl Let { env: &Env<'a, 'env>, ) -> Result { let map = self.bindings.clone(); - let mut env = env.enter_let(&map); + let env = env.enter_let(&map); self.bindings - .into_iter() - .map(|(_, ir)| { - ir.resolve(self_idx, ctx, &mut env)?; + .into_iter().try_for_each(|(_, ir)| { + ir.resolve(self_idx, ctx, &env)?; Ok(()) - }) - .collect::>()?; + })?; self.expr.resolve(self_idx, ctx, &env)?.ok() } } diff --git a/src/ir/utils.rs b/src/ir/utils.rs index 742ed8a..3303251 100644 --- a/src/ir/utils.rs +++ b/src/ir/utils.rs @@ -4,7 +4,7 @@ use super::*; pub fn downgrade_param(param: ast::Param, ctx: &mut DowngradeContext) -> Result { match param { - ast::Param::IdentParam(ident) => Ok(Param::Ident(ident.to_string().into())), + ast::Param::IdentParam(ident) => Ok(Param::Ident(ident.to_string())), ast::Param::Pattern(pattern) => downgrade_pattern(pattern, ctx), } } @@ -13,7 +13,7 @@ pub fn downgrade_pattern(pattern: ast::Pattern, ctx: &mut DowngradeContext) -> R let formals = pattern .pat_entries() .map(|entry| { - let ident = entry.ident().unwrap().to_string().into(); + let ident = entry.ident().unwrap().to_string(); if entry.default().is_none() { Ok((ident, None)) } else { @@ -28,7 +28,7 @@ pub fn downgrade_pattern(pattern: ast::Pattern, ctx: &mut DowngradeContext) -> R let ellipsis = pattern.ellipsis_token().is_some(); let alias = pattern .pat_bind() - .map(|alias| alias.ident().unwrap().to_string().into()); + .map(|alias| alias.ident().unwrap().to_string()); Ok(Param::Formals { formals, ellipsis, @@ -94,14 +94,14 @@ pub fn downgrade_attr(attr: ast::Attr, ctx: &mut DowngradeContext) -> Result Ok(Attr::Str(ident.to_string().into())), + Ident(ident) => Ok(Attr::Str(ident.to_string())), Str(string) => { let parts = string.normalized_parts(); if parts.is_empty() { Ok(Attr::Str("".into())) } else if parts.len() == 1 { match parts.into_iter().next().unwrap() { - Literal(ident) => Ok(Attr::Str(ident.into())), + Literal(ident) => Ok(Attr::Str(ident)), Interpolation(interpol) => { Ok(Attr::Dynamic(interpol.expr().unwrap().downgrade(ctx)?)) } @@ -110,7 +110,7 @@ pub fn downgrade_attr(attr: ast::Attr, ctx: &mut DowngradeContext) -> Result self::Str { val: lit.into() }.ir().ok(), + Literal(lit) => self::Str { val: lit }.ir().ok(), Interpolation(interpol) => interpol.expr().unwrap().downgrade(ctx), }) .collect::>>()?; @@ -142,5 +142,5 @@ pub fn downgrade_attrpathvalue( x @ Ir::Const(_) => x, x => ctx.new_thunk(x).ir(), }; - attrs.insert(path, value, ctx) + attrs.insert(path, value) } diff --git a/src/ty/internal/list.rs b/src/ty/internal/list.rs index 6e986b7..08e568a 100644 --- a/src/ty/internal/list.rs +++ b/src/ty/internal/list.rs @@ -19,7 +19,7 @@ impl Default for List { } } -impl<'gc, T: Into>> From for List { +impl>> From for List { fn from(value: T) -> Self { Self { data: value.into() } }