Rename VariantKind -> Variant

There's no `Variant`, so it seems silly to have `Kind`.
This commit is contained in:
Joshua Nelson 2021-01-15 01:17:23 -05:00
parent dd459a2be6
commit d11855a8ce
6 changed files with 24 additions and 24 deletions

View File

@ -1840,11 +1840,11 @@ impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
impl Clean<Item> for ty::VariantDef { impl Clean<Item> for ty::VariantDef {
fn clean(&self, cx: &DocContext<'_>) -> Item { fn clean(&self, cx: &DocContext<'_>) -> Item {
let kind = match self.ctor_kind { let kind = match self.ctor_kind {
CtorKind::Const => VariantKind::CLike, CtorKind::Const => Variant::CLike,
CtorKind::Fn => VariantKind::Tuple( CtorKind::Fn => Variant::Tuple(
self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(), self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(),
), ),
CtorKind::Fictive => VariantKind::Struct(VariantStruct { CtorKind::Fictive => Variant::Struct(VariantStruct {
struct_type: doctree::Plain, struct_type: doctree::Plain,
fields_stripped: false, fields_stripped: false,
fields: self fields: self
@ -1868,14 +1868,14 @@ impl Clean<Item> for ty::VariantDef {
} }
} }
impl Clean<VariantKind> for hir::VariantData<'_> { impl Clean<Variant> for hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> VariantKind { fn clean(&self, cx: &DocContext<'_>) -> Variant {
match self { match self {
hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)), hir::VariantData::Struct(..) => Variant::Struct(self.clean(cx)),
hir::VariantData::Tuple(..) => { hir::VariantData::Tuple(..) => {
VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect()) Variant::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
} }
hir::VariantData::Unit(..) => VariantKind::CLike, hir::VariantData::Unit(..) => Variant::CLike,
} }
} }
} }

View File

