From 3106de5f2a0983f617433d6e3429ff1a90d71f8d Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 23 Jan 2021 19:40:29 -0500 Subject: [PATCH] Remove struct_type from union output and bump format --- src/librustdoc/json/conversions.rs | 7 +++---- src/librustdoc/json/mod.rs | 2 +- src/rustdoc-json-types/lib.rs | 10 +++++++++- src/test/rustdoc-json/unions/union.rs | 7 +++++++ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/test/rustdoc-json/unions/union.rs diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index b2e5c8834b8..9c4d3becbda 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -154,7 +154,7 @@ fn from(item: clean::ItemKind) -> Self { } ImportItem(i) => ItemEnum::ImportItem(i.into()), StructItem(s) => ItemEnum::StructItem(s.into()), - UnionItem(u) => ItemEnum::StructItem(u.into()), + UnionItem(u) => ItemEnum::UnionItem(u.into()), StructFieldItem(f) => ItemEnum::StructFieldItem(f.into()), EnumItem(e) => ItemEnum::EnumItem(e.into()), VariantItem(v) => ItemEnum::VariantItem(v.into()), @@ -205,11 +205,10 @@ fn from(struct_: clean::Struct) -> Self { } } -impl From for Struct { +impl From for Union { fn from(struct_: clean::Union) -> Self { let clean::Union { generics, fields, fields_stripped } = struct_; - Struct { - struct_type: StructType::Union, + Union { generics: generics.into(), fields_stripped, fields: ids(fields), diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index a7c875fb748..876b1b56dee 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -243,7 +243,7 @@ fn after_krate( ) }) .collect(), - format_version: 2, + format_version: 3, }; let mut p = self.out_path.clone(); p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 3fb2a32d5a0..083f99e4a68 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -194,6 +194,7 @@ pub enum ItemEnum { }, ImportItem(Import), + UnionItem(Union), StructItem(Struct), StructFieldItem(Type), EnumItem(Enum), @@ -238,6 +239,14 @@ pub struct Module { pub items: Vec, } +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +pub struct Union { + pub generics: Generics, + pub fields_stripped: bool, + pub fields: Vec, + pub impls: Vec, +} + #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct Struct { pub struct_type: StructType, @@ -270,7 +279,6 @@ pub enum StructType { Plain, Tuple, Unit, - Union, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] diff --git a/src/test/rustdoc-json/unions/union.rs b/src/test/rustdoc-json/unions/union.rs new file mode 100644 index 00000000000..ac2eb797791 --- /dev/null +++ b/src/test/rustdoc-json/unions/union.rs @@ -0,0 +1,7 @@ +// @has union.json "$.index[*][?(@.name=='Union')].visibility" \"public\" +// @has - "$.index[*][?(@.name=='Union')].kind" \"union\" +// @!has - "$.index[*][?(@.name=='Union')].inner.struct_type" +pub union Union { + int: i32, + float: f32, +}