Skip to content

Commit 3349b40

Browse files
committed
Remove StructType entirely and replace it with CtorKind
1 parent 450c5ea commit 3349b40

File tree

5 files changed

+22
-44
lines changed

5 files changed

+22
-44
lines changed

src/librustdoc/clean/inline.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::iter::once;
55
use rustc_ast as ast;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir as hir;
8-
use rustc_hir::def::{CtorKind, DefKind, Res};
8+
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
1010
use rustc_hir::Mutability;
1111
use rustc_metadata::creader::LoadedMacro;
@@ -15,7 +15,7 @@ use rustc_span::hygiene::MacroKind;
1515
use rustc_span::symbol::{kw, sym, Symbol};
1616
use rustc_span::Span;
1717

18-
use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind, StructType};
18+
use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind};
1919
use crate::core::DocContext;
2020

2121
use super::Clean;
@@ -245,11 +245,7 @@ fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct {
245245
let variant = cx.tcx.adt_def(did).non_enum_variant();
246246

247247
clean::Struct {
248-
struct_type: match variant.ctor_kind {
249-
CtorKind::Fictive => StructType::Plain,
250-
CtorKind::Fn => StructType::Tuple,
251-
CtorKind::Const => StructType::Unit,
252-
},
248+
struct_type: variant.ctor_kind,
253249
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
254250
fields: variant.fields.clean(cx),
255251
fields_stripped: false,

src/librustdoc/clean/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1824,19 +1824,10 @@ impl Clean<Visibility> for ty::Visibility {
18241824
}
18251825
}
18261826

1827-
crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
1828-
use StructType::*;
1829-
match *vdata {
1830-
hir::VariantData::Struct(..) => Plain,
1831-
hir::VariantData::Tuple(..) => Tuple,
1832-
hir::VariantData::Unit(..) => Unit,
1833-
}
1834-
}
1835-
18361827
impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
18371828
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
18381829
VariantStruct {
1839-
struct_type: struct_type_from_def(self),
1830+
struct_type: CtorKind::from_hir(self),
18401831
fields: self.fields().iter().map(|x| x.clean(cx)).collect(),
18411832
fields_stripped: false,
18421833
}
@@ -1851,7 +1842,7 @@ impl Clean<Item> for ty::VariantDef {
18511842
self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(),
18521843
),
18531844
CtorKind::Fictive => Variant::Struct(VariantStruct {
1854-
struct_type: StructType::Plain,
1845+
struct_type: CtorKind::Fictive,
18551846
fields_stripped: false,
18561847
fields: self
18571848
.fields
@@ -2010,7 +2001,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
20102001
fields_stripped: false,
20112002
}),
20122003
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
2013-
struct_type: struct_type_from_def(&variant_data),
2004+
struct_type: CtorKind::from_hir(variant_data),
20142005
generics: generics.clean(cx),
20152006
fields: variant_data.fields().clean(cx),
20162007
fields_stripped: false,

src/librustdoc/clean/types.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
1616
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1717
use rustc_feature::UnstableFeatures;
1818
use rustc_hir as hir;
19-
use rustc_hir::def::Res;
19+
use rustc_hir::def::{CtorKind, Res};
2020
use rustc_hir::def_id::{CrateNum, DefId};
2121
use rustc_hir::lang_items::LangItem;
2222
use rustc_hir::Mutability;
@@ -1682,19 +1682,9 @@ impl Visibility {
16821682
}
16831683
}
16841684

