Skip to content

Commit

Permalink
Remove struct_type from union output and bump format
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Jan 29, 2021
1 parent 74500b9 commit 3106de5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl From<clean::ItemKind> 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()),
Expand Down Expand Up @@ -205,11 +205,10 @@ impl From<clean::Struct> for Struct {
}
}

impl From<clean::Union> for Struct {
impl From<clean::Union> 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),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
10 changes: 9 additions & 1 deletion src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub enum ItemEnum {
},
ImportItem(Import),

UnionItem(Union),
StructItem(Struct),
StructFieldItem(Type),
EnumItem(Enum),
Expand Down Expand Up @@ -238,6 +239,14 @@ pub struct Module {
pub items: Vec<Id>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Union {
pub generics: Generics,
pub fields_stripped: bool,
pub fields: Vec<Id>,
pub impls: Vec<Id>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Struct {
pub struct_type: StructType,
Expand Down Expand Up @@ -270,7 +279,6 @@ pub enum StructType {
Plain,
Tuple,
Unit,
Union,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
Expand Down
7 changes: 7 additions & 0 deletions src/test/rustdoc-json/unions/union.rs
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 3106de5

Please sign in to comment.