From ed1aea41f31776568aef509157dbb5708b855e3f Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 7 Oct 2024 21:49:18 -0700 Subject: [PATCH] clean up some clippy warnings --- .../fayalite-proc-macros-impl/src/hdl_bundle.rs | 3 +-- crates/fayalite-proc-macros-impl/src/hdl_enum.rs | 2 +- .../src/hdl_type_common.rs | 6 +++--- crates/fayalite/src/bundle.rs | 10 +++++++++- crates/fayalite/src/enum_.rs | 9 +++++++-- crates/fayalite/src/int.rs | 4 ++-- crates/fayalite/src/memory.rs | 4 ++-- crates/fayalite/src/module.rs | 15 ++++++++------- .../src/module/transform/simplify_enums.rs | 11 ++++------- .../src/module/transform/simplify_memories.rs | 2 +- crates/fayalite/src/util/scoped_ref.rs | 6 ++++++ crates/fayalite/tests/module.rs | 2 +- 12 files changed, 45 insertions(+), 29 deletions(-) diff --git a/crates/fayalite-proc-macros-impl/src/hdl_bundle.rs b/crates/fayalite-proc-macros-impl/src/hdl_bundle.rs index b13aa08..cf08c7e 100644 --- a/crates/fayalite-proc-macros-impl/src/hdl_bundle.rs +++ b/crates/fayalite-proc-macros-impl/src/hdl_bundle.rs @@ -58,8 +58,7 @@ impl ParsedBundle { } *mutability = FieldMutability::None; colon_token.get_or_insert(Token![:](ident.span())); - let options = errors.unwrap_or_default(HdlAttr::parse_and_take_attr(attrs)); - options + errors.unwrap_or_default(HdlAttr::parse_and_take_attr(attrs)) } fn parse(item: ItemStruct) -> syn::Result { let ItemStruct { diff --git a/crates/fayalite-proc-macros-impl/src/hdl_enum.rs b/crates/fayalite-proc-macros-impl/src/hdl_enum.rs index adddd74..1d16177 100644 --- a/crates/fayalite-proc-macros-impl/src/hdl_enum.rs +++ b/crates/fayalite-proc-macros-impl/src/hdl_enum.rs @@ -600,7 +600,7 @@ impl ToTokens for ParsedEnum { static_generics.split_for_impl(); let static_type_body_variants = Vec::from_iter(variants.iter().map(|ParsedVariant { ident, field, .. }| { - if let Some(_) = field { + if field.is_some() { quote_spanned! {span=> #ident: ::fayalite::ty::StaticType::TYPE, } diff --git a/crates/fayalite-proc-macros-impl/src/hdl_type_common.rs b/crates/fayalite-proc-macros-impl/src/hdl_type_common.rs index 239f32b..e36f68e 100644 --- a/crates/fayalite-proc-macros-impl/src/hdl_type_common.rs +++ b/crates/fayalite-proc-macros-impl/src/hdl_type_common.rs @@ -1410,7 +1410,7 @@ impl ParseTypes for ParsedType { let mut args = None; let segments = Punctuated::from_iter(segments.pairs_mut().map_pair_value_mut(|segment| { let PathSegment { ident, arguments } = segment; - if let Some(_) = args { + if args.is_some() { parser .errors() .error(&ident, "associated types/consts are not yet implemented"); @@ -1594,7 +1594,7 @@ impl ParseTypes for ParsedConstGenericType { let mut args = None; let segments = Punctuated::from_iter(segments.pairs_mut().map_pair_value_mut(|segment| { let PathSegment { ident, arguments } = segment; - if let Some(_) = args { + if args.is_some() { parser .errors() .error(&ident, "associated types/consts are not yet implemented"); @@ -3554,7 +3554,7 @@ impl SplitForImpl for Generics { Self::TypeGenerics<'_>, Self::WhereClause<'_>, ) { - Generics::split_for_impl(&self) + Generics::split_for_impl(self) } } diff --git a/crates/fayalite/src/bundle.rs b/crates/fayalite/src/bundle.rs index 199c2b2..b338322 100644 --- a/crates/fayalite/src/bundle.rs +++ b/crates/fayalite/src/bundle.rs @@ -144,6 +144,12 @@ impl BundleTypePropertiesBuilder { } } +impl Default for BundleTypePropertiesBuilder { + fn default() -> Self { + Self::new() + } +} + impl Bundle { #[track_caller] pub fn new(fields: Interned<[BundleField]>) -> Self { @@ -342,6 +348,7 @@ macro_rules! impl_tuples { std::iter::once(MatchVariantWithoutScope(($(Expr::field(this, stringify!($num)),)*))) } fn mask_type(&self) -> Self::MaskType { + #![allow(clippy::unused_unit)] let ($($var,)*) = self; ($($var.mask_type(),)*) } @@ -350,6 +357,7 @@ macro_rules! impl_tuples { } #[track_caller] fn from_canonical(canonical_type: CanonicalType) -> Self { + #![allow(clippy::unused_unit)] let CanonicalType::Bundle(bundle) = canonical_type else { panic!("expected bundle"); }; @@ -358,7 +366,7 @@ macro_rules! impl_tuples { }; $(let BundleField { name, flipped, ty } = $var; assert_eq!(&*name, stringify!($num)); - assert_eq!(flipped, false); + assert!(!flipped); let $var = $T::from_canonical(ty);)* ($($var,)*) } diff --git a/crates/fayalite/src/enum_.rs b/crates/fayalite/src/enum_.rs index 13724ef..2ed0b8e 100644 --- a/crates/fayalite/src/enum_.rs +++ b/crates/fayalite/src/enum_.rs @@ -169,6 +169,12 @@ impl EnumTypePropertiesBuilder { } } +impl Default for EnumTypePropertiesBuilder { + fn default() -> Self { + Self::new() + } +} + impl Enum { #[track_caller] pub fn new(variants: Interned<[EnumVariant]>) -> Self { @@ -399,9 +405,8 @@ impl HdlOption { else { unreachable!(); }; - let value = f(value).map_err(|e| { + let value = f(value).inspect_err(|_| { and_then_out.complete(()); // avoid error - e })?; let and_then_out = and_then_out.complete(Expr::ty(value)); connect(and_then_out, value); diff --git a/crates/fayalite/src/int.rs b/crates/fayalite/src/int.rs index f529198..dd631d0 100644 --- a/crates/fayalite/src/int.rs +++ b/crates/fayalite/src/int.rs @@ -147,7 +147,7 @@ where fn try_from_usize(v: usize) -> Option { if v == VALUE { - Some(Self::SizeType::default()) + Some(ConstUsize) } else { None } @@ -560,7 +560,7 @@ pub trait BoolOrIntType: Type + sealed::BoolOrIntTypeSealed { } fn bits_to_expr(bits: Cow<'_, BitSlice>) -> Expr; fn le_bytes_to_expr_wrapping(bytes: &[u8], bit_width: usize) -> Expr { - let bitslice = BitSlice::::from_slice(&bytes); + let bitslice = BitSlice::::from_slice(bytes); let bitslice = &bitslice[..bit_width.min(bitslice.len())]; let mut bits = BitVec::new(); bits.extend_from_bitslice(bitslice); diff --git a/crates/fayalite/src/memory.rs b/crates/fayalite/src/memory.rs index 1762f57..f583a8c 100644 --- a/crates/fayalite/src/memory.rs +++ b/crates/fayalite/src/memory.rs @@ -634,7 +634,7 @@ impl Mem { self.0.source_location } pub fn array_type(self) -> ArrayType { - self.0.array_type.clone() + self.0.array_type } pub fn initial_value(self) -> Option> { self.0.initial_value @@ -987,7 +987,7 @@ impl MemBuilder { #[allow(clippy::result_unit_err)] pub fn get_array_type(&self) -> Result, ()> { Ok(ArrayType::new( - self.mem_element_type.clone(), + self.mem_element_type, Len::from_usize(self.get_depth()?), )) } diff --git a/crates/fayalite/src/module.rs b/crates/fayalite/src/module.rs index 2ba3800..7d6949c 100644 --- a/crates/fayalite/src/module.rs +++ b/crates/fayalite/src/module.rs @@ -607,6 +607,10 @@ impl BlockStack { pub struct Id(NonZeroU64); impl Id { + #[allow( + clippy::new_without_default, + reason = "returns a different value each time, so there isn't really a default value" + )] pub fn new() -> Self { static NEXT_ID: AtomicU64 = AtomicU64::new(1); Self( @@ -945,7 +949,7 @@ impl From> for NormalModuleBody { Stmt::Declaration(decl) => { let annotations = annotations_map .remove(&decl) - .map(|v| Intern::intern_owned(v)) + .map(Intern::intern_owned) .unwrap_or_default(); match decl { StmtDeclaration::Wire(StmtWire { @@ -1615,10 +1619,7 @@ impl AssertValidityState { let module = self.module; if block == 0 { for module_io in &*module.module_io { - self.insert_new_base( - TargetBase::intern_sized(module_io.module_io.clone().into()), - block, - ); + self.insert_new_base(TargetBase::intern_sized(module_io.module_io.into()), block); } } let Block { memories, stmts } = self.blocks[block]; @@ -1934,7 +1935,7 @@ impl ModuleBuilder { let module_io = module_io.canonical(); let mut impl_ = self.impl_.borrow_mut(); let impl_ = &mut *impl_; - impl_.io_indexes.insert(module_io.clone(), impl_.io.len()); + impl_.io_indexes.insert(module_io, impl_.io.len()); impl_.io.push(AnnotatedModuleIO { annotations: vec![], module_io, @@ -2478,7 +2479,7 @@ pub fn memory_array_with_loc( mem_array_type: ArrayType, source_location: SourceLocation, ) -> MemBuilder { - let mut retval = memory_impl(name, mem_array_type.element().clone(), source_location); + let mut retval = memory_impl(name, mem_array_type.element(), source_location); retval.depth(mem_array_type.len()); retval } diff --git a/crates/fayalite/src/module/transform/simplify_enums.rs b/crates/fayalite/src/module/transform/simplify_enums.rs index f398006..bb57cf0 100644 --- a/crates/fayalite/src/module/transform/simplify_enums.rs +++ b/crates/fayalite/src/module/transform/simplify_enums.rs @@ -271,12 +271,12 @@ impl State { .into()), EnumTypeState::TagUIntAndBody(_) => { let int_tag_expr = Expr::>::from_canonical(folded_expr).tag; - Ok(match_int_tag(int_tag_expr, source_location, &folded_blocks).into()) + Ok(match_int_tag(int_tag_expr, source_location, folded_blocks).into()) } EnumTypeState::UInt(_) => { let int_tag_expr = Expr::::from_canonical(folded_expr) [..unfolded_enum_type.discriminant_bit_width()]; - Ok(match_int_tag(int_tag_expr, source_location, &folded_blocks).into()) + Ok(match_int_tag(int_tag_expr, source_location, folded_blocks).into()) } EnumTypeState::Unchanged => Ok(StmtMatch { expr: Expr::from_canonical(folded_expr), @@ -929,13 +929,10 @@ impl Folder for State { unreachable!() } - fn fold_enum_literal( + fn fold_enum_literal>( &mut self, _v: ops::EnumLiteral, - ) -> Result, Self::Error> - where - T: Fold, - { + ) -> Result, Self::Error> { unreachable!() } diff --git a/crates/fayalite/src/module/transform/simplify_memories.rs b/crates/fayalite/src/module/transform/simplify_memories.rs index 71e459c..e8f9cbf 100644 --- a/crates/fayalite/src/module/transform/simplify_memories.rs +++ b/crates/fayalite/src/module/transform/simplify_memories.rs @@ -766,7 +766,7 @@ impl ModuleState { output_stmts.push( StmtWire { annotations: Default::default(), - wire: canonical_wire.clone(), + wire: canonical_wire, } .into(), ); diff --git a/crates/fayalite/src/util/scoped_ref.rs b/crates/fayalite/src/util/scoped_ref.rs index 7705377..27f2f89 100644 --- a/crates/fayalite/src/util/scoped_ref.rs +++ b/crates/fayalite/src/util/scoped_ref.rs @@ -106,3 +106,9 @@ impl ScopedRef { self.0.with_opt(f) } } + +impl Default for ScopedRef { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/fayalite/tests/module.rs b/crates/fayalite/tests/module.rs index b0b1fb6..222f7ba 100644 --- a/crates/fayalite/tests/module.rs +++ b/crates/fayalite/tests/module.rs @@ -2258,7 +2258,7 @@ pub fn check_memory_of_bundle() { let wmask: (Bool, Bool) = m.input(); #[hdl] let clk: Clock = m.input(); - let mem_init = Vec::from_iter((0..0x10u8).map(|i| (i ^ 3, (i ^ i / 2).cast_to_static()))); + let mem_init = Vec::from_iter((0..0x10u8).map(|i| (i ^ 3, (i ^ (i / 2)).cast_to_static()))); #[hdl] let mut mem = memory_with_init(mem_init); let read_port = mem.new_read_port();