Skip to content

Commit

Permalink
Remove useless clean::Variant struct
Browse files Browse the repository at this point in the history
It had exactly one field and no special behavior, so there was no point.
  • Loading branch information
jyn514 committed Jan 15, 2021
1 parent e48eb37 commit dd459a2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 36 deletions.
10 changes: 3 additions & 7 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,8 @@ impl Clean<Item> for ty::VariantDef {
.collect(),
}),
};
let what_rustc_thinks = Item::from_def_id_and_parts(
self.def_id,
Some(self.ident.name),
VariantItem(Variant { kind }),
cx,
);
let what_rustc_thinks =
Item::from_def_id_and_parts(self.def_id, Some(self.ident.name), VariantItem(kind), cx);
// don't show `pub` for fields, which are always public
Item { visibility: Inherited, ..what_rustc_thinks }
}
Expand Down Expand Up @@ -2048,7 +2044,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {

impl Clean<Item> for hir::Variant<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let kind = VariantItem(Variant { kind: self.data.clean(cx) });
let kind = VariantItem(self.data.clean(cx));
let what_rustc_thinks =
Item::from_hir_id_and_parts(self.id, Some(self.ident.name), kind, cx);
// don't show `pub` for variants, which are always public
Expand Down
13 changes: 3 additions & 10 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,7 @@ impl Item {
match *self.kind {
StructItem(ref _struct) => Some(_struct.fields_stripped),
UnionItem(ref union) => Some(union.fields_stripped),
VariantItem(Variant { kind: VariantKind::Struct(ref vstruct) }) => {
Some(vstruct.fields_stripped)
}
VariantItem(VariantKind::Struct(ref vstruct)) => Some(vstruct.fields_stripped),
_ => None,
}
}
Expand Down Expand Up @@ -325,7 +323,7 @@ crate enum ItemKind {
/// A method with a body.
MethodItem(Function, Option<hir::Defaultness>),
StructFieldItem(Type),
VariantItem(Variant),
VariantItem(VariantKind),
/// `fn`s from an extern block
ForeignFunctionItem(Function),
/// `static`s from an extern block
Expand Down Expand Up @@ -353,7 +351,7 @@ impl ItemKind {
match self {
StructItem(s) => s.fields.iter(),
UnionItem(u) => u.fields.iter(),
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
VariantItem(VariantKind::Struct(v)) => v.fields.iter(),
EnumItem(e) => e.variants.iter(),
TraitItem(t) => t.items.iter(),
ImplItem(i) => i.items.iter(),
Expand Down Expand Up @@ -1718,11 +1716,6 @@ crate struct Enum {
crate variants_stripped: bool,
}

#[derive(Clone, Debug)]
crate struct Variant {
crate kind: VariantKind,
}

#[derive(Clone, Debug)]
crate enum VariantKind {
CLike,
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ crate trait DocFolder: Sized {
}
VariantItem(i) => {
let i2 = i.clone(); // this clone is small
match i.kind {
match i {
VariantKind::Struct(mut j) => {
let num_fields = j.fields.len();
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
j.fields_stripped |= num_fields != j.fields.len()
|| j.fields.iter().any(|f| f.is_stripped());
VariantItem(Variant { kind: VariantKind::Struct(j) })
VariantItem(VariantKind::Struct(j))
}
_ => VariantItem(i2),
}
Expand Down
23 changes: 10 additions & 13 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3200,7 +3200,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
write!(w, " ");
let name = v.name.as_ref().unwrap();
match *v.kind {
clean::VariantItem(ref var) => match var.kind {
clean::VariantItem(ref var) => match var {
clean::VariantKind::CLike => write!(w, "{}", name),
clean::VariantKind::Tuple(ref tys) => {
write!(w, "{}(", name);
Expand Down Expand Up @@ -3249,25 +3249,22 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
id = id,
name = variant.name.as_ref().unwrap()
);
if let clean::VariantItem(ref var) = *variant.kind {
if let clean::VariantKind::Tuple(ref tys) = var.kind {
write!(w, "(");
for (i, ty) in tys.iter().enumerate() {
if i > 0 {
write!(w, ",&nbsp;");
}
write!(w, "{}", ty.print());
if let clean::VariantItem(clean::VariantKind::Tuple(ref tys)) = *variant.kind {
write!(w, "(");
for (i, ty) in tys.iter().enumerate() {
if i > 0 {
write!(w, ",&nbsp;");
}
write!(w, ")");
write!(w, "{}", ty.print());
}
write!(w, ")");
}
write!(w, "</code></div>");
document(w, cx, variant, Some(it));
document_non_exhaustive(w, variant);

use crate::clean::{Variant, VariantKind};
if let clean::VariantItem(Variant { kind: VariantKind::Struct(ref s) }) = *variant.kind
{
use crate::clean::VariantKind;
if let clean::VariantItem(VariantKind::Struct(ref s)) = *variant.kind {
let variant_id = cx.derive_id(format!(
"{}.{}.fields",
ItemType::Variant,
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,10 @@ impl From<clean::VariantStruct> for Struct {
}
}

impl From<clean::Variant> for Variant {
fn from(variant: clean::Variant) -> Self {
impl From<clean::VariantKind> for Variant {
fn from(variant: clean::VariantKind) -> Self {
use clean::VariantKind::*;
match variant.kind {
match variant {
CLike => Variant::Plain,
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),
Struct(s) => Variant::Struct(ids(s.fields)),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/stripper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a> DocFolder for Stripper<'a> {
// implementations of traits are always public.
clean::ImplItem(ref imp) if imp.trait_.is_some() => true,
// Struct variant fields have inherited visibility
clean::VariantItem(clean::Variant { kind: clean::VariantKind::Struct(..) }) => true,
clean::VariantItem(clean::VariantKind::Struct(..)) => true,
_ => false,
};

Expand Down

0 comments on commit dd459a2

Please sign in to comment.