Skip to content

Commit dd459a2

Browse files
committed
Remove useless clean::Variant struct
It had exactly one field and no special behavior, so there was no point.
1 parent e48eb37 commit dd459a2

File tree

6 files changed

+22
-36
lines changed

6 files changed

+22
-36
lines changed

src/librustdoc/clean/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1861,12 +1861,8 @@ 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
}
@@ -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(VariantKind::Struct(ref vstruct)) => Some(vstruct.fields_stripped),
243241
_ => None,
244242
}
245243
}
@@ -325,7 +323,7 @@ crate enum ItemKind {
325323
/// A method with a body.
326324
MethodItem(Function, Option<hir::Defaultness>),
327325
StructFieldItem(Type),
328-
VariantItem(Variant),
326+
VariantItem(VariantKind),
329327
/// `fn`s from an extern block
330328
ForeignFunctionItem(Function),
331329
/// `static`s from an extern block
@@ -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(VariantKind::Struct(v)) => v.fields.iter(),
357355
EnumItem(e) => e.variants.iter(),
358356
TraitItem(t) => t.items.iter(),
359357
ImplItem(i) => i.items.iter(),
@@ -1718,11 +1716,6 @@ crate struct Enum {
17181716
crate variants_stripped: bool,
17191717
}
17201718

1721-
#[derive(Clone, Debug)]
1722-
crate struct Variant {
1723-
crate kind: VariantKind,
1724-
}
1725-
17261719
#[derive(Clone, Debug)]
17271720
crate enum VariantKind {
17281721
CLike,

src/librustdoc/fold.rs

+2-2
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 {
58+
match i {
5959
VariantKind::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(VariantKind::Struct(j))
6565
}
6666
_ => VariantItem(i2),
6767
}

src/librustdoc/html/render/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -3200,7 +3200,7 @@ 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 {
3203+
clean::VariantItem(ref var) => match var {
32043204
clean::VariantKind::CLike => write!(w, "{}", name),
32053205
clean::VariantKind::Tuple(ref tys) => {
32063206
write!(w, "{}(", name);
@@ -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::VariantKind::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::VariantKind;
3267+
if let clean::VariantItem(VariantKind::Struct(ref s)) = *variant.kind {
32713268
let variant_id = cx.derive_id(format!(
32723269
"{}.{}.fields",
32733270
ItemType::Variant,

src/librustdoc/json/conversions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,10 @@ impl From<clean::VariantStruct> for Struct {
480480
}
481481
}
482482

483-
impl From<clean::Variant> for Variant {
484-
fn from(variant: clean::Variant) -> Self {
483+
impl From<clean::VariantKind> for Variant {
484+
fn from(variant: clean::VariantKind) -> Self {
485485
use clean::VariantKind::*;
486-
match variant.kind {
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::VariantKind::Struct(..)) => true,
9898
_ => false,
9999
};
100100

0 commit comments

Comments
 (0)