From d4680165afa4eedb3df00aae4b50d2f6584dfe96 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 6 May 2016 22:05:32 -0400 Subject: [PATCH] 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 --- src/re_unicode.rs | 12 ------------ tests/api_str.rs | 6 ------ tests/misc.rs | 7 ------- 3 files changed, 25 deletions(-) diff --git a/src/re_unicode.rs b/src/re_unicode.rs index 5a3ede915d..adeba1cdd5 100644 --- a/src/re_unicode.rs +++ b/src/re_unicode.rs @@ -136,18 +136,6 @@ impl From 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; diff --git a/tests/api_str.rs b/tests/api_str.rs index e5e667863d..c6d392876b 100644 --- a/tests/api_str.rs +++ b/tests/api_str.rs @@ -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()); -} diff --git a/tests/misc.rs b/tests/misc.rs index 293cddb322..dfe28c9707 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -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()); -}