clean up some clippy warnings
Some checks failed
/ test (push) Failing after 3m41s

This commit is contained in:
Jacob Lifshay 2024-10-07 21:49:18 -07:00
parent f12322aa2a
commit ed1aea41f3
Signed by: programmerjake
SSH key fingerprint: SHA256:B1iRVvUJkvd7upMIiMqn6OyxvD2SgJkAH3ZnUOj6z+c
12 changed files with 45 additions and 29 deletions

View file

@ -58,8 +58,7 @@ impl ParsedBundle {
} }
*mutability = FieldMutability::None; *mutability = FieldMutability::None;
colon_token.get_or_insert(Token![:](ident.span())); colon_token.get_or_insert(Token![:](ident.span()));
let options = errors.unwrap_or_default(HdlAttr::parse_and_take_attr(attrs)); errors.unwrap_or_default(HdlAttr::parse_and_take_attr(attrs))
options
} }
fn parse(item: ItemStruct) -> syn::Result<Self> { fn parse(item: ItemStruct) -> syn::Result<Self> {
let ItemStruct { let ItemStruct {

View file

@ -600,7 +600,7 @@ impl ToTokens for ParsedEnum {
static_generics.split_for_impl(); static_generics.split_for_impl();
let static_type_body_variants = let static_type_body_variants =
Vec::from_iter(variants.iter().map(|ParsedVariant { ident, field, .. }| { Vec::from_iter(variants.iter().map(|ParsedVariant { ident, field, .. }| {
if let Some(_) = field { if field.is_some() {
quote_spanned! {span=> quote_spanned! {span=>
#ident: ::fayalite::ty::StaticType::TYPE, #ident: ::fayalite::ty::StaticType::TYPE,
} }

View file

@ -1410,7 +1410,7 @@ impl ParseTypes<Path> for ParsedType {
let mut args = None; let mut args = None;
let segments = Punctuated::from_iter(segments.pairs_mut().map_pair_value_mut(|segment| { let segments = Punctuated::from_iter(segments.pairs_mut().map_pair_value_mut(|segment| {
let PathSegment { ident, arguments } = segment; let PathSegment { ident, arguments } = segment;
if let Some(_) = args { if args.is_some() {
parser parser
.errors() .errors()
.error(&ident, "associated types/consts are not yet implemented"); .error(&ident, "associated types/consts are not yet implemented");
@ -1594,7 +1594,7 @@ impl ParseTypes<Path> for ParsedConstGenericType {
let mut args = None; let mut args = None;
let segments = Punctuated::from_iter(segments.pairs_mut().map_pair_value_mut(|segment| { let segments = Punctuated::from_iter(segments.pairs_mut().map_pair_value_mut(|segment| {
let PathSegment { ident, arguments } = segment; let PathSegment { ident, arguments } = segment;
if let Some(_) = args { if args.is_some() {
parser parser
.errors() .errors()
.error(&ident, "associated types/consts are not yet implemented"); .error(&ident, "associated types/consts are not yet implemented");
@ -3554,7 +3554,7 @@ impl SplitForImpl for Generics {
Self::TypeGenerics<'_>, Self::TypeGenerics<'_>,
Self::WhereClause<'_>, Self::WhereClause<'_>,
) { ) {
Generics::split_for_impl(&self) Generics::split_for_impl(self)
} }
} }

View file

@ -144,6 +144,12 @@ impl BundleTypePropertiesBuilder {
} }
} }
impl Default for BundleTypePropertiesBuilder {
fn default() -> Self {
Self::new()
}
}
impl Bundle { impl Bundle {
#[track_caller] #[track_caller]
pub fn new(fields: Interned<[BundleField]>) -> Self { pub fn new(fields: Interned<[BundleField]>) -> Self {
@ -342,6 +348,7 @@ macro_rules! impl_tuples {
std::iter::once(MatchVariantWithoutScope(($(Expr::field(this, stringify!($num)),)*))) std::iter::once(MatchVariantWithoutScope(($(Expr::field(this, stringify!($num)),)*)))
} }
fn mask_type(&self) -> Self::MaskType { fn mask_type(&self) -> Self::MaskType {
#![allow(clippy::unused_unit)]
let ($($var,)*) = self; let ($($var,)*) = self;
($($var.mask_type(),)*) ($($var.mask_type(),)*)
} }
@ -350,6 +357,7 @@ macro_rules! impl_tuples {
} }
#[track_caller] #[track_caller]
fn from_canonical(canonical_type: CanonicalType) -> Self { fn from_canonical(canonical_type: CanonicalType) -> Self {
#![allow(clippy::unused_unit)]
let CanonicalType::Bundle(bundle) = canonical_type else { let CanonicalType::Bundle(bundle) = canonical_type else {
panic!("expected bundle"); panic!("expected bundle");
}; };
@ -358,7 +366,7 @@ macro_rules! impl_tuples {
}; };
$(let BundleField { name, flipped, ty } = $var; $(let BundleField { name, flipped, ty } = $var;
assert_eq!(&*name, stringify!($num)); assert_eq!(&*name, stringify!($num));
assert_eq!(flipped, false); assert!(!flipped);
let $var = $T::from_canonical(ty);)* let $var = $T::from_canonical(ty);)*
($($var,)*) ($($var,)*)
} }

View file

@ -169,6 +169,12 @@ impl EnumTypePropertiesBuilder {
} }
} }
impl Default for EnumTypePropertiesBuilder {
fn default() -> Self {
Self::new()
}
}
impl Enum { impl Enum {
#[track_caller] #[track_caller]
pub fn new(variants: Interned<[EnumVariant]>) -> Self { pub fn new(variants: Interned<[EnumVariant]>) -> Self {
@ -399,9 +405,8 @@ impl<T: Type> HdlOption<T> {
else { else {
unreachable!(); unreachable!();
}; };
let value = f(value).map_err(|e| { let value = f(value).inspect_err(|_| {
and_then_out.complete(()); // avoid error and_then_out.complete(()); // avoid error
e
})?; })?;
let and_then_out = and_then_out.complete(Expr::ty(value)); let and_then_out = and_then_out.complete(Expr::ty(value));
connect(and_then_out, value); connect(and_then_out, value);

View file

@ -147,7 +147,7 @@ where
fn try_from_usize(v: usize) -> Option<Self::SizeType> { fn try_from_usize(v: usize) -> Option<Self::SizeType> {
if v == VALUE { if v == VALUE {
Some(Self::SizeType::default()) Some(ConstUsize)
} else { } else {
None None
} }
@ -560,7 +560,7 @@ pub trait BoolOrIntType: Type + sealed::BoolOrIntTypeSealed {
} }
fn bits_to_expr(bits: Cow<'_, BitSlice>) -> Expr<Self>; fn bits_to_expr(bits: Cow<'_, BitSlice>) -> Expr<Self>;
fn le_bytes_to_expr_wrapping(bytes: &[u8], bit_width: usize) -> Expr<Self> { fn le_bytes_to_expr_wrapping(bytes: &[u8], bit_width: usize) -> Expr<Self> {
let bitslice = BitSlice::<u8, Lsb0>::from_slice(&bytes); let bitslice = BitSlice::<u8, Lsb0>::from_slice(bytes);
let bitslice = &bitslice[..bit_width.min(bitslice.len())]; let bitslice = &bitslice[..bit_width.min(bitslice.len())];
let mut bits = BitVec::new(); let mut bits = BitVec::new();
bits.extend_from_bitslice(bitslice); bits.extend_from_bitslice(bitslice);

View file

@ -634,7 +634,7 @@ impl<Element: Type, Len: Size> Mem<Element, Len> {
self.0.source_location self.0.source_location
} }
pub fn array_type(self) -> ArrayType<Element, Len> { pub fn array_type(self) -> ArrayType<Element, Len> {
self.0.array_type.clone() self.0.array_type
} }
pub fn initial_value(self) -> Option<Interned<BitSlice>> { pub fn initial_value(self) -> Option<Interned<BitSlice>> {
self.0.initial_value self.0.initial_value
@ -987,7 +987,7 @@ impl<Element: Type, Len: Size> MemBuilder<Element, Len> {
#[allow(clippy::result_unit_err)] #[allow(clippy::result_unit_err)]
pub fn get_array_type(&self) -> Result<ArrayType<Element, Len>, ()> { pub fn get_array_type(&self) -> Result<ArrayType<Element, Len>, ()> {
Ok(ArrayType::new( Ok(ArrayType::new(
self.mem_element_type.clone(), self.mem_element_type,
Len::from_usize(self.get_depth()?), Len::from_usize(self.get_depth()?),
)) ))
} }

View file

@ -607,6 +607,10 @@ impl BlockStack {
pub struct Id(NonZeroU64); pub struct Id(NonZeroU64);
impl Id { 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 { pub fn new() -> Self {
static NEXT_ID: AtomicU64 = AtomicU64::new(1); static NEXT_ID: AtomicU64 = AtomicU64::new(1);
Self( Self(
@ -945,7 +949,7 @@ impl From<NormalModuleBody<ModuleBuilding>> for NormalModuleBody {
Stmt::Declaration(decl) => { Stmt::Declaration(decl) => {
let annotations = annotations_map let annotations = annotations_map
.remove(&decl) .remove(&decl)
.map(|v| Intern::intern_owned(v)) .map(Intern::intern_owned)
.unwrap_or_default(); .unwrap_or_default();
match decl { match decl {
StmtDeclaration::Wire(StmtWire { StmtDeclaration::Wire(StmtWire {
@ -1615,10 +1619,7 @@ impl AssertValidityState {
let module = self.module; let module = self.module;
if block == 0 { if block == 0 {
for module_io in &*module.module_io { for module_io in &*module.module_io {
self.insert_new_base( self.insert_new_base(TargetBase::intern_sized(module_io.module_io.into()), block);
TargetBase::intern_sized(module_io.module_io.clone().into()),
block,
);
} }
} }
let Block { memories, stmts } = self.blocks[block]; let Block { memories, stmts } = self.blocks[block];
@ -1934,7 +1935,7 @@ impl ModuleBuilder {
let module_io = module_io.canonical(); let module_io = module_io.canonical();
let mut impl_ = self.impl_.borrow_mut(); let mut impl_ = self.impl_.borrow_mut();
let impl_ = &mut *impl_; 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 { impl_.io.push(AnnotatedModuleIO {
annotations: vec![], annotations: vec![],
module_io, module_io,
@ -2478,7 +2479,7 @@ pub fn memory_array_with_loc<Element: Type, Len: Size>(
mem_array_type: ArrayType<Element, Len>, mem_array_type: ArrayType<Element, Len>,
source_location: SourceLocation, source_location: SourceLocation,
) -> MemBuilder<Element, Len> { ) -> MemBuilder<Element, Len> {
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.depth(mem_array_type.len());
retval retval
} }

View file

@ -271,12 +271,12 @@ impl State {
.into()), .into()),
EnumTypeState::TagUIntAndBody(_) => { EnumTypeState::TagUIntAndBody(_) => {
let int_tag_expr = Expr::<TagAndBody<UInt, UInt>>::from_canonical(folded_expr).tag; let int_tag_expr = Expr::<TagAndBody<UInt, UInt>>::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(_) => { EnumTypeState::UInt(_) => {
let int_tag_expr = Expr::<UInt>::from_canonical(folded_expr) let int_tag_expr = Expr::<UInt>::from_canonical(folded_expr)
[..unfolded_enum_type.discriminant_bit_width()]; [..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 { EnumTypeState::Unchanged => Ok(StmtMatch {
expr: Expr::from_canonical(folded_expr), expr: Expr::from_canonical(folded_expr),
@ -929,13 +929,10 @@ impl Folder for State {
unreachable!() unreachable!()
} }
fn fold_enum_literal<T: EnumType>( fn fold_enum_literal<T: EnumType + Fold<Self>>(
&mut self, &mut self,
_v: ops::EnumLiteral<T>, _v: ops::EnumLiteral<T>,
) -> Result<ops::EnumLiteral<T>, Self::Error> ) -> Result<ops::EnumLiteral<T>, Self::Error> {
where
T: Fold<Self>,
{
unreachable!() unreachable!()
} }

View file

@ -766,7 +766,7 @@ impl ModuleState {
output_stmts.push( output_stmts.push(
StmtWire { StmtWire {
annotations: Default::default(), annotations: Default::default(),
wire: canonical_wire.clone(), wire: canonical_wire,
} }
.into(), .into(),
); );

View file

@ -106,3 +106,9 @@ impl<T: ?Sized> ScopedRef<T> {
self.0.with_opt(f) self.0.with_opt(f)
} }
} }
impl<T: ?Sized> Default for ScopedRef<T> {
fn default() -> Self {
Self::new()
}
}

View file

@ -2258,7 +2258,7 @@ pub fn check_memory_of_bundle() {
let wmask: (Bool, Bool) = m.input(); let wmask: (Bool, Bool) = m.input();
#[hdl] #[hdl]
let clk: Clock = m.input(); 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] #[hdl]
let mut mem = memory_with_init(mem_init); let mut mem = memory_with_init(mem_init);
let read_port = mem.new_read_port(); let read_port = mem.new_read_port();