From b419ee9c6809d1e4081c885380fbf8c8103dad49 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 23 Oct 2018 15:40:38 +0200 Subject: do_trial(): Fix unreachable `DurationError` patterns I was getting these warnings: warning: unreachable pattern --> src/trial.rs:41:17 | 40 | DurationError => return trial_expired(), | ------------- matches any value 41 | e => { | ^ unreachable pattern warning: unreachable pattern --> src/trial.rs:55:9 | 54 | DurationError => trial_expired(), | ------------- matches any value 55 | Err(e) => (), | ^^^^^^ unreachable pattern Wasn't correctly matching the `DurationError`s. Add an 'error-chain' `ErrorKind` for `DurationError` to make it the same type as the others matched in the first `match` pattern. --- src/errors.rs | 1 + src/trial.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/errors.rs b/src/errors.rs index f84bb2e..75079e3 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -8,6 +8,7 @@ error_chain! { Io(::std::io::Error); DateCrypt(DateCryptError); + Duration(DurationError); } } diff --git a/src/trial.rs b/src/trial.rs index 2b535a7..38c8a82 100644 --- a/src/trial.rs +++ b/src/trial.rs @@ -31,7 +31,7 @@ fn do_trial() { ::std::process::exit(exitcode::IOERR); }, }, - DurationError => return trial_expired(), + ErrorKind::Duration(_) => return trial_expired(), e => { eprintln!("{}", e); ::std::process::exit(exitcode::SOFTWARE); @@ -45,8 +45,11 @@ fn do_trial() { match days_remaining_from_now(date) { Ok(remaining) => print_trial_days(remaining), - DurationError => trial_expired(), - Err(e) => (), + Err(e) => { + match e { + DurationError::NegativeDuration(_) => trial_expired(), + } + }, } } -- cgit v1.2.3