1685-
#[derive(Debug, Clone, Copy)]
1686-
crate enum StructType {
1687-
/// A braced struct
1688-
Plain,
1689-
/// A tuple struct
1690-
Tuple,
1691-
/// A unit struct
1692-
Unit,
1693-
}
1694-
16951685
#[derive(Clone, Debug)]
16961686
crate struct Struct {
1697-
crate struct_type: StructType,
1687+
crate struct_type: CtorKind,
16981688
crate generics: Generics,
16991689
crate fields: Vec<Item>,
17001690
crate fields_stripped: bool,
@@ -1712,7 +1702,7 @@ crate struct Union {
17121702
/// only as a variant in an enum.
17131703
#[derive(Clone, Debug)]
17141704
crate struct VariantStruct {
1715-
crate struct_type: StructType,
1705+
crate struct_type: CtorKind,
17161706
crate fields: Vec<Item>,
17171707
crate fields_stripped: bool,
17181708
}

src/librustdoc/html/render/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use rustc_attr::{Deprecation, StabilityLevel};
5252
use rustc_data_structures::flock;
5353
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5454
use rustc_hir as hir;
55+
use rustc_hir::def::CtorKind;
5556
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
5657
use rustc_hir::Mutability;
5758
use rustc_middle::middle::stability;
@@ -3100,7 +3101,7 @@ fn item_struct(
31003101
_ => None,
31013102
})
31023103
.peekable();
3103-
if let clean::StructType::Plain = s.struct_type {
3104+
if let CtorKind::Fictive = s.struct_type {
31043105
if fields.peek().is_some() {
31053106
write!(
31063107
w,
@@ -3350,7 +3351,7 @@ fn render_struct(
33503351
w: &mut Buffer,
33513352
it: &clean::Item,
33523353
g: Option<&clean::Generics>,
3353-
ty: clean::StructType,
3354+
ty: CtorKind,
33543355
fields: &[clean::Item],
33553356
tab: &str,
33563357
structhead: bool,
@@ -3367,7 +3368,7 @@ fn render_struct(
33673368
write!(w, "{}", g.print())
33683369
}
33693370
match ty {
3370-
clean::StructType::Plain => {
3371+
CtorKind::Fictive => {
33713372
if let Some(g) = g {
33723373
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })
33733374
}
@@ -3399,7 +3400,7 @@ fn render_struct(
33993400
}
34003401
write!(w, "}}");
34013402
}
3402-
clean::StructType::Tuple => {
3403+
CtorKind::Fn => {
34033404
write!(w, "(");
34043405
for (i, field) in fields.iter().enumerate() {
34053406
if i > 0 {
@@ -3424,7 +3425,7 @@ fn render_struct(
34243425
}
34253426
write!(w, ";");
34263427
}
3427-
clean::StructType::Unit => {
3428+
CtorKind::Const => {
34283429
// Needed for PhantomData.
34293430
if let Some(g) = g {
34303431
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })
@@ -4459,7 +4460,7 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
44594460
let fields = get_struct_fields_name(&s.fields);
44604461

44614462
if !fields.is_empty() {
4462-
if let clean::StructType::Plain = s.struct_type {
4463+
if let CtorKind::Fictive = s.struct_type {
44634464
sidebar.push_str(&format!(
44644465
"<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\
44654466
<div class=\"sidebar-links\">{}</div>",

src/librustdoc/json/conversions.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use std::convert::From;
66

77
use rustc_ast::ast;
8+
use rustc_hir::def::CtorKind;
89
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX};
910
use rustc_span::Pos;
1011

@@ -220,13 +221,12 @@ impl From<clean::Union> for Struct {
220221
}
221222
}
222223

223-
impl From<clean::StructType> for StructType {
224-
fn from(struct_type: clean::StructType) -> Self {
225-
use clean::StructType::*;
224+
impl From<CtorKind> for StructType {
225+
fn from(struct_type: CtorKind) -> Self {
226226
match struct_type {
227-
Plain => StructType::Plain,
228-
Tuple => StructType::Tuple,
229-
Unit => StructType::Unit,
227+
CtorKind::Fictive => StructType::Plain,
228+
CtorKind::Fn => StructType::Tuple,
229+
CtorKind::Const => StructType::Unit,
230230
}
231231
}
232232
}

0 commit comments

Comments
 (0)