Skip to content

Commit 636e22f

Browse files
committed
fix empty struct
1 parent 813c49a commit 636e22f

File tree

4 files changed

+141
-95
lines changed

4 files changed

+141
-95
lines changed

macro/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use proc_macro2::TokenStream;
22
use proc_macro_error::{abort_call_site, proc_macro_error, ResultExt};
33
use quote::format_ident;
4+
use quote_use::quote_use as quote;
5+
use syn::punctuated::Punctuated;
46
use syn::{
5-
parse_macro_input, punctuated::Punctuated, DataStruct, DeriveInput, Field, Fields, FieldsNamed,
6-
Lit, Meta, MetaNameValue, NestedMeta, Token,
7+
parse_macro_input, DataStruct, DeriveInput, Field, Fields, FieldsNamed, Lit, Meta,
8+
MetaNameValue, NestedMeta, Token,
79
};
810

9-
use quote_use::quote_use as quote;
10-
1111
// TODO generally should use fully qualified names for trait function calls
1212

1313
#[proc_macro_error]
@@ -30,7 +30,7 @@ pub fn attribute_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre
3030
.into_iter()
3131
.filter(|attribute| attribute.path.is_ident("attribute"))
3232
{
33-
const VALID_FORMAT: &str = r#"Expected `#[attribute(ident="name_of_your_attribute", invalid_field="error message")]`"#;
33+
const VALID_FORMAT: &str = r#"Expected `#[attribute(ident="name_of_your_attribute", invalid_field="error message", missing="error messag", conflicts(a, b)")]`"#;
3434
let meta: Meta = attribute.parse_meta().unwrap_or_abort();
3535
if let Meta::List(meta) = meta {
3636
for meta in meta.nested {
@@ -208,16 +208,16 @@ pub fn attribute_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStre
208208
_ => abort_call_site!("Only works on structs with named fields"),
209209
};
210210

211-
let error_invalid_name = invalid_field.unwrap_or_else(|| {
212-
if possible_variables.len() > 1 {
211+
let error_invalid_name = invalid_field.unwrap_or_else(|| match possible_variables.len() {
212+
0 => format!("Expected empty attribute"),
213+
1 => format!("Expected supported field {}", possible_variables[0]),
214+
_ => {
213215
let last = possible_variables.pop().unwrap();
214216
format!(
215217
"Supported fields are {} and {}",
216218
possible_variables.join(", "),
217219
last
218220
)
219-
} else {
220-
format!("Expected supported field {}", possible_variables[0])
221221
}
222222
});
223223

rustfmt.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
condense_wildcard_suffixes = true
2+
format_code_in_doc_comments = true
3+
format_macro_matchers = true
4+
format_strings = true
5+
hex_literal_case = "Upper"
6+
imports_granularity = "Module"
7+
normalize_comments = true
8+
normalize_doc_attributes = true
9+
overflow_delimited_expr = true
10+
reorder_impl_items = true
11+
group_imports = "StdExternalCrate"
12+
unstable_features = true
13+
use_field_init_shorthand = true
14+
version = "Two"
15+
wrap_comments = true

0 commit comments

Comments
 (0)