These match-expressions are implementing unwrap_or_else

This commit is contained in:
David Tolnay 2018-06-02 22:08:01 -07:00
parent 6d31ec521b
commit 57de28744c
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -29,7 +29,7 @@
feature = "cargo-clippy",
allow(
enum_variant_names, redundant_field_names, too_many_arguments, used_underscore_binding,
cyclomatic_complexity
cyclomatic_complexity, needless_pass_by_value
)
)]
// Whitelisted clippy_pedantic lints
@ -69,17 +69,21 @@ mod try;
#[proc_macro_derive(Serialize, attributes(serde))]
pub fn derive_serialize(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
match ser::expand_derive_serialize(&input) {
Ok(expanded) => expanded.into(),
Err(msg) => quote! {compile_error!(#msg);}.into(),
}
ser::expand_derive_serialize(&input)
.unwrap_or_else(compile_error)
.into()
}
#[proc_macro_derive(Deserialize, attributes(serde))]
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
let input: DeriveInput = syn::parse(input).unwrap();
match de::expand_derive_deserialize(&input) {
Ok(expanded) => expanded.into(),
Err(msg) => quote! {compile_error!(#msg);}.into(),
de::expand_derive_deserialize(&input)
.unwrap_or_else(compile_error)
.into()
}
fn compile_error(message: String) -> proc_macro2::TokenStream {
quote! {
compile_error!(#message);
}
}