Skip to content

Commit ede4fc7

Browse files
committed
Drop the PartialEq and Eq impls on Regex.
It is misleading to suggest that Regex implements equality, since equality is a well defined operation on regular expressions and this particular implementation doesn't correspond to that definition at all. Moreover, I suspect the actual use cases for such an impl are rather niche. A simple newtype+deref should resolve any such use cases. Fixes #178
1 parent 1fac7b7 commit ede4fc7

File tree

3 files changed

+0
-25
lines changed

3 files changed

+0
-25
lines changed

src/re_unicode.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,6 @@ impl From<Exec> for Regex {
136136
}
137137
}
138138

139-
/// Equality comparison is based on the original string. It is possible that
140-
/// different regular expressions have the same matching behavior, but are
141-
/// still compared unequal. For example, `\d+` and `\d\d*` match the same set
142-
/// of strings, but are not considered equal.
143-
impl PartialEq for Regex {
144-
fn eq(&self, other: &Regex) -> bool {
145-
self.as_str() == other.as_str()
146-
}
147-
}
148-
149-
impl Eq for Regex {}
150-
151139
impl FromStr for Regex {
152140
type Err = Error;
153141

tests/api_str.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,3 @@ fn empty_match_unicode_captures_iter() {
1919
.collect();
2020
assert_eq!(vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)], ms);
2121
}
22-
23-
#[test]
24-
fn eq() {
25-
use regex::Regex;
26-
assert_eq!(regex!(r"[a-z]+"), Regex::new("[a-z]+").unwrap());
27-
}

tests/misc.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use regex::Regex;
12-
1311
mat!(prefix_literal_match, r"^abc", r"abc", Some((0, 3)));
1412
mat!(prefix_literal_nomatch, r"^abc", r"zabc", None);
1513
mat!(one_literal_edge, r"abc", r"xxxxxab", None);
16-
17-
#[test]
18-
fn eq() {
19-
assert_eq!(regex!(r"[a-z]+"), Regex::new("[a-z]+").unwrap());
20-
}

0 commit comments

Comments
 (0)