diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 438a8d57cc22..026d8f96dee6 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -154,7 +154,7 @@ impl From for ItemEnum { } 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 @@ impl From for Struct { } } -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 a7c875fb7480..876b1b56dee6 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -243,7 +243,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { ) }) .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 3fb2a32d5a0a..083f99e4a681 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 000000000000..ac2eb797791f --- /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, +}