Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 0a5589e

Browse files
bennofsYamakaky
authored andcommitted
Allow , after description/display/... in errors section (#139)
* Allow , after description/display/... in errors section * Add example with comma to docs
1 parent d859531 commit 0a5589e

File tree

3 files changed

+53
-9
lines changed

3 files changed

+53
-9
lines changed

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@
155155
//! description("invalid toolchain name")
156156
//! display("invalid toolchain name: '{}'", t)
157157
//! }
158+
//!
159+
//! // You can also add commas after description/display.
160+
//! // This may work better with some editor auto-identation modes:
161+
//! UnknownToolchainVersion(v: String) {
162+
//! description("unknown toolchain version"), // note the ,
163+
//! display("unknown toolchain version: '{}'", v), // trailing comma is allowed
164+
//! }
158165
//! }
159166
//! }
160167
//!

src/quick_error.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -506,24 +506,28 @@ macro_rules! quick_error {
506506
// This is to contrast FIND_* clauses which just find stuff they need and
507507
// skip everything else completely
508508
(ERROR_CHECK $imode:tt display($self_:tt) -> ($( $exprs:tt )*) $( $tail:tt )*)
509-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
509+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
510510
(ERROR_CHECK $imode:tt display($pattern: expr) $( $tail:tt )*)
511-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
511+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
512512
(ERROR_CHECK $imode:tt display($pattern: expr, $( $exprs:tt )*) $( $tail:tt )*)
513-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
513+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
514514
(ERROR_CHECK $imode:tt description($expr:expr) $( $tail:tt )*)
515-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
515+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
516516
(ERROR_CHECK $imode:tt cause($expr:expr) $($tail:tt)*)
517-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
517+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
518518
(ERROR_CHECK $imode:tt from() $($tail:tt)*)
519-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
519+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
520520
(ERROR_CHECK $imode:tt from($ftyp:ty) $($tail:tt)*)
521-
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
521+
=> { quick_error!(ERROR_CHECK_COMMA $imode $($tail)*); };
522522
(ERROR_CHECK TUPLE from($fvar:ident: $ftyp:ty) -> ($( $e:expr ),*) $( $tail:tt )*)
523-
=> { quick_error!(ERROR_CHECK TUPLE $($tail)*); };
523+
=> { quick_error!(ERROR_CHECK_COMMA TUPLE $($tail)*); };
524524
(ERROR_CHECK STRUCT from($fvar:ident: $ftyp:ty) -> {$( $v:ident: $e:expr ),*} $( $tail:tt )*)
525-
=> { quick_error!(ERROR_CHECK STRUCT $($tail)*); };
525+
=> { quick_error!(ERROR_CHECK_COMMA STRUCT $($tail)*); };
526526
(ERROR_CHECK $imode:tt ) => {};
527+
(ERROR_CHECK_COMMA $imode:tt , $( $tail:tt )*)
528+
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
529+
(ERROR_CHECK_COMMA $imode:tt $( $tail:tt )*)
530+
=> { quick_error!(ERROR_CHECK $imode $($tail)*); };
527531
// Utility functions
528532
(IDENT $ident:ident) => { $ident }
529533
}

tests/tests.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,3 +593,36 @@ fn rewrapping() {
593593
);
594594

595595
}
596+
597+
#[test]
598+
fn comma_in_errors_impl() {
599+
error_chain! {
600+
links { }
601+
602+
foreign_links { }
603+
604+
errors {
605+
HttpStatus(e: u32) {
606+
description("http request returned an unsuccessful status code"),
607+
display("http request returned an unsuccessful status code: {}", e)
608+
}
609+
}
610+
};
611+
}
612+
613+
614+
#[test]
615+
fn trailing_comma_in_errors_impl() {
616+
error_chain! {
617+
links { }
618+
619+
foreign_links { }
620+
621+
errors {
622+
HttpStatus(e: u32) {
623+
description("http request returned an unsuccessful status code"),
624+
display("http request returned an unsuccessful status code: {}", e),
625+
}
626+
}
627+
};
628+
}

0 commit comments

Comments
 (0)