Skip to content

Commit 6d5e909

Browse files
committed
Fixes from code review.
The big change here is the addition of a non-public variant in the error enums. This will hint to users that one shouldn't exhaustively match the enums in case new variants are added.
1 parent 69e242d commit 6d5e909

File tree

8 files changed

+26
-15
lines changed

8 files changed

+26
-15
lines changed

.gitignore

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
/target
2-
/Cargo.lock
3-
/regex_macros/target
4-
/regex_macros/Cargo.lock
5-
/regex_syntax/target
6-
/regex_syntax/Cargo.lock
7-
/bench-log
1+
target
2+
Cargo.lock
3+
bench-log
84
.*.swp

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ path = "regex_macros/benches/bench_dynamic.rs"
2121
test = false
2222
bench = true
2323

24-
[dependencies.regex-syntax]
25-
path = "regex_syntax"
26-
version = "*"
24+
[dependencies]
25+
regex-syntax = { path = "regex-syntax", version = "0.1" }
2726

2827
[dev-dependencies]
2928
rand = "0.3"
@@ -32,5 +31,4 @@ rand = "0.3"
3231
pattern = []
3332

3433
[profile.bench]
35-
opt-level = 3
3634
lto = true

regex_syntax/Cargo.toml renamed to regex-syntax/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ license = "MIT/Apache-2.0"
66
repository = "https://github.com/rust-lang/regex"
77
documentation = "http://doc.rust-lang.org/regex"
88
homepage = "https://github.com/rust-lang/regex"
9-
description = "A regular expression parser (RE2 only)."
9+
description = "A regular expression parser."
1010

1111
[dev-dependencies]
12-
quickcheck = "*"
13-
rand = "*"
12+
quickcheck = "0.2"
13+
rand = "0.3"

regex_syntax/src/lib.rs renamed to regex-syntax/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ impl PartialOrd<ClassRange> for char {
540540

541541
/// This implementation of `Display` will write a regular expression from the
542542
/// syntax tree. It does not write the original string parsed.
543-
// TODO(burntsushi): Write tests for the regex writer.
544543
impl fmt::Display for Expr {
545544
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
546545
match *self {
@@ -722,6 +721,13 @@ pub enum ErrorKind {
722721
UnrecognizedFlag(char),
723722
/// Unrecognized named Unicode class. e.g., `\p{Foo}`.
724723
UnrecognizedUnicodeClass(String),
724+
/// Hints that destructuring should not be exhaustive.
725+
///
726+
/// This enum may grow additional variants, so this makes sure clients
727+
/// don't count on exhaustive matching. (Otherwise, adding a new variant
728+
/// could break existing code.)
729+
#[doc(hidden)]
730+
__Nonexhaustive,
725731
}
726732

727733
impl Error {
@@ -773,6 +779,7 @@ impl ErrorKind {
773779
UnrecognizedEscape(_) => "unrecognized escape sequence",
774780
UnrecognizedFlag(_) => "unrecognized flag",
775781
UnrecognizedUnicodeClass(_) => "unrecognized Unicode class name",
782+
__Nonexhaustive => unreachable!(),
776783
}
777784
}
778785
}
@@ -866,6 +873,7 @@ impl fmt::Display for ErrorKind {
866873
(Allowed flags: i, s, m, U, x.)", c),
867874
UnrecognizedUnicodeClass(ref s) =>
868875
write!(f, "Unrecognized Unicode class name: '{}'.", s),
876+
__Nonexhaustive => unreachable!(),
869877
}
870878
}
871879
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/re.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ pub enum Error {
5959
/// The compiled program exceeded the set size limit.
6060
/// The argument is the size limit imposed.
6161
CompiledTooBig(usize),
62+
/// Hints that destructuring should not be exhaustive.
63+
///
64+
/// This enum may grow additional variants, so this makes sure clients
65+
/// don't count on exhaustive matching. (Otherwise, adding a new variant
66+
/// could break existing code.)
67+
#[doc(hidden)]
68+
__Nonexhaustive,
6269
}
6370

6471
impl ::std::error::Error for Error {
6572
fn description(&self) -> &str {
6673
match *self {
6774
Error::Syntax(ref err) => err.description(),
6875
Error::CompiledTooBig(_) => "compiled program too big",
76+
Error::__Nonexhaustive => unreachable!(),
6977
}
7078
}
7179

@@ -85,6 +93,7 @@ impl fmt::Display for Error {
8593
write!(f, "Compiled regex exceeds size limit of {} bytes.",
8694
limit)
8795
}
96+
Error::__Nonexhaustive => unreachable!(),
8897
}
8998
}
9099
}

0 commit comments

Comments
 (0)