diff options
| author | Jeremy Fitzhardinge <jeremy@goop.org> | 2021-02-06 20:29:04 -0800 |
|---|---|---|
| committer | Jeremy Fitzhardinge <jeremy@goop.org> | 2021-02-07 14:54:22 -0800 |
| commit | 91d8c3b521b95b64eec3329c2ddbddb2315024d9 (patch) | |
| tree | 76e9a003f0954641ce8317955602e6bd818e1842 /compiler/rustc_errors/src/json.rs | |
| parent | 50572d66295840ba13aee0cd500c20b9513e77f7 (diff) | |
| download | rust-91d8c3b521b95b64eec3329c2ddbddb2315024d9.tar.gz rust-91d8c3b521b95b64eec3329c2ddbddb2315024d9.zip | |
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.
Diffstat (limited to 'compiler/rustc_errors/src/json.rs')
| -rw-r--r-- | compiler/rustc_errors/src/json.rs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs index f26c439add9..c27b39a9d62 100644 --- a/compiler/rustc_errors/src/json.rs +++ b/compiler/rustc_errors/src/json.rs @@ -188,11 +188,24 @@ struct Diagnostic { } 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; $( - $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 @@ -206,9 +219,23 @@ impl<E: Encoder> Encodable<E> for Diagnostic { s.emit_struct("diagnostic", 7, |s| { 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() { - 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; |
