Skip to content

Commit

Permalink
Drop the PartialEq and Eq impls on Regex.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BurntSushi committed Dec 30, 2016
1 parent f98219b commit 83fce85
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 25 deletions.
12 changes: 0 additions & 12 deletions src/re_unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ impl From<Exec> for Regex {
}
}

/// Equality comparison is based on the original string. It is possible that
/// different regular expressions have the same matching behavior, but are
/// still compared unequal. For example, `\d+` and `\d\d*` match the same set
/// of strings, but are not considered equal.
impl PartialEq for Regex {
fn eq(&self, other: &Regex) -> bool {
self.as_str() == other.as_str()
}
}

impl Eq for Regex {}

impl FromStr for Regex {
type Err = Error;

Expand Down
6 changes: 0 additions & 6 deletions tests/api_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,3 @@ fn empty_match_unicode_captures_iter() {
.collect();
assert_eq!(vec![(0, 0), (3, 3), (4, 4), (7, 7), (8, 8)], ms);
}

#[test]
fn eq() {
use regex::Regex;
assert_eq!(regex!(r"[a-z]+"), Regex::new("[a-z]+").unwrap());
}
7 changes: 0 additions & 7 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use regex::Regex;

mat!(prefix_literal_match, r"^abc", r"abc", Some((0, 3)));
mat!(prefix_literal_nomatch, r"^abc", r"zabc", None);
mat!(one_literal_edge, r"abc", r"xxxxxab", None);
matiter!(terminates, r"a$", r"a", (0, 1));

#[test]
fn eq() {
assert_eq!(regex!(r"[a-z]+"), Regex::new("[a-z]+").unwrap());
}

0 comments on commit 83fce85

Please sign in to comment.