Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy fixes #272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions svd-encoder/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where
NumberFormat::UpperHex => format!("{:#X}", value),
NumberFormat::UpperHex8 => format!("{:#010X}", value),
NumberFormat::UpperHex16 => {
if value.into() > std::u32::MAX as u64 {
if value.into() > u32::MAX as u64 {
format!("{:#018X}", value)
} else {
format!("{:#010X}", value)
Expand All @@ -139,7 +139,7 @@ where
NumberFormat::LowerHex => format!("{:#x}", value),
NumberFormat::LowerHex8 => format!("{:#010x}", value),
NumberFormat::LowerHex16 => {
if value.into() > std::u32::MAX as u64 {
if value.into() > u32::MAX as u64 {
format!("{:#018x}", value)
} else {
format!("{:#010x}", value)
Expand Down
36 changes: 17 additions & 19 deletions svd-parser/src/expand.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Provides [expand] method to convert arrays, clusters and derived items in regular instances

use anyhow::{anyhow, Result};
use std::collections::HashMap;
use std::fmt;
use std::mem::take;
use std::{collections::HashMap, fmt, mem::take, ops::Deref};
use svd_rs::{
array::names, cluster, field, peripheral, register, Cluster, ClusterInfo, DeriveFrom, Device,
EnumeratedValues, Field, Peripheral, Register, RegisterCluster, RegisterProperties,
Expand Down Expand Up @@ -63,11 +61,11 @@ impl PartialEq<str> for BlockPath {
}
let mut parts = other.split('.');
if let Some(part1) = parts.next() {
if self.peripheral != part1 {
if self.peripheral.deref() != part1 {
Copy link
Member

@jannic jannic Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What clippy message is fixed by that change?

Perhaps the deref commit slipped into the PR by accident?

return false;
}
for p in parts.zip(self.path.iter()) {
if p.0 != p.1 {
if p.0 != p.1.deref() {
return false;
}
}
Expand Down Expand Up @@ -120,7 +118,7 @@ impl RegisterPath {
impl PartialEq<str> for RegisterPath {
fn eq(&self, other: &str) -> bool {
if let Some((block, reg)) = other.rsplit_once('.') {
self.name == reg && &self.block == block
self.name.deref() == reg && &self.block == block
} else {
false
}
Expand Down Expand Up @@ -180,7 +178,7 @@ impl FieldPath {
impl PartialEq<str> for FieldPath {
fn eq(&self, other: &str) -> bool {
if let Some((reg, field)) = other.rsplit_once('.') {
self.name == field && &self.register == reg
self.name.deref() == field && &self.register == reg
} else {
false
}
Expand Down Expand Up @@ -224,7 +222,7 @@ impl EnumPath {
impl PartialEq<str> for EnumPath {
fn eq(&self, other: &str) -> bool {
if let Some((field, evs)) = other.rsplit_once('.') {
self.name == evs && &self.field == field
self.name.deref() == evs && &self.field == field
} else {
false
}
Expand Down Expand Up @@ -263,7 +261,7 @@ impl<'a> Index<'a> {
self.peripherals.insert(path, p);
}
}
let path = BlockPath::new(&p.name);
let path = BlockPath::new(p.name.deref());
for r in p.registers() {
self.add_register(&path, r);
}
Expand All @@ -286,7 +284,7 @@ impl<'a> Index<'a> {
self.clusters.insert(cpath, c);
}
}
let cpath = path.new_cluster(&c.name);
let cpath = path.new_cluster(c.name.deref());
for r in c.registers() {
self.add_register(&cpath, r);
}
Expand All @@ -305,7 +303,7 @@ impl<'a> Index<'a> {
self.registers.insert(rpath, r);
}
}
let rpath = path.new_register(&r.name);
let rpath = path.new_register(r.name.deref());
for f in r.fields() {
self.add_field(&rpath, f);
}
Expand All @@ -317,16 +315,16 @@ impl<'a> Index<'a> {
let fpath = path.new_field(name);
for evs in &f.enumerated_values {
if let Some(name) = evs.name.as_ref() {
self.evs.insert(fpath.new_enum(name), evs);
self.evs.insert(fpath.new_enum(name.deref()), evs);
}
}
self.fields.insert(fpath, f);
}
}
let fpath = path.new_field(&f.name);
let fpath = path.new_field(f.name.deref());
for evs in &f.enumerated_values {
if let Some(name) = evs.name.as_ref() {
self.evs.insert(fpath.new_enum(name), evs);
self.evs.insert(fpath.new_enum(name.deref()), evs);
}
}
self.fields.insert(fpath, f);
Expand Down Expand Up @@ -365,7 +363,7 @@ fn expand_cluster_array(
if let Some(dpath) = dpath {
cpath = derive_cluster(&mut c, &dpath, path, index)?;
}
let cpath = cpath.unwrap_or_else(|| path.new_cluster(&c.name));
let cpath = cpath.unwrap_or_else(|| path.new_cluster(c.name.deref()));

for rc in take(&mut c.children) {
expand_register_cluster(&mut c.children, rc, &cpath, index)?;
Expand Down Expand Up @@ -499,7 +497,7 @@ fn expand_register_array(
if let Some(dpath) = dpath {
rpath = derive_register(&mut r, &dpath, path, index)?;
}
let rpath = rpath.unwrap_or_else(|| path.new_register(&r.name));
let rpath = rpath.unwrap_or_else(|| path.new_register(r.name.deref()));

if let Some(field) = r.fields.as_mut() {
for f in take(field) {
Expand Down Expand Up @@ -529,7 +527,7 @@ fn expand_field(
if let Some(dpath) = dpath {
fpath = derive_field(&mut f, &dpath, rpath, index)?;
}
let fpath = fpath.unwrap_or_else(|| rpath.new_field(&f.name));
let fpath = fpath.unwrap_or_else(|| rpath.new_field(f.name.deref()));

for ev in &mut f.enumerated_values {
let dpath = ev.derived_from.take();
Expand Down Expand Up @@ -564,7 +562,7 @@ pub fn derive_enumerated_values(
if let Some(r) = index.registers.get(rdpath) {
let mut found = None;
for f in r.fields() {
let epath = EnumPath::new(rdpath.new_field(&f.name), dname);
let epath = EnumPath::new(rdpath.new_field(f.name.deref()), dname);
if let Some(d) = index.evs.get(&epath) {
found = Some((d, epath));
break;
Expand Down Expand Up @@ -645,7 +643,7 @@ pub fn expand(indevice: &Device) -> Result<Device> {
if let Some(dpath) = dpath {
path = derive_peripheral(&mut p, &dpath, &index)?;
}
let path = path.unwrap_or_else(|| BlockPath::new(&p.name));
let path = path.unwrap_or_else(|| BlockPath::new(p.name.deref()));
if let Some(regs) = p.registers.as_mut() {
for rc in take(regs) {
expand_register_cluster(regs, rc, &path, &index)?;
Expand Down
9 changes: 2 additions & 7 deletions svd-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,17 @@ pub mod riscv;
pub use self::riscv::Riscv;

/// Level of validation
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ValidateLevel {
/// No validation.
Disabled,
/// Weak validation.
#[default]
Weak,
/// Strict validation.
Strict,
}

impl Default for ValidateLevel {
fn default() -> Self {
ValidateLevel::Weak
}
}

impl ValidateLevel {
/// Returns true if validation is disabled.
pub fn is_disabled(self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion svd-rs/src/registerproperties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub(crate) fn check_reset_value(
mask: Option<u64>,
lvl: ValidateLevel,
) -> Result<(), Error> {
const MAX_BITS: u32 = core::u64::MAX.count_ones();
const MAX_BITS: u32 = u64::MAX.count_ones();

if let (Some(size), Some(value)) = (size, value) {
if MAX_BITS - value.leading_zeros() > size {
Expand Down
15 changes: 3 additions & 12 deletions svd-rs/src/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,9 @@ impl RiscvBuilder {
/// Validate and build a [`Riscv`].
pub fn build(self, lvl: ValidateLevel) -> Result<Riscv, SvdError> {
let riscv = Riscv {
core_interrupts: match self.core_interrupts {
Some(core_interrupts) => core_interrupts,
None => Vec::new(),
},
exceptions: match self.exceptions {
Some(exceptions) => exceptions,
None => Vec::new(),
},
priorities: match self.priorities {
Some(priorities) => priorities,
None => Vec::new(),
},
core_interrupts: self.core_interrupts.unwrap_or_default(),
exceptions: self.exceptions.unwrap_or_default(),
priorities: self.priorities.unwrap_or_default(),
harts: self
.harts
.ok_or_else(|| BuildError::Uninitialized("harts".to_string()))?,
Expand Down