Skip to content

Commit 97b736c

Browse files
Rollup merge of #81033 - jyn514:nested-variant, r=CraftSpider
Remove useless `clean::Variant` struct It had exactly one field and no special behavior, so there was no point in having it. r? `@CraftSpider`
2 parents 38772f1 + d11855a commit 97b736c

File tree

6 files changed

+33
-47
lines changed

6 files changed

+33
-47
lines changed

src/librustdoc/clean/mod.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -1840,11 +1840,11 @@ impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
18401840
impl Clean<Item> for ty::VariantDef {
18411841
fn clean(&self, cx: &DocContext<'_>) -> Item {
18421842
let kind = match self.ctor_kind {
1843-
CtorKind::Const => VariantKind::CLike,
1844-
CtorKind::Fn => VariantKind::Tuple(
1843+
CtorKind::Const => Variant::CLike,
1844+
CtorKind::Fn => Variant::Tuple(
18451845
self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(),
18461846
),
1847-
CtorKind::Fictive => VariantKind::Struct(VariantStruct {
1847+
CtorKind::Fictive => Variant::Struct(VariantStruct {
18481848
struct_type: doctree::Plain,
18491849
fields_stripped: false,
18501850
fields: self
@@ -1861,25 +1861,21 @@ impl Clean<Item> for ty::VariantDef {
18611861
.collect(),
18621862
}),
18631863
};
1864-
let what_rustc_thinks = Item::from_def_id_and_parts(
1865-
self.def_id,
1866-
Some(self.ident.name),
1867-
VariantItem(Variant { kind }),
1868-
cx,
1869-
);
1864+
let what_rustc_thinks =
1865+
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), VariantItem(kind), cx);
18701866
// don't show `pub` for fields, which are always public
18711867
Item { visibility: Inherited, ..what_rustc_thinks }
18721868
}
18731869
}
18741870

1875-
impl Clean<VariantKind> for hir::VariantData<'_> {
1876-
fn clean(&self, cx: &DocContext<'_>) -> VariantKind {
1871+
impl Clean<Variant> for hir::VariantData<'_> {
1872+
fn clean(&self, cx: &DocContext<'_>) -> Variant {
18771873
match self {
1878-
hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)),
1874+
hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)),
18791875
hir::VariantData::Tuple(..) => {
1880-
VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
1876+
Variant::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
18811877
}
1882-
hir::VariantData::Unit(..) => VariantKind::CLike,
1878+
hir::VariantData::Unit(..) => Variant::CLike,
18831879
}
18841880
}
18851881
}
@@ -2048,7 +2044,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
20482044

20492045
impl Clean<Item> for hir::Variant<'_> {
20502046
fn clean(&self, cx: &DocContext<'_>) -> Item {
2051-
let kind = VariantItem(Variant { kind: self.data.clean(cx) });
2047+
let kind = VariantItem(self.data.clean(cx));
20522048
let what_rustc_thinks =
20532049
Item::from_hir_id_and_parts(self.id, Some(self.ident.name), kind, cx);
20542050
// don't show `pub` for variants, which are always public

src/librustdoc/clean/types.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ impl Item {
237237
match *self.kind {
238238
StructItem(ref _struct) => Some(_struct.fields_stripped),
239239
UnionItem(ref union) => Some(union.fields_stripped),
240-
VariantItem(Variant { kind: VariantKind::Struct(ref vstruct) }) => {
241-
Some(vstruct.fields_stripped)
242-
}
240+
VariantItem(Variant::Struct(ref vstruct)) => Some(vstruct.fields_stripped),
243241
_ => None,
244242
}
245243
}
@@ -353,7 +351,7 @@ impl ItemKind {
353351
match self {
354352
StructItem(s) => s.fields.iter(),
355353
UnionItem(u) => u.fields.iter(),
356-
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
354+
VariantItem(Variant::Struct(v)) => v.fields.iter(),
357355
EnumItem(e) => e.variants.iter(),
358356
TraitItem(t) => t.items.iter(),
359357
ImplItem(i) => i.items.iter(),
@@ -1719,12 +1717,7 @@ crate struct Enum {
17191717
}
17201718

17211719
#[derive(Clone, Debug)]
1722-
crate struct Variant {
1723-
crate kind: VariantKind,
1724-
}
1725-
1726-
#[derive(Clone, Debug)]
1727-
crate enum VariantKind {
1720+
crate enum Variant {
17281721
CLike,
17291722
Tuple(Vec<Type>),
17301723
Struct(VariantStruct),

src/librustdoc/fold.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ crate trait DocFolder: Sized {
5555
}
5656
VariantItem(i) => {
5757
let i2 = i.clone(); // this clone is small
58-
match i.kind {
59-
VariantKind::Struct(mut j) => {
58+
match i {
59+
Variant::Struct(mut j) => {
6060
let num_fields = j.fields.len();
6161
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
6262
j.fields_stripped |= num_fields != j.fields.len()
6363
|| j.fields.iter().any(|f| f.is_stripped());
64-
VariantItem(Variant { kind: VariantKind::Struct(j) })
64+
VariantItem(Variant::Struct(j))
6565
}
6666
_ => VariantItem(i2),
6767
}

src/librustdoc/html/render/mod.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -3200,9 +3200,9 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
32003200
write!(w, " ");
32013201
let name = v.name.as_ref().unwrap();
32023202
match *v.kind {
3203-
clean::VariantItem(ref var) => match var.kind {
3204-
clean::VariantKind::CLike => write!(w, "{}", name),
3205-
clean::VariantKind::Tuple(ref tys) => {
3203+
clean::VariantItem(ref var) => match var {
3204+
clean::Variant::CLike => write!(w, "{}", name),
3205+
clean::Variant::Tuple(ref tys) => {
32063206
write!(w, "{}(", name);
32073207
for (i, ty) in tys.iter().enumerate() {
32083208
if i > 0 {
@@ -3212,7 +3212,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
32123212
}
32133213
write!(w, ")");
32143214
}
3215-
clean::VariantKind::Struct(ref s) => {
3215+
clean::Variant::Struct(ref s) => {
32163216
render_struct(w, v, None, s.struct_type, &s.fields, " ", false, cx);
32173217
}
32183218
},
@@ -3249,25 +3249,22 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
32493249
id = id,
32503250
name = variant.name.as_ref().unwrap()
32513251
);
3252-
if let clean::VariantItem(ref var) = *variant.kind {
3253-
if let clean::VariantKind::Tuple(ref tys) = var.kind {
3254-
write!(w, "(");
3255-
for (i, ty) in tys.iter().enumerate() {
3256-
if i > 0 {
3257-
write!(w, ",&nbsp;");
3258-
}
3259-
write!(w, "{}", ty.print());
3252+
if let clean::VariantItem(clean::Variant::Tuple(ref tys)) = *variant.kind {
3253+
write!(w, "(");
3254+
for (i, ty) in tys.iter().enumerate() {
3255+
if i > 0 {
3256+
write!(w, ",&nbsp;");
32603257
}
3261-
write!(w, ")");
3258+
write!(w, "{}", ty.print());
32623259
}
3260+
write!(w, ")");
32633261
}
32643262
write!(w, "</code></div>");
32653263
document(w, cx, variant, Some(it));
32663264
document_non_exhaustive(w, variant);
32673265

3268-
use crate::clean::{Variant, VariantKind};
3269-
if let clean::VariantItem(Variant { kind: VariantKind::Struct(ref s) }) = *variant.kind
3270-
{
3266+
use crate::clean::Variant;
3267+
if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
32713268
let variant_id = cx.derive_id(format!(
32723269
"{}.{}.fields",
32733270
ItemType::Variant,

src/librustdoc/json/conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ impl From<clean::VariantStruct> for Struct {
482482

483483
impl From<clean::Variant> for Variant {
484484
fn from(variant: clean::Variant) -> Self {
485-
use clean::VariantKind::*;
486-
match variant.kind {
485+
use clean::Variant::*;
486+
match variant {
487487
CLike => Variant::Plain,
488488
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),
489489
Struct(s) => Variant::Struct(ids(s.fields)),

src/librustdoc/passes/stripper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'a> DocFolder for Stripper<'a> {
9494
// implementations of traits are always public.
9595
clean::ImplItem(ref imp) if imp.trait_.is_some() => true,
9696
// Struct variant fields have inherited visibility
97-
clean::VariantItem(clean::Variant { kind: clean::VariantKind::Struct(..) }) => true,
97+
clean::VariantItem(clean::Variant::Struct(..)) => true,
9898
_ => false,
9999
};
100100

0 commit comments

Comments
 (0)