Skip to content

Commit c80032d

Browse files
committed
Remove eq on LexErrorKind add private is_same_kind.
1 parent 6b853ee commit c80032d

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

lrlex/src/lib/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub enum LexErrorKind {
6565
VerbatimNotSupported,
6666
}
6767

68-
impl PartialEq for LexErrorKind {
69-
fn eq(&self, other: &Self) -> bool {
68+
impl LexErrorKind {
69+
fn is_same_kind(&self, other: &Self) -> bool {
7070
use LexErrorKind as EK;
7171
match (self, other) {
7272
(EK::PrematureEnd, EK::PrematureEnd)
@@ -82,16 +82,13 @@ impl PartialEq for LexErrorKind {
8282
| (EK::InvalidGrmtoolsSectionValue, EK::InvalidGrmtoolsSectionValue)
8383
| (EK::InvalidNumber, EK::InvalidNumber)
8484
| (EK::DuplicateGrmtoolsSectionValue, EK::DuplicateGrmtoolsSectionValue)
85+
| (EK::RegexError(_), EK::RegexError(_))
8586
| (EK::VerbatimNotSupported, EK::VerbatimNotSupported) => true,
86-
(EK::RegexError(e1), EK::RegexError(e2)) => e1.to_string() == e2.to_string(),
87-
8887
_ => false,
8988
}
9089
}
9190
}
9291

93-
impl Eq for LexErrorKind {}
94-
9592
impl Spanned for LexBuildError {
9693
fn spans(&self) -> &[Span] {
9794
self.spans.as_slice()

lrlex/src/lib/parser.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn add_duplicate_occurrence(
113113
dup_span: Span,
114114
) {
115115
if !errs.iter_mut().any(|e| {
116-
if e.kind == kind && e.spans[0] == orig_span {
116+
if e.kind.is_same_kind(&kind) && e.spans[0] == orig_span {
117117
e.spans.push(dup_span);
118118
true
119119
} else {
@@ -852,7 +852,7 @@ mod test {
852852
.expect_err("Parsed ok while expecting error");
853853
assert_eq!(errs.len(), 1);
854854
let e = &errs[0];
855-
assert_eq!(e.kind, kind);
855+
assert!(e.kind.is_same_kind(&kind));
856856
assert_eq!(
857857
e.spans()
858858
.iter()
@@ -880,20 +880,22 @@ mod test {
880880
}
881881
}
882882

883-
assert_eq!(
884-
errs.iter()
885-
.map(|e| {
886-
(
887-
e.kind.clone(),
888-
e.spans()
889-
.iter()
890-
.map(|span| line_col!(src, span))
891-
.collect::<Vec<_>>(),
892-
)
893-
})
894-
.collect::<Vec<_>>(),
895-
expected.collect::<Vec<_>>()
896-
);
883+
for ((ek1, es1), (ek2, es2)) in errs
884+
.iter()
885+
.map(|e| {
886+
(
887+
e.kind.clone(),
888+
e.spans()
889+
.iter()
890+
.map(|span| line_col!(src, span))
891+
.collect::<Vec<_>>(),
892+
)
893+
})
894+
.zip(expected)
895+
{
896+
assert!(ek1.is_same_kind(&ek2));
897+
assert_eq!(es1, es2);
898+
}
897899
}
898900
}
899901

0 commit comments

Comments
 (0)