Skip to content

Commit f04a9a7

Browse files
committed
added hidden nonexaustive variant
fixes rust-lang-deprecated#182
1 parent c723ff7 commit f04a9a7

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- [Add a new method for `Error`: `chain_err`.](https://github.com/brson/error-chain/pull/141)
44
- [Allow `chain_err` to be used on `Option<T>`](https://github.com/brson/error-chain/pull/156)
55
- [Add support for creating an error chain on boxed trait errors (`Box<Error>`)](https://github.com/brson/error-chain/pull/156)
6+
- [Generated `ErrorKind` enums are now nonexaustive](https://github.com/brson/error-chain/pull/193)
67

78
# 0.10.0
89

@@ -15,7 +16,7 @@
1516

1617
# 0.8.1
1718

18-
- Add crates.io categorie.
19+
- Add crates.io category.
1920

2021
# 0.8.0
2122

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@
331331
//!
332332
//! error-chain error variants are matched with simple patterns.
333333
//! `Error` is a tuple struct and its first field is the `ErrorKind`,
334-
//! making dispatching on error kinds relatively compact:
334+
//! making dispatching on error kinds relatively compact. Note that
335+
//! because `ErrorKind` is open and always extensible, you always need
336+
//! to handle the unknown case:
335337
//!
336338
//! ```
337339
//! # #[macro_use] extern crate error_chain;
@@ -348,6 +350,7 @@
348350
//! match Error::from("error!") {
349351
//! Error(ErrorKind::InvalidToolchainName(_), _) => { }
350352
//! Error(ErrorKind::Msg(_), _) => { }
353+
//! _ => { }
351354
//! }
352355
//! # }
353356
//! ```

src/quick_error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ macro_rules! quick_error {
200200
$(#[$imeta])*
201201
$iitem $(($( $ttyp ),*))* $({$( $svar: $styp ),*})*,
202202
)*
203+
204+
#[doc(hidden)]
205+
__Nonexhaustive {}
203206
}
204207
};
205208
// Private enum (Queue Empty)
@@ -278,6 +281,8 @@ macro_rules! quick_error {
278281
display_fn(self, fmt)
279282
}
280283
)*
284+
285+
_ => Ok(())
281286
}
282287
}
283288
}
@@ -325,6 +330,8 @@ macro_rules! quick_error {
325330
{$( $funcs )*})
326331
}
327332
)*
333+
334+
_ => "",
328335
}
329336
}
330337
}

tests/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ fn error_patterns() {
490490

491491
// Tuples look nice when matching errors
492492
match Error::from("Test") {
493-
Error(ErrorKind::Msg(_), _) => {}
493+
Error(ErrorKind::Msg(_), _) => {},
494+
_ => {},
494495
}
495496
}
496497

0 commit comments

Comments
 (0)