@@ -188,11 +188,24 @@ struct Diagnostic {
188
188
}
189
189
190
190
macro_rules! encode_fields {
191
- ( $enc: expr, $s: expr, $idx: expr, [ $( $name: ident) ,+$( , ) ? ] ) => {
191
+ (
192
+ $enc: expr, // encoder
193
+ $idx: expr, // starting field index
194
+ $struct: expr, // struct we're serializing
195
+ $struct_name: ident, // struct name
196
+ [ $( $name: ident) ,+$( , ) ? ] , // fields to encode
197
+ [ $( $ignore: ident) ,+$( , ) ? ] // fields we're skipping
198
+ ) => {
192
199
{
200
+ // Pattern match to make sure all fields are accounted for
201
+ let $struct_name { $( $name, ) + $( $ignore: _, ) + } = $struct;
193
202
let mut idx = $idx;
194
203
$(
195
- $enc. emit_struct_field( stringify!( $name) , idx, |enc| $s. $name. encode( enc) ) ?;
204
+ $enc. emit_struct_field(
205
+ stringify!( $name) ,
206
+ idx,
207
+ |enc| $name. encode( enc) ,
208
+ ) ?;
196
209
idx += 1 ;
197
210
) +
198
211
idx
@@ -206,9 +219,23 @@ impl<E: Encoder> Encodable<E> for Diagnostic {
206
219
s. emit_struct ( "diagnostic" , 7 , |s| {
207
220
let mut idx = 0 ;
208
221
209
- idx = encode_fields ! ( s, self , idx, [ message, code, level, spans, children, rendered] ) ;
222
+ idx = encode_fields ! (
223
+ s,
224
+ idx,
225
+ self ,
226
+ Self ,
227
+ [ message, code, level, spans, children, rendered] ,
228
+ [ tool_metadata]
229
+ ) ;
210
230
if self . tool_metadata . is_set ( ) {
211
- idx = encode_fields ! ( s, self , idx, [ tool_metadata] ) ;
231
+ idx = encode_fields ! (
232
+ s,
233
+ idx,
234
+ self ,
235
+ Self ,
236
+ [ tool_metadata] ,
237
+ [ message, code, level, spans, children, rendered]
238
+ ) ;
212
239
}
213
240
214
241
let _ = idx;
0 commit comments