Skip to content

Commit 4c1b0c2

Browse files
authored
Merge pull request #3061 from mehcode/feature/default-edition
Fix help message for edition config option
2 parents 3dc6eed + c7377c3 commit 4c1b0c2

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/config/options.rs

+26-12
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ use isatty::stdout_isatty;
1717
use std::collections::HashSet;
1818
use std::path::{Path, PathBuf};
1919

20-
/// Macro for deriving implementations of Serialize/Deserialize for enums
20+
/// Macro that will stringify the enum variants or a provided textual repr
2121
#[macro_export]
22-
macro_rules! impl_enum_serialize_and_deserialize {
23-
(@stringify $variant:ident) => (
22+
macro_rules! configuration_option_enum_stringify {
23+
($variant:ident) => {
2424
stringify!($variant)
25-
);
25+
};
2626

27-
(@stringify $_variant:ident: $value:expr) => (
27+
($_variant:ident: $value:expr) => {
2828
stringify!($value)
29-
);
29+
};
30+
}
3031

32+
/// Macro for deriving implementations of Serialize/Deserialize for enums
33+
#[macro_export]
34+
macro_rules! impl_enum_serialize_and_deserialize {
3135
( $e:ident, $( $variant:ident $(: $value:expr)* ),* ) => {
3236
impl ::serde::ser::Serialize for $e {
3337
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
@@ -40,7 +44,7 @@ macro_rules! impl_enum_serialize_and_deserialize {
4044
match *self {
4145
$(
4246
$e::$variant => serializer.serialize_str(
43-
impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
47+
configuration_option_enum_stringify!($variant $(: $value)*)
4448
),
4549
)*
4650
_ => {
@@ -69,13 +73,13 @@ macro_rules! impl_enum_serialize_and_deserialize {
6973
}
7074
let s = d.deserialize_string(StringOnly::<D>(PhantomData))?;
7175
$(
72-
if impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
76+
if configuration_option_enum_stringify!($variant $(: $value)*)
7377
.eq_ignore_ascii_case(&s) {
7478
return Ok($e::$variant);
7579
}
7680
)*
7781
static ALLOWED: &'static[&str] = &[
78-
$(impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*),)*];
82+
$(configuration_option_enum_stringify!($variant $(: $value)*),)*];
7983
Err(D::Error::unknown_variant(&s, ALLOWED))
8084
}
8185
}
@@ -85,7 +89,7 @@ macro_rules! impl_enum_serialize_and_deserialize {
8589

8690
fn from_str(s: &str) -> Result<Self, Self::Err> {
8791
$(
88-
if impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
92+
if configuration_option_enum_stringify!($variant $(: $value)*)
8993
.eq_ignore_ascii_case(s) {
9094
return Ok($e::$variant);
9195
}
@@ -99,7 +103,7 @@ macro_rules! impl_enum_serialize_and_deserialize {
99103
let mut variants = Vec::new();
100104
$(
101105
variants.push(
102-
impl_enum_serialize_and_deserialize!(@stringify $variant $(: $value)*)
106+
configuration_option_enum_stringify!($variant $(: $value)*)
103107
);
104108
)*
105109
format!("[{}]", variants.join("|"))
@@ -110,11 +114,21 @@ macro_rules! impl_enum_serialize_and_deserialize {
110114

111115
macro_rules! configuration_option_enum {
112116
($e:ident: $( $name:ident $(: $value:expr)* ),+ $(,)*) => (
113-
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
117+
#[derive(Copy, Clone, Eq, PartialEq)]
114118
pub enum $e {
115119
$( $name ),+
116120
}
117121

122+
impl ::std::fmt::Debug for $e {
123+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
124+
f.write_str(match self {
125+
$(
126+
$e::$name => configuration_option_enum_stringify!($name $(: $value)*),
127+
)+
128+
})
129+
}
130+
}
131+
118132
impl_enum_serialize_and_deserialize!($e, $( $name $(: $value)* ),+);
119133
);
120134
}

0 commit comments

Comments
 (0)