Skip to content

Commit 6705828

Browse files
authored
Fixes all clippy warnings (#242)
1 parent 20224ea commit 6705828

File tree

6 files changed

+46
-42
lines changed

6 files changed

+46
-42
lines changed

ion-schema/src/isl/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
//! This module consists of three submodules that help constructing ISL types/constraint:
44
//!
55
//! * `isl_type` module represents a schema type [IslType] which converts given ion content in the schema file
6-
//! into an ISL types(not-yet-resolved types). It stores `IslConstraint`s defined within the given type.
7-
//!
6+
//! into an ISL types(not-yet-resolved types). It stores `IslConstraint`s defined within the given type.
87
//! * `isl_import` module represents a schema import [IslImport] which converts given ion content in the schema file
9-
//! into an ISL import. It stores schema id, an optional type that needs to be imported and an optional alias to that type.
10-
//!
8+
//! into an ISL import. It stores schema id, an optional type that needs to be imported and an optional alias to that type.
119
//! * `isl_constraint` module represents schema constraints [IslConstraint]
12-
//! which converts given ion content in the schema file into an ISL constraint(not-yet-resolved constraints).
13-
//!
10+
//! which converts given ion content in the schema file into an ISL constraint(not-yet-resolved constraints).
1411
//! * `isl_type_reference` module provides a schema type reference.
12+
//!
1513
//! The type reference grammar is defined in the [Ion Schema Specification]
1614
//!
1715
//! [IslConstraint]: isl_constraint::IslConstraint
@@ -555,6 +553,7 @@ impl<'a> Iterator for SchemaIterator<'a> {
555553
}
556554

557555
#[cfg(test)]
556+
#[allow(unused_must_use)]
558557
mod isl_tests {
559558
use crate::authority::FileSystemDocumentAuthority;
560559
use crate::ion_extension::ElementExtensions;

ion-schema/src/isl/util.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,15 @@ impl ValidValue {
209209
if element.annotations().contains("range") {
210210
isl_require!(annotation.len() == 1 => "Unexpected annotation(s) on valid values argument: {element}")?;
211211
// Does it contain any timestamps
212-
let has_timestamp = element.as_sequence().map_or(false, |s| {
213-
s.elements().any(|it| it.ion_type() == IonType::Timestamp)
214-
});
212+
let has_timestamp = {
213+
if let Some(sequence) = element.as_sequence() {
214+
sequence
215+
.elements()
216+
.any(|it| it.ion_type() == IonType::Timestamp)
217+
} else {
218+
false
219+
}
220+
};
215221
let range = if has_timestamp {
216222
ValidValue::TimestampRange(TimestampRange::from_ion_element(element, |e| {
217223
e.as_timestamp()

ion-schema/src/ordered_elements_nfa.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl OrderedElementsNfa {
218218
edges.clone()
219219
} else {
220220
// The only state without edges is `Final`, which cannot be exited.
221-
invalid_transitions.insert(TraversalError::CannotExitState(from_state_id));
221+
invalid_transitions.insert(TraversalError::Exiting(from_state_id));
222222
break;
223223
};
224224

@@ -231,7 +231,7 @@ impl OrderedElementsNfa {
231231
let is_loop = to_state_id == from_state_id;
232232

233233
if !is_loop && !can_exit {
234-
invalid_transitions.insert(TraversalError::CannotExitState(from_state_id));
234+
invalid_transitions.insert(TraversalError::Exiting(from_state_id));
235235
// We haven't reached the min_occurs of the current state. Any further
236236
// transitions will also suffer from the same problem. No need to report
237237
// this same problem repeatedly, so we break here.
@@ -245,9 +245,9 @@ impl OrderedElementsNfa {
245245

246246
if let Err(violation) = can_enter {
247247
invalid_transitions
248-
.insert(TraversalError::CannotEnterState(to_state_id, violation));
248+
.insert(TraversalError::Entering(to_state_id, violation));
249249
} else if is_loop && !can_reenter {
250-
invalid_transitions.insert(TraversalError::CannotReEnterState(to_state_id));
250+
invalid_transitions.insert(TraversalError::ReEntering(to_state_id));
251251
} else {
252252
let new_num_visits = if is_loop { num_visits + 1 } else { 1 };
253253
new_states.insert((to_state_id, new_num_visits));
@@ -284,19 +284,19 @@ impl OrderedElementsNfa {
284284
let reasons = reasons
285285
.into_iter()
286286
.map(|it| match it {
287-
TraversalError::CannotExitState(s) => Violation::new(
287+
TraversalError::Exiting(s) => Violation::new(
288288
"ordered_elements",
289289
ViolationCode::ElementMismatched,
290290
format!("{}: min occurs not reached", &self.states[s]),
291291
ion_path,
292292
),
293-
TraversalError::CannotReEnterState(s) => Violation::new(
293+
TraversalError::ReEntering(s) => Violation::new(
294294
"ordered_elements",
295295
ViolationCode::ElementMismatched,
296296
format!("{}: max occurs already reached", &self.states[s],),
297297
ion_path,
298298
),
299-
TraversalError::CannotEnterState(s, v) => Violation::with_violations(
299+
TraversalError::Entering(s, v) => Violation::with_violations(
300300
"ordered_elements",
301301
ViolationCode::ElementMismatched,
302302
format!("{}: does not match type", &self.states[s]),
@@ -424,9 +424,9 @@ impl Display for State {
424424
/// The reason why a transition (or edge) in the state machine graph cannot be traversed.
425425
#[derive(Debug)]
426426
enum TraversalError {
427-
CannotEnterState(StateId, Violation),
428-
CannotExitState(StateId),
429-
CannotReEnterState(StateId),
427+
Entering(StateId, Violation),
428+
Exiting(StateId),
429+
ReEntering(StateId),
430430
}
431431

432432
impl PartialOrd for TraversalError {
@@ -438,14 +438,14 @@ impl PartialOrd for TraversalError {
438438
impl Ord for TraversalError {
439439
fn cmp(&self, other: &Self) -> Ordering {
440440
let self_id = match self {
441-
TraversalError::CannotEnterState(id, _)
442-
| TraversalError::CannotExitState(id)
443-
| TraversalError::CannotReEnterState(id) => id,
441+
TraversalError::Entering(id, _)
442+
| TraversalError::Exiting(id)
443+
| TraversalError::ReEntering(id) => id,
444444
};
445445
let other_id = match other {
446-
TraversalError::CannotEnterState(id, _)
447-
| TraversalError::CannotExitState(id)
448-
| TraversalError::CannotReEnterState(id) => id,
446+
TraversalError::Entering(id, _)
447+
| TraversalError::Exiting(id)
448+
| TraversalError::ReEntering(id) => id,
449449
};
450450
self_id.cmp(other_id)
451451
}
@@ -456,22 +456,19 @@ impl Eq for TraversalError {}
456456
impl PartialEq for TraversalError {
457457
fn eq(&self, other: &Self) -> bool {
458458
match (self, other) {
459-
(
460-
TraversalError::CannotExitState(self_id),
461-
TraversalError::CannotExitState(other_id),
462-
) => self_id == other_id,
463-
(
464-
TraversalError::CannotReEnterState(self_id),
465-
TraversalError::CannotReEnterState(other_id),
466-
) => self_id == other_id,
459+
(TraversalError::Exiting(self_id), TraversalError::Exiting(other_id)) => {
460+
self_id == other_id
461+
}
462+
(TraversalError::ReEntering(self_id), TraversalError::ReEntering(other_id)) => {
463+
self_id == other_id
464+
}
467465
// It is okay to ignore the violation here because we only consider one event/element at
468466
// any given point in the state machine. Since that is the case, if the IDs are the same,
469467
// then they must represent the same destination state (type reference), and so the
470468
// violations must be equal.
471-
(
472-
TraversalError::CannotEnterState(self_id, _),
473-
TraversalError::CannotEnterState(other_id, _),
474-
) => self_id == other_id,
469+
(TraversalError::Entering(self_id, _), TraversalError::Entering(other_id, _)) => {
470+
self_id == other_id
471+
}
475472
(_, _) => false,
476473
}
477474
}
@@ -484,9 +481,9 @@ impl Hash for TraversalError {
484481
// between the prime numbers makes it even more unlikely that a collision would occur since
485482
// the first IDs that could have a collision with each other would be 107 and 307.
486483
state.write_usize(match self {
487-
TraversalError::CannotEnterState(id, _) => id * 503,
488-
TraversalError::CannotExitState(id) => id * 307,
489-
TraversalError::CannotReEnterState(id) => id * 107,
484+
TraversalError::Entering(id, _) => id * 503,
485+
TraversalError::Exiting(id) => id * 307,
486+
TraversalError::ReEntering(id) => id * 107,
490487
})
491488
}
492489
}

ion-schema/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//!
44
//! * `get_types`: This function returns an [`SchemaTypeIterator`] which can be used to iterate over the [`TypeDefinition`]s.
55
//! * `get_type`: This function requires to pass the name of a type definition that you want to use for validation.
6+
//!
67
//! It returns the [`TypeDefinition`] if it is defined in the [`Schema`] otherwise returns [`None`].
78
//!
89

ion-schema/src/system.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use std::sync::Arc;
4747
/// * A nested anonymous type definition.
4848
/// * A reference to type definition that is followed by current type definition. These type references
4949
/// will be deferred to later check if a type definition with that name exists in the schema.
50+
///
5051
/// Because the [`SchemaSystem`] does not yet know the complete definition
5152
/// of these types, it cannot find them in the [`TypeStore`].
5253
/// An instance of [`PendingTypes`] is used to track information about types
@@ -92,6 +93,7 @@ impl PendingTypes {
9293
/// exists in [`PendingTypes`] it would have been added as a deferred type definition.
9394
/// This deferred type will be loaded into [`TypeStore`] as it is and will be replaced with a type definition
9495
/// once it is resolved.
96+
///
9597
/// Returns true, if this update is not for an isl import type or it is for an isl import type but it is added to the type_store
9698
/// Otherwise, returns false if this update is for an isl import type and it is not yet added to the type_store.
9799
pub fn update_type_store(

ion-schema/src/violation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ macro_rules! assert_equivalent_violations {
210210
};
211211
}
212212

213-
#[macro_export]
214-
215213
/// Equivalence for `Violation`s is not supported due to its tree structure of having children violations.
216214
/// This macro can be used for comparing if two violations are not equal and uses `flattened_violations` for the comparison.
215+
#[macro_export]
217216
macro_rules! assert_non_equivalent_violations {
218217
($left:expr, $right:expr $(,)?) => {
219218
let mut left_strings: Vec<String> = $left

0 commit comments

Comments
 (0)