Skip to content

Commit 9d1211e

Browse files
committed
use #[non_exhaustive] attribute instead of __Nonexhaustive enum variant hack
1 parent 67824c7 commit 9d1211e

File tree

4 files changed

+4
-37
lines changed

4 files changed

+4
-37
lines changed

regex-syntax/src/ast/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl Error {
6666

6767
/// The type of an error that occurred while building an AST.
6868
#[derive(Clone, Debug, Eq, PartialEq)]
69+
#[non_exhaustive]
6970
pub enum ErrorKind {
7071
/// The capturing group limit was exceeded.
7172
///
@@ -169,13 +170,6 @@ pub enum ErrorKind {
169170
/// `(?<!re)`. Note that all of these syntaxes are otherwise invalid; this
170171
/// error is used to improve the user experience.
171172
UnsupportedLookAround,
172-
/// Hints that destructuring should not be exhaustive.
173-
///
174-
/// This enum may grow additional variants, so this makes sure clients
175-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
176-
/// could break existing code.)
177-
#[doc(hidden)]
178-
__Nonexhaustive,
179173
}
180174

181175
impl error::Error for Error {
@@ -310,7 +304,6 @@ impl fmt::Display for ErrorKind {
310304
"look-around, including look-ahead and look-behind, \
311305
is not supported"
312306
),
313-
_ => unreachable!(),
314307
}
315308
}
316309
}

regex-syntax/src/error.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@ pub type Result<T> = result::Result<T, Error>;
1111

1212
/// This error type encompasses any error that can be returned by this crate.
1313
#[derive(Clone, Debug, Eq, PartialEq)]
14+
#[non_exhaustive]
1415
pub enum Error {
1516
/// An error that occurred while translating concrete syntax into abstract
1617
/// syntax (AST).
1718
Parse(ast::Error),
1819
/// An error that occurred while translating abstract syntax into a high
1920
/// level intermediate representation (HIR).
2021
Translate(hir::Error),
21-
/// Hints that destructuring should not be exhaustive.
22-
///
23-
/// This enum may grow additional variants, so this makes sure clients
24-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
25-
/// could break existing code.)
26-
#[doc(hidden)]
27-
__Nonexhaustive,
2822
}
2923

3024
impl From<ast::Error> for Error {
@@ -46,7 +40,6 @@ impl error::Error for Error {
4640
match *self {
4741
Error::Parse(ref x) => x.description(),
4842
Error::Translate(ref x) => x.description(),
49-
_ => unreachable!(),
5043
}
5144
}
5245
}
@@ -56,7 +49,6 @@ impl fmt::Display for Error {
5649
match *self {
5750
Error::Parse(ref x) => x.fmt(f),
5851
Error::Translate(ref x) => x.fmt(f),
59-
_ => unreachable!(),
6052
}
6153
}
6254
}

regex-syntax/src/hir/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl Error {
5454

5555
/// The type of an error that occurred while building an `Hir`.
5656
#[derive(Clone, Debug, Eq, PartialEq)]
57+
#[non_exhaustive]
5758
pub enum ErrorKind {
5859
/// This error occurs when a Unicode feature is used when Unicode
5960
/// support is disabled. For example `(?-u:\pL)` would trigger this error.
@@ -81,13 +82,6 @@ pub enum ErrorKind {
8182
/// Note that this restriction in the translator may be removed in the
8283
/// future.
8384
EmptyClassNotAllowed,
84-
/// Hints that destructuring should not be exhaustive.
85-
///
86-
/// This enum may grow additional variants, so this makes sure clients
87-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
88-
/// could break existing code.)
89-
#[doc(hidden)]
90-
__Nonexhaustive,
9185
}
9286

9387
impl ErrorKind {
@@ -109,7 +103,6 @@ impl ErrorKind {
109103
(make sure the unicode-case feature is enabled)"
110104
}
111105
EmptyClassNotAllowed => "empty character classes are not allowed",
112-
__Nonexhaustive => unreachable!(),
113106
}
114107
}
115108
}

src/error.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@ use std::iter::repeat;
33

44
/// An error that occurred during parsing or compiling a regular expression.
55
#[derive(Clone, PartialEq)]
6+
#[non_exhaustive]
67
pub enum Error {
78
/// A syntax error.
89
Syntax(String),
910
/// The compiled program exceeded the set size limit.
1011
/// The argument is the size limit imposed.
1112
CompiledTooBig(usize),
12-
/// Hints that destructuring should not be exhaustive.
13-
///
14-
/// This enum may grow additional variants, so this makes sure clients
15-
/// don't count on exhaustive matching. (Otherwise, adding a new variant
16-
/// could break existing code.)
17-
#[doc(hidden)]
18-
__Nonexhaustive,
1913
}
2014

2115
impl ::std::error::Error for Error {
@@ -25,7 +19,6 @@ impl ::std::error::Error for Error {
2519
match *self {
2620
Error::Syntax(ref err) => err,
2721
Error::CompiledTooBig(_) => "compiled program too big",
28-
Error::__Nonexhaustive => unreachable!(),
2922
}
3023
}
3124
}
@@ -39,7 +32,6 @@ impl fmt::Display for Error {
3932
"Compiled regex exceeds size limit of {} bytes.",
4033
limit
4134
),
42-
Error::__Nonexhaustive => unreachable!(),
4335
}
4436
}
4537
}
@@ -63,9 +55,6 @@ impl fmt::Debug for Error {
6355
Error::CompiledTooBig(limit) => {
6456
f.debug_tuple("CompiledTooBig").field(&limit).finish()
6557
}
66-
Error::__Nonexhaustive => {
67-
f.debug_tuple("__Nonexhaustive").finish()
68-
}
6958
}
7059
}
7160
}

0 commit comments

Comments
 (0)