@ -237,7 +237,7 @@ impl Item {
match *self.kind { match *self.kind {
StructItem(ref _struct) => Some(_struct.fields_stripped), StructItem(ref _struct) => Some(_struct.fields_stripped),
UnionItem(ref union) => Some(union.fields_stripped), UnionItem(ref union) => Some(union.fields_stripped),
VariantItem(VariantKind::Struct(ref vstruct)) => Some(vstruct.fields_stripped), VariantItem(Variant::Struct(ref vstruct)) => Some(vstruct.fields_stripped),
_ => None, _ => None,
} }
} }
@ -323,7 +323,7 @@ crate enum ItemKind {
/// A method with a body. /// A method with a body.
MethodItem(Function, Option<hir::Defaultness>), MethodItem(Function, Option<hir::Defaultness>),
StructFieldItem(Type), StructFieldItem(Type),
VariantItem(VariantKind), VariantItem(Variant),
/// `fn`s from an extern block /// `fn`s from an extern block
ForeignFunctionItem(Function), ForeignFunctionItem(Function),
/// `static`s from an extern block /// `static`s from an extern block
@ -351,7 +351,7 @@ impl ItemKind {
match self { match self {
StructItem(s) => s.fields.iter(), StructItem(s) => s.fields.iter(),
UnionItem(u) => u.fields.iter(), UnionItem(u) => u.fields.iter(),
VariantItem(VariantKind::Struct(v)) => v.fields.iter(), VariantItem(Variant::Struct(v)) => v.fields.iter(),
EnumItem(e) => e.variants.iter(), EnumItem(e) => e.variants.iter(),
TraitItem(t) => t.items.iter(), TraitItem(t) => t.items.iter(),
ImplItem(i) => i.items.iter(), ImplItem(i) => i.items.iter(),
@ -1717,7 +1717,7 @@ crate struct Enum {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
crate enum VariantKind { crate enum Variant {
CLike, CLike,
Tuple(Vec<Type>), Tuple(Vec<Type>),
Struct(VariantStruct), Struct(VariantStruct),

View File

@ -56,12 +56,12 @@ crate trait DocFolder: Sized {
VariantItem(i) => { VariantItem(i) => {
let i2 = i.clone(); // this clone is small let i2 = i.clone(); // this clone is small
match i { match i {
VariantKind::Struct(mut j) => { Variant::Struct(mut j) => {
let num_fields = j.fields.len(); let num_fields = j.fields.len();
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
j.fields_stripped |= num_fields != j.fields.len() j.fields_stripped |= num_fields != j.fields.len()
|| j.fields.iter().any(|f| f.is_stripped()); || j.fields.iter().any(|f| f.is_stripped());
VariantItem(VariantKind::Struct(j)) VariantItem(Variant::Struct(j))
} }
_ => VariantItem(i2), _ => VariantItem(i2),
} }

View File

@ -3201,8 +3201,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
let name = v.name.as_ref().unwrap(); let name = v.name.as_ref().unwrap();
match *v.kind { match *v.kind {
clean::VariantItem(ref var) => match var { clean::VariantItem(ref var) => match var {
clean::VariantKind::CLike => write!(w, "{}", name), clean::Variant::CLike => write!(w, "{}", name),
clean::VariantKind::Tuple(ref tys) => { clean::Variant::Tuple(ref tys) => {
write!(w, "{}(", name); write!(w, "{}(", name);
for (i, ty) in tys.iter().enumerate() { for (i, ty) in tys.iter().enumerate() {
if i > 0 { if i > 0 {
@ -3212,7 +3212,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
} }
write!(w, ")"); write!(w, ")");
} }
clean::VariantKind::Struct(ref s) => { clean::Variant::Struct(ref s) => {
render_struct(w, v, None, s.struct_type, &s.fields, " ", false, cx); render_struct(w, v, None, s.struct_type, &s.fields, " ", false, cx);
} }
}, },
@ -3249,7 +3249,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
id = id, id = id,
name = variant.name.as_ref().unwrap() name = variant.name.as_ref().unwrap()
); );
if let clean::VariantItem(clean::VariantKind::Tuple(ref tys)) = *variant.kind { if let clean::VariantItem(clean::Variant::Tuple(ref tys)) = *variant.kind {
write!(w, "("); write!(w, "(");
for (i, ty) in tys.iter().enumerate() { for (i, ty) in tys.iter().enumerate() {
if i > 0 { if i > 0 {
@ -3263,8 +3263,8 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
document(w, cx, variant, Some(it)); document(w, cx, variant, Some(it));
document_non_exhaustive(w, variant); document_non_exhaustive(w, variant);
use crate::clean::VariantKind; use crate::clean::Variant;
if let clean::VariantItem(VariantKind::Struct(ref s)) = *variant.kind { if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
let variant_id = cx.derive_id(format!( let variant_id = cx.derive_id(format!(
"{}.{}.fields", "{}.{}.fields",
ItemType::Variant, ItemType::Variant,

View File

@ -480,9 +480,9 @@ impl From<clean::VariantStruct> for Struct {
} }
} }
impl From<clean::VariantKind> for Variant { impl From<clean::Variant> for Variant {
fn from(variant: clean::VariantKind) -> Self { fn from(variant: clean::Variant) -> Self {
use clean::VariantKind::*; use clean::Variant::*;
match variant { match variant {
CLike => Variant::Plain, CLike => Variant::Plain,
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()), Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),

View File

@ -94,7 +94,7 @@ impl<'a> DocFolder for Stripper<'a> {
// implementations of traits are always public. // implementations of traits are always public.
clean::ImplItem(ref imp) if imp.trait_.is_some() => true, clean::ImplItem(ref imp) if imp.trait_.is_some() => true,
// Struct variant fields have inherited visibility // Struct variant fields have inherited visibility
clean::VariantItem(clean::VariantKind::Struct(..)) => true, clean::VariantItem(clean::Variant::Struct(..)) => true,
_ => false, _ => false,
}; };