diff options
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/lib.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 36a8bb5..c33fcba 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs | |||
@@ -53,12 +53,16 @@ fn generate_self_impl(struct_name: &Ident) -> TokenStream2 { | |||
53 | fn generate_meta_impl(struct_name: &Ident, meta: &LintMeta) -> TokenStream2 { | 53 | fn generate_meta_impl(struct_name: &Ident, meta: &LintMeta) -> TokenStream2 { |
54 | let name_fn = generate_name_fn(meta); | 54 | let name_fn = generate_name_fn(meta); |
55 | let note_fn = generate_note_fn(meta); | 55 | let note_fn = generate_note_fn(meta); |
56 | let code_fn = generate_code_fn(meta); | ||
57 | let report_fn = generate_report_fn(); | ||
56 | let match_with_fn = generate_match_with_fn(meta); | 58 | let match_with_fn = generate_match_with_fn(meta); |
57 | let match_kind = generate_match_kind(meta); | 59 | let match_kind = generate_match_kind(meta); |
58 | quote! { | 60 | quote! { |
59 | impl Metadata for #struct_name { | 61 | impl Metadata for #struct_name { |
60 | #name_fn | 62 | #name_fn |
61 | #note_fn | 63 | #note_fn |
64 | #code_fn | ||
65 | #report_fn | ||
62 | #match_with_fn | 66 | #match_with_fn |
63 | #match_kind | 67 | #match_kind |
64 | } | 68 | } |
@@ -99,6 +103,31 @@ fn generate_note_fn(meta: &LintMeta) -> TokenStream2 { | |||
99 | panic!("Invalid value for `note`"); | 103 | panic!("Invalid value for `note`"); |
100 | } | 104 | } |
101 | 105 | ||
106 | fn generate_code_fn(meta: &LintMeta) -> TokenStream2 { | ||
107 | let code = meta | ||
108 | .0 | ||
109 | .get(&format_ident!("code")) | ||
110 | .unwrap_or_else(|| panic!("`code` not present")); | ||
111 | if let syn::Expr::Lit(code_lit) = code { | ||
112 | if let Lit::Int(code_int) = &code_lit.lit { | ||
113 | return quote! { | ||
114 | fn code() -> u32 { | ||
115 | #code_int | ||
116 | } | ||
117 | }; | ||
118 | } | ||
119 | } | ||
120 | panic!("Invalid value for `note`"); | ||
121 | } | ||
122 | |||
123 | fn generate_report_fn() -> TokenStream2 { | ||
124 | quote! { | ||
125 | fn report() -> Report { | ||
126 | Report::new(Self::note(), Self::code()) | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | |||
102 | fn generate_match_with_fn(meta: &LintMeta) -> TokenStream2 { | 131 | fn generate_match_with_fn(meta: &LintMeta) -> TokenStream2 { |
103 | let match_with_lit = meta | 132 | let match_with_lit = meta |
104 | .0 | 133 | .0 |