Skip to content

Commit 6e68098

Browse files
committed
syntax: remove '__Nonexhaustive' hack, use #[non_exhaustive]
This marks the various error types as '#[non_exhaustive]' instead of using a __Nonexhaustive variant hack. Closes #884
1 parent 23dd51e commit 6e68098

File tree

3 files changed

+12
-24
lines changed

3 files changed

+12
-24
lines changed

regex-syntax/src/ast/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ impl Error {
6464
}
6565

6666
/// The type of an error that occurred while building an AST.
67+
///
68+
/// This error type is marked as `non_exhaustive`. This means that adding a
69+
/// new variant is not considered a breaking change.
70+
#[non_exhaustive]
6771
#[derive(Clone, Debug, Eq, PartialEq)]
6872
pub enum ErrorKind {
6973
/// The capturing group limit was exceeded.
@@ -168,13 +172,6 @@ pub enum ErrorKind {
168172
/// `(?<!re)`. Note that all of these syntaxes are otherwise invalid; this
169173
/// error is used to improve the user experience.
170174
UnsupportedLookAround,
171-
/// Hints that destructuring should not be exhaustive.
172-
///
173-
/// This enum may grow additional variants, so this makes sure clients
174-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
175-
/// could break existing code.)
176-
#[doc(hidden)]
177-
__Nonexhaustive,
178175
}
179176

180177
impl std::error::Error for Error {}
@@ -270,7 +267,6 @@ impl fmt::Display for ErrorKind {
270267
"look-around, including look-ahead and look-behind, \
271268
is not supported"
272269
),
273-
_ => unreachable!(),
274270
}
275271
}
276272
}

regex-syntax/src/error.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use crate::hir;
99
pub type Result<T> = result::Result<T, Error>;
1010

1111
/// This error type encompasses any error that can be returned by this crate.
12+
///
13+
/// This error type is marked as `non_exhaustive`. This means that adding a
14+
/// new variant is not considered a breaking change.
15+
#[non_exhaustive]
1216
#[derive(Clone, Debug, Eq, PartialEq)]
1317
pub enum Error {
1418
/// An error that occurred while translating concrete syntax into abstract
@@ -17,13 +21,6 @@ pub enum Error {
1721
/// An error that occurred while translating abstract syntax into a high
1822
/// level intermediate representation (HIR).
1923
Translate(hir::Error),
20-
/// Hints that destructuring should not be exhaustive.
21-
///
22-
/// This enum may grow additional variants, so this makes sure clients
23-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
24-
/// could break existing code.)
25-
#[doc(hidden)]
26-
__Nonexhaustive,
2724
}
2825

2926
impl From<ast::Error> for Error {
@@ -45,7 +42,6 @@ impl fmt::Display for Error {
4542
match *self {
4643
Error::Parse(ref x) => x.fmt(f),
4744
Error::Translate(ref x) => x.fmt(f),
48-
_ => unreachable!(),
4945
}
5046
}
5147
}

regex-syntax/src/hir/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ impl Error {
5252
}
5353

5454
/// The type of an error that occurred while building an `Hir`.
55+
///
56+
/// This error type is marked as `non_exhaustive`. This means that adding a
57+
/// new variant is not considered a breaking change.
58+
#[non_exhaustive]
5559
#[derive(Clone, Debug, Eq, PartialEq)]
5660
pub enum ErrorKind {
5761
/// This error occurs when a Unicode feature is used when Unicode
@@ -80,13 +84,6 @@ pub enum ErrorKind {
8084
/// Note that this restriction in the translator may be removed in the
8185
/// future.
8286
EmptyClassNotAllowed,
83-
/// Hints that destructuring should not be exhaustive.
84-
///
85-
/// This enum may grow additional variants, so this makes sure clients
86-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
87-
/// could break existing code.)
88-
#[doc(hidden)]
89-
__Nonexhaustive,
9087
}
9188

9289
// BREADCRUMBS:
@@ -122,7 +119,6 @@ impl fmt::Display for ErrorKind {
122119
(make sure the unicode-case feature is enabled)"
123120
}
124121
EmptyClassNotAllowed => "empty character classes are not allowed",
125-
__Nonexhaustive => unreachable!(),
126122
};
127123
f.write_str(msg)
128124
}

0 commit comments

Comments
 (0)