Make sure all fields are accounted for in encode_fields!
This will make sure the encoder will get updated if any new fields are added to Diagnostic.
This commit is contained in:
parent
50572d6629
commit
91d8c3b521
1 changed files with 31 additions and 4 deletions
|
@ -188,11 +188,24 @@ struct Diagnostic {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! encode_fields {
|
macro_rules! encode_fields {
|
||||||
($enc:expr, $s:expr, $idx:expr, [ $($name:ident),+$(,)? ]) => {
|
(
|
||||||
|
$enc:expr, // encoder
|
||||||
|
$idx:expr, // starting field index
|
||||||
|
$struct:expr, // struct we're serializing
|
||||||
|
$struct_name:ident, // struct name
|
||||||
|
[ $($name:ident),+$(,)? ], // fields to encode
|
||||||
|
[ $($ignore:ident),+$(,)? ] // fields we're skipping
|
||||||
|
) => {
|
||||||
{
|
{
|
||||||
|
// Pattern match to make sure all fields are accounted for
|
||||||
|
let $struct_name { $($name,)+ $($ignore: _,)+ } = $struct;
|
||||||
let mut idx = $idx;
|
let mut idx = $idx;
|
||||||
$(
|
$(
|
||||||
$enc.emit_struct_field(stringify!($name), idx, |enc| $s.$name.encode(enc))?;
|
$enc.emit_struct_field(
|
||||||
|
stringify!($name),
|
||||||
|
idx,
|
||||||
|
|enc| $name.encode(enc),
|
||||||
|
)?;
|
||||||
idx += 1;
|
idx += 1;
|
||||||
)+
|
)+
|
||||||
idx
|
idx
|
||||||
|
@ -206,9 +219,23 @@ impl<E: Encoder> Encodable<E> for Diagnostic {
|
||||||
s.emit_struct("diagnostic", 7, |s| {
|
s.emit_struct("diagnostic", 7, |s| {
|
||||||
let mut idx = 0;
|
let mut idx = 0;
|
||||||
|
|
||||||
idx = encode_fields!(s, self, idx, [message, code, level, spans, children, rendered]);
|
idx = encode_fields!(
|
||||||
|
s,
|
||||||
|
idx,
|
||||||
|
self,
|
||||||
|
Self,
|
||||||
|
[message, code, level, spans, children, rendered],
|
||||||
|
[tool_metadata]
|
||||||
|
);
|
||||||
if self.tool_metadata.is_set() {
|
if self.tool_metadata.is_set() {
|
||||||
idx = encode_fields!(s, self, idx, [tool_metadata]);
|
idx = encode_fields!(
|
||||||
|
s,
|
||||||
|
idx,
|
||||||
|
self,
|
||||||
|
Self,
|
||||||
|
[tool_metadata],
|
||||||
|
[message, code, level, spans, children, rendered]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = idx;
|
let _ = idx;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue