Skip to content

Commit 421947b

Browse files
committed
Fix new clippy lints
As a result we're now using let chains, raising the msrv to 1.88
1 parent 85aab3c commit 421947b

6 files changed

Lines changed: 269 additions & 282 deletions

File tree

autosar-data-specification/src/lib.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,12 @@ impl ElementType {
407407

408408
pub(crate) fn short_name_version_mask(self) -> Option<u32> {
409409
let sub_elements = ElementType::get_sub_elements(self.typ);
410-
if !sub_elements.is_empty() {
411-
if let SubElement::Element(idx) = sub_elements[0] {
412-
if ELEMENTS[idx as usize].name == ElementName::ShortName {
413-
let ver_idx = ElementType::get_sub_element_ver(self.typ);
414-
return Some(VERSION_INFO[ver_idx]);
415-
}
416-
}
410+
if !sub_elements.is_empty()
411+
&& let SubElement::Element(idx) = sub_elements[0]
412+
&& ELEMENTS[idx as usize].name == ElementName::ShortName
413+
{
414+
let ver_idx = ElementType::get_sub_element_ver(self.typ);
415+
return Some(VERSION_INFO[ver_idx]);
417416
}
418417
None
419418
}
@@ -704,10 +703,10 @@ pub fn expand_version_mask(version_mask: u32) -> Vec<AutosarVersion> {
704703
let mut versions = vec![];
705704
for i in 0..u32::BITS {
706705
let val = 1u32 << i;
707-
if version_mask & val != 0 {
708-
if let Some(enum_value) = AutosarVersion::from_val(val) {
709-
versions.push(enum_value);
710-
}
706+
if version_mask & val != 0
707+
&& let Some(enum_value) = AutosarVersion::from_val(val)
708+
{
709+
versions.push(enum_value);
711710
}
712711
}
713712

autosar-data/src/autosarmodel.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ impl AutosarModel {
195195
// in this case we only keep the first one
196196
if let Some(existing_element) = data.identifiables.get(&key).and_then(WeakElement::upgrade) {
197197
// present in both
198-
if let Some(new_element) = value.upgrade() {
199-
if existing_element.element_name() != new_element.element_name() {
200-
// referenced element is different on both sides
201-
return Err(AutosarDataError::OverlappingDataError {
202-
filename,
203-
path: new_element.xml_path(),
204-
});
205-
}
198+
if let Some(new_element) = value.upgrade()
199+
&& existing_element.element_name() != new_element.element_name()
200+
{
201+
// referenced element is different on both sides
202+
return Err(AutosarDataError::OverlappingDataError {
203+
filename,
204+
path: new_element.xml_path(),
205+
});
206206
}
207207
} else {
208208
data.identifiables.insert(key, value);
@@ -1017,13 +1017,13 @@ impl AutosarModel {
10171017
let keys: Vec<String> = model.identifiables.keys().cloned().collect();
10181018
for key in keys {
10191019
// find keys referring to entries inside the renamed package
1020-
if let Some(suffix) = key.strip_prefix(old_path) {
1021-
if suffix.is_empty() || suffix.starts_with('/') {
1022-
let new_key = format!("{new_path}{suffix}");
1023-
// fix the identifiables hashmap
1024-
if let Some(entry) = model.identifiables.swap_remove(&key) {
1025-
model.identifiables.insert(new_key, entry);
1026-
}
1020+
if let Some(suffix) = key.strip_prefix(old_path)
1021+
&& (suffix.is_empty() || suffix.starts_with('/'))
1022+
{
1023+
let new_key = format!("{new_path}{suffix}");
1024+
// fix the identifiables hashmap
1025+
if let Some(entry) = model.identifiables.swap_remove(&key) {
1026+
model.identifiables.insert(new_key, entry);
10271027
}
10281028
}
10291029
}
@@ -1050,11 +1050,11 @@ impl AutosarModel {
10501050
let mut data = self.0.write();
10511051
let mut remove_list = false;
10521052
// remove the old entry
1053-
if let Some(referrer_list) = data.reference_origins.get_mut(old_ref) {
1054-
if let Some(index) = referrer_list.iter().position(|x| *x == origin) {
1055-
referrer_list.swap_remove(index);
1056-
remove_list = referrer_list.is_empty();
1057-
}
1053+
if let Some(referrer_list) = data.reference_origins.get_mut(old_ref)
1054+
&& let Some(index) = referrer_list.iter().position(|x| *x == origin)
1055+
{
1056+
referrer_list.swap_remove(index);
1057+
remove_list = referrer_list.is_empty();
10581058
}
10591059
if remove_list {
10601060
data.reference_origins.remove(old_ref);

autosar-data/src/chardata.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ impl CharacterData {
2323
CharacterDataSpec::Pattern {
2424
check_fn, max_length, ..
2525
} => {
26-
if let CharacterData::String(stringval) = &value {
27-
if stringval.len() <= max_length.unwrap_or(usize::MAX) && check_fn(stringval.as_bytes()) {
28-
return true;
29-
}
26+
if let CharacterData::String(stringval) = &value
27+
&& stringval.len() <= max_length.unwrap_or(usize::MAX)
28+
&& check_fn(stringval.as_bytes())
29+
{
30+
return true;
3031
}
3132
}
3233
CharacterDataSpec::String { max_length, .. } => {
33-
if let CharacterData::String(stringval) = &value {
34-
if stringval.len() <= max_length.unwrap_or(usize::MAX) {
35-
return true;
36-
}
34+
if let CharacterData::String(stringval) = &value
35+
&& stringval.len() <= max_length.unwrap_or(usize::MAX)
36+
{
37+
return true;
3738
}
3839
}
3940
CharacterDataSpec::UnsignedInteger => {
@@ -79,12 +80,11 @@ impl CharacterData {
7980
pub(crate) fn parse(input: &str, character_data_spec: &CharacterDataSpec, version: AutosarVersion) -> Option<Self> {
8081
match character_data_spec {
8182
CharacterDataSpec::Enum { items } => {
82-
if let Ok(enumitem) = EnumItem::from_str(input) {
83-
if let Some((_, version_mask)) = items.iter().find(|(item, _)| *item == enumitem) {
84-
if version as u32 & version_mask != 0 {
85-
return Some(CharacterData::Enum(enumitem));
86-
}
87-
}
83+
if let Ok(enumitem) = EnumItem::from_str(input)
84+
&& let Some((_, version_mask)) = items.iter().find(|(item, _)| *item == enumitem)
85+
&& version as u32 & version_mask != 0
86+
{
87+
return Some(CharacterData::Enum(enumitem));
8888
}
8989
}
9090
CharacterDataSpec::Pattern {

0 commit comments

Comments
 (0)