Skip to content

Commit ea7274b

Browse files
authored
Rollup merge of rust-lang#81500 - CraftSpider:union-kind, r=jyn514
Remove struct_type from union output Also bumps the format number and adds a test Rationale: It's illegal to have unions of the form `union Union(i32, f32);`, or `union Union;`. The struct_type field was recently removed from the rustdoc Union AST, at which time this field was changed to always just read "union". It makes sense to completely remove it, as it provides no information.
2 parents 0cc179f + 3106de5 commit ea7274b

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/librustdoc/json/conversions.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl From<clean::ItemKind> for ItemEnum {
154154
}
155155
ImportItem(i) => ItemEnum::ImportItem(i.into()),
156156
StructItem(s) => ItemEnum::StructItem(s.into()),
157-
UnionItem(u) => ItemEnum::StructItem(u.into()),
157+
UnionItem(u) => ItemEnum::UnionItem(u.into()),
158158
StructFieldItem(f) => ItemEnum::StructFieldItem(f.into()),
159159
EnumItem(e) => ItemEnum::EnumItem(e.into()),
160160
VariantItem(v) => ItemEnum::VariantItem(v.into()),
@@ -205,11 +205,10 @@ impl From<clean::Struct> for Struct {
205205
}
206206
}
207207

208-
impl From<clean::Union> for Struct {
208+
impl From<clean::Union> for Union {
209209
fn from(struct_: clean::Union) -> Self {
210210
let clean::Union { generics, fields, fields_stripped } = struct_;
211-
Struct {
212-
struct_type: StructType::Union,
211+
Union {
213212
generics: generics.into(),
214213
fields_stripped,
215214
fields: ids(fields),

src/librustdoc/json/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
243243
)
244244
})
245245
.collect(),
246-
format_version: 2,
246+
format_version: 3,
247247
};
248248
let mut p = self.out_path.clone();
249249
p.push(output.index.get(&output.root).unwrap().name.clone().unwrap());

src/rustdoc-json-types/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ pub enum ItemEnum {
194194
},
195195
ImportItem(Import),
196196

197+
UnionItem(Union),
197198
StructItem(Struct),
198199
StructFieldItem(Type),
199200
EnumItem(Enum),
@@ -238,6 +239,14 @@ pub struct Module {
238239
pub items: Vec<Id>,
239240
}
240241

242+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
243+
pub struct Union {
244+
pub generics: Generics,
245+
pub fields_stripped: bool,
246+
pub fields: Vec<Id>,
247+
pub impls: Vec<Id>,
248+
}
249+
241250
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
242251
pub struct Struct {
243252
pub struct_type: StructType,
@@ -270,7 +279,6 @@ pub enum StructType {
270279
Plain,
271280
Tuple,
272281
Unit,
273-
Union,
274282
}
275283

276284
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]

src/test/rustdoc-json/unions/union.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @has union.json "$.index[*][?(@.name=='Union')].visibility" \"public\"
2+
// @has - "$.index[*][?(@.name=='Union')].kind" \"union\"
3+
// @!has - "$.index[*][?(@.name=='Union')].inner.struct_type"
4+
pub union Union {
5+
int: i32,
6+
float: f32,
7+
}

0 commit comments

Comments
 (0)