From 540f95d9fad41a605e4c8b898d77f47374a76cbd Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 24 Jan 2018 11:50:30 +0530 Subject: Add internal-only rustc_serialize_exclude_null attribute for making the field only exist in the json if the flag is passed --- src/libsyntax/feature_gate.rs | 5 +++++ src/libsyntax/json.rs | 2 ++ src/libsyntax/lib.rs | 1 + 3 files changed, 8 insertions(+) (limited to 'src/libsyntax') diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9a2560b0458..3e523fca92a 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -788,6 +788,11 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG is just used for rustc unit tests \ and will never be stable", cfg_fn!(rustc_attrs))), + ("rustc_serialize_exclude_null", Normal, Gated(Stability::Unstable, + "rustc_attrs", + "the `#[rustc_serialize_exclude_null]` attribute \ + is an internal-only feature", + cfg_fn!(rustc_attrs))), ("rustc_synthetic", Whitelisted, Gated(Stability::Unstable, "rustc_attrs", "this attribute \ diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index 7a8717ada4c..681e14a6137 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -108,6 +108,7 @@ struct Diagnostic { } #[derive(RustcEncodable)] +#[allow(unused_attributes)] struct DiagnosticSpan { file_name: String, byte_start: u32, @@ -129,6 +130,7 @@ struct DiagnosticSpan { /// that should be sliced in atop this span. suggested_replacement: Option, /// If the suggestion is approximate + #[rustc_serialize_exclude_null] suggestion_approximate: Option, /// Macro invocations that created the code at this span, if any. expansion: Option>, diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 3b4c5da10f2..9181cca215c 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -25,6 +25,7 @@ #![feature(match_default_bindings)] #![feature(i128_type)] #![feature(const_atomic_usize_new)] +#![feature(rustc_attrs)] // See librustc_cratesio_shim/Cargo.toml for a comment explaining this. #[allow(unused_extern_crates)] -- cgit 1.4.1-3-g733a5