From 54256515b49595a2ac4c2b218e4ddbb5a4920d9b Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 10 Mar 2018 09:04:01 -0500 Subject: [PATCH] globset: make ErrorKind enum extensible This commit makes the ErrorKind enum extensible by adding a __Nonexhaustive variant. Callers should use this as a hint that exhaustive case analysis isn't possible in a stable way since new variants may be added in the future without a semver bump. --- globset/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/globset/src/lib.rs b/globset/src/lib.rs index fb95ce75..17292b06 100644 --- a/globset/src/lib.rs +++ b/globset/src/lib.rs @@ -163,6 +163,13 @@ pub enum ErrorKind { DanglingEscape, /// An error associated with parsing or compiling a regex. Regex(String), + /// 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 StdError for Error { @@ -210,6 +217,7 @@ impl ErrorKind { "dangling '\\'" } ErrorKind::Regex(ref err) => err, + ErrorKind::__Nonexhaustive => unreachable!(), } } } @@ -240,6 +248,7 @@ impl fmt::Display for ErrorKind { ErrorKind::InvalidRange(s, e) => { write!(f, "invalid range; '{}' > '{}'", s, e) } + ErrorKind::__Nonexhaustive => unreachable!(), } } }