From 8baf111734c6c29504a0e1804b8f8d56600896f7 Mon Sep 17 00:00:00 2001 From: David Mak Date: Mon, 6 Jan 2025 17:08:03 +0800 Subject: [PATCH] [meta] Apply clippy suggestions --- nac3artiq/src/codegen.rs | 6 +++--- nac3artiq/src/lib.rs | 4 ++-- nac3artiq/src/symbol_resolver.rs | 6 +++--- nac3core/src/codegen/expr.rs | 2 +- nac3core/src/codegen/mod.rs | 2 +- nac3core/src/toplevel/test.rs | 2 +- nac3core/src/typecheck/function_check.rs | 4 ++-- nac3core/src/typecheck/type_error.rs | 2 +- nac3core/src/typecheck/type_inferencer/mod.rs | 4 ++-- nac3ld/src/dwarf.rs | 8 ++++---- nac3ld/src/lib.rs | 2 +- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/nac3artiq/src/codegen.rs b/nac3artiq/src/codegen.rs index 156ba23..9baa0af 100644 --- a/nac3artiq/src/codegen.rs +++ b/nac3artiq/src/codegen.rs @@ -162,7 +162,7 @@ impl<'a> ArtiqCodeGenerator<'a> { } } -impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> { +impl CodeGenerator for ArtiqCodeGenerator<'_> { fn get_name(&self) -> &str { &self.name } @@ -1505,7 +1505,7 @@ pub fn call_rtio_log_impl<'ctx>( /// Generates a call to `core_log`. pub fn gen_core_log<'ctx>( ctx: &mut CodeGenContext<'ctx, '_>, - obj: &Option<(Type, ValueEnum<'ctx>)>, + obj: Option<&(Type, ValueEnum<'ctx>)>, fun: (&FunSignature, DefinitionId), args: &[(Option, ValueEnum<'ctx>)], generator: &mut dyn CodeGenerator, @@ -1522,7 +1522,7 @@ pub fn gen_core_log<'ctx>( /// Generates a call to `rtio_log`. pub fn gen_rtio_log<'ctx>( ctx: &mut CodeGenContext<'ctx, '_>, - obj: &Option<(Type, ValueEnum<'ctx>)>, + obj: Option<&(Type, ValueEnum<'ctx>)>, fun: (&FunSignature, DefinitionId), args: &[(Option, ValueEnum<'ctx>)], generator: &mut dyn CodeGenerator, diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index ca2f2f1..1601d4a 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -330,7 +330,7 @@ impl Nac3 { vars: into_var_map([arg_ty]), }, Arc::new(GenCall::new(Box::new(move |ctx, obj, fun, args, generator| { - gen_core_log(ctx, &obj, fun, &args, generator)?; + gen_core_log(ctx, obj.as_ref(), fun, &args, generator)?; Ok(None) }))), @@ -360,7 +360,7 @@ impl Nac3 { vars: into_var_map([arg_ty]), }, Arc::new(GenCall::new(Box::new(move |ctx, obj, fun, args, generator| { - gen_rtio_log(ctx, &obj, fun, &args, generator)?; + gen_rtio_log(ctx, obj.as_ref(), fun, &args, generator)?; Ok(None) }))), diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 232cd08..1e99ac2 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -931,9 +931,9 @@ impl InnerResolver { |_| Ok(Ok(extracted_ty)), ) } else if unifier.unioned(extracted_ty, primitives.bool) { - if let Ok(_) = obj.extract::() { - Ok(Ok(extracted_ty)) - } else if let Ok(_) = obj.call_method("__bool__", (), None)?.extract::() { + if obj.extract::().is_ok() + || obj.call_method("__bool__", (), None)?.extract::().is_ok() + { Ok(Ok(extracted_ty)) } else { Ok(Err(format!("{obj} is not in the range of bool"))) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 4b83e63..e74e7ad 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -79,7 +79,7 @@ pub fn get_subst_key( .join(", ") } -impl<'ctx, 'a> CodeGenContext<'ctx, 'a> { +impl<'ctx> CodeGenContext<'ctx, '_> { /// Builds a sequence of `getelementptr` and `load` instructions which stores the value of a /// struct field into an LLVM value. pub fn build_gep_and_load( diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index 4e83d53..e74071b 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -228,7 +228,7 @@ pub struct CodeGenContext<'ctx, 'a> { pub current_loc: Location, } -impl<'ctx, 'a> CodeGenContext<'ctx, 'a> { +impl CodeGenContext<'_, '_> { /// Whether the [current basic block][Builder::get_insert_block] referenced by `builder` /// contains a [terminator statement][BasicBlock::get_terminator]. pub fn is_terminated(&self) -> bool { diff --git a/nac3core/src/toplevel/test.rs b/nac3core/src/toplevel/test.rs index 1f33a4b..6a83632 100644 --- a/nac3core/src/toplevel/test.rs +++ b/nac3core/src/toplevel/test.rs @@ -807,7 +807,7 @@ struct TypeToStringFolder<'a> { unifier: &'a mut Unifier, } -impl<'a> Fold> for TypeToStringFolder<'a> { +impl Fold> for TypeToStringFolder<'_> { type TargetU = String; type Error = String; fn map_user(&mut self, user: Option) -> Result { diff --git a/nac3core/src/typecheck/function_check.rs b/nac3core/src/typecheck/function_check.rs index ed801a1..2e655d1 100644 --- a/nac3core/src/typecheck/function_check.rs +++ b/nac3core/src/typecheck/function_check.rs @@ -15,7 +15,7 @@ use super::{ }; use crate::toplevel::helper::PrimDef; -impl<'a> Inferencer<'a> { +impl Inferencer<'_> { fn should_have_value(&mut self, expr: &Expr>) -> Result<(), HashSet> { if matches!(expr.custom, Some(ty) if self.unifier.unioned(ty, self.primitives.none)) { Err(HashSet::from([format!("Error at {}: cannot have value none", expr.location)])) @@ -94,7 +94,7 @@ impl<'a> Inferencer<'a> { // there are some cases where the custom field is None if let Some(ty) = &expr.custom { if !matches!(&expr.node, ExprKind::Constant { value: Constant::Ellipsis, .. }) - && !ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::List.id()) + && ty.obj_id(self.unifier).is_none_or(|id| id != PrimDef::List.id()) && !self.unifier.is_concrete(*ty, &self.function_data.bound_variables) { return Err(HashSet::from([format!( diff --git a/nac3core/src/typecheck/type_error.rs b/nac3core/src/typecheck/type_error.rs index 3cf5bdc..b144f8a 100644 --- a/nac3core/src/typecheck/type_error.rs +++ b/nac3core/src/typecheck/type_error.rs @@ -94,7 +94,7 @@ fn loc_to_str(loc: Option) -> String { } } -impl<'a> Display for DisplayTypeError<'a> { +impl Display for DisplayTypeError<'_> { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { use TypeErrorKind::*; let mut notes = Some(HashMap::new()); diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index 8769211..742fa19 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -187,7 +187,7 @@ fn fix_assignment_target_context(node: &mut ast::Located) { } } -impl<'a> Fold<()> for Inferencer<'a> { +impl Fold<()> for Inferencer<'_> { type TargetU = Option; type Error = InferenceError; @@ -657,7 +657,7 @@ impl<'a> Fold<()> for Inferencer<'a> { type InferenceResult = Result; -impl<'a> Inferencer<'a> { +impl Inferencer<'_> { /// Constrain a <: b /// Currently implemented as unification fn constrain(&mut self, a: Type, b: Type, location: &Location) -> Result<(), InferenceError> { diff --git a/nac3ld/src/dwarf.rs b/nac3ld/src/dwarf.rs index e85a4e4..4bcccd3 100644 --- a/nac3ld/src/dwarf.rs +++ b/nac3ld/src/dwarf.rs @@ -30,7 +30,7 @@ pub struct DwarfReader<'a> { pub virt_addr: u32, } -impl<'a> DwarfReader<'a> { +impl DwarfReader<'_> { pub fn new(slice: &[u8], virt_addr: u32) -> DwarfReader { DwarfReader { slice, virt_addr } } @@ -113,7 +113,7 @@ pub struct DwarfWriter<'a> { pub offset: usize, } -impl<'a> DwarfWriter<'a> { +impl DwarfWriter<'_> { pub fn new(slice: &mut [u8]) -> DwarfWriter { DwarfWriter { slice, offset: 0 } } @@ -375,7 +375,7 @@ pub struct FDE_Records<'a> { available: usize, } -impl<'a> Iterator for FDE_Records<'a> { +impl Iterator for FDE_Records<'_> { type Item = (u32, u32); fn next(&mut self) -> Option { @@ -423,7 +423,7 @@ pub struct EH_Frame_Hdr<'a> { fdes: Vec<(u32, u32)>, } -impl<'a> EH_Frame_Hdr<'a> { +impl EH_Frame_Hdr<'_> { /// Create a [EH_Frame_Hdr] object, and write out the fixed fields of `.eh_frame_hdr` to memory. /// /// Load address is not known at this point. diff --git a/nac3ld/src/lib.rs b/nac3ld/src/lib.rs index 73e065d..8ef8653 100644 --- a/nac3ld/src/lib.rs +++ b/nac3ld/src/lib.rs @@ -159,7 +159,7 @@ struct SymbolTableReader<'a> { strtab: &'a [u8], } -impl<'a> SymbolTableReader<'a> { +impl SymbolTableReader<'_> { pub fn find_index_by_name(&self, sym_name: &[u8]) -> Option { self.symtab.iter().position(|sym| { if let Ok(dynsym_name) = name_starting_at_slice(self.strtab, sym.st_name as usize) {