Skip to content

Commit

Permalink
syntax: remove '__Nonexhaustive' hack, use #[non_exhaustive]
Browse files Browse the repository at this point in the history
This marks the various error types as '#[non_exhaustive]' instead of
using a __Nonexhaustive variant hack.

Closes #884
  • Loading branch information
BurntSushi committed Nov 5, 2022
1 parent e0e4746 commit d6e936b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
12 changes: 4 additions & 8 deletions regex-syntax/src/ast/mod.rs
Expand Up @@ -64,6 +64,10 @@ impl Error {
}

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

impl std::error::Error for Error {}
Expand Down Expand Up @@ -270,7 +267,6 @@ impl fmt::Display for ErrorKind {
"look-around, including look-ahead and look-behind, \
is not supported"
),
_ => unreachable!(),
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions regex-syntax/src/error.rs
Expand Up @@ -9,6 +9,10 @@ use crate::hir;
pub type Result<T> = result::Result<T, Error>;

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

impl From<ast::Error> for Error {
Expand All @@ -45,7 +42,6 @@ impl fmt::Display for Error {
match *self {
Error::Parse(ref x) => x.fmt(f),
Error::Translate(ref x) => x.fmt(f),
_ => unreachable!(),
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions regex-syntax/src/hir/mod.rs
Expand Up @@ -52,6 +52,10 @@ impl Error {
}

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

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

0 comments on commit d6e936b

Please sign in to comment.