[meta] Apply clippy suggestions

This commit is contained in:
David Mak 2025-01-06 17:08:03 +08:00
parent eaaa194a87
commit 8baf111734
11 changed files with 21 additions and 21 deletions

View File

@ -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<StrRef>, 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<StrRef>, ValueEnum<'ctx>)],
generator: &mut dyn CodeGenerator,

View File

@ -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)
}))),

View File

@ -931,9 +931,9 @@ impl InnerResolver {
|_| Ok(Ok(extracted_ty)),
)
} else if unifier.unioned(extracted_ty, primitives.bool) {
if let Ok(_) = obj.extract::<bool>() {
Ok(Ok(extracted_ty))
} else if let Ok(_) = obj.call_method("__bool__", (), None)?.extract::<bool>() {
if obj.extract::<bool>().is_ok()
|| obj.call_method("__bool__", (), None)?.extract::<bool>().is_ok()
{
Ok(Ok(extracted_ty))
} else {
Ok(Err(format!("{obj} is not in the range of bool")))

View File

@ -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(

View File

@ -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 {

View File

@ -807,7 +807,7 @@ struct TypeToStringFolder<'a> {
unifier: &'a mut Unifier,
}
impl<'a> Fold<Option<Type>> for TypeToStringFolder<'a> {
impl Fold<Option<Type>> for TypeToStringFolder<'_> {
type TargetU = String;
type Error = String;
fn map_user(&mut self, user: Option<Type>) -> Result<Self::TargetU, Self::Error> {

View File

@ -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<Option<Type>>) -> Result<(), HashSet<String>> {
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!(

View File

@ -94,7 +94,7 @@ fn loc_to_str(loc: Option<Location>) -> 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());

View File

@ -187,7 +187,7 @@ fn fix_assignment_target_context(node: &mut ast::Located<ExprKind>) {
}
}
impl<'a> Fold<()> for Inferencer<'a> {
impl Fold<()> for Inferencer<'_> {
type TargetU = Option<Type>;
type Error = InferenceError;
@ -657,7 +657,7 @@ impl<'a> Fold<()> for Inferencer<'a> {
type InferenceResult = Result<Type, InferenceError>;
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> {

View File

@ -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<Self::Item> {
@ -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.

View File

@ -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<usize> {
self.symtab.iter().position(|sym| {
if let Ok(dynsym_name) = name_starting_at_slice(self.strtab, sym.st_name as usize) {