Remove StructType entirely and replace it with CtorKind
This commit is contained in:
parent
450c5eae1d
commit
3349b40d47
@ -5,7 +5,7 @@ use std::iter::once;
|
|||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
use rustc_metadata::creader::LoadedMacro;
|
use rustc_metadata::creader::LoadedMacro;
|
||||||
@ -15,7 +15,7 @@ use rustc_span::hygiene::MacroKind;
|
|||||||
use rustc_span::symbol::{kw, sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind, StructType};
|
use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind};
|
||||||
use crate::core::DocContext;
|
use crate::core::DocContext;
|
||||||
|
|
||||||
use super::Clean;
|
use super::Clean;
|
||||||
@ -245,11 +245,7 @@ fn build_struct(cx: &DocContext<'_>, did: DefId) -> clean::Struct {
|
|||||||
let variant = cx.tcx.adt_def(did).non_enum_variant();
|
let variant = cx.tcx.adt_def(did).non_enum_variant();
|
||||||
|
|
||||||
clean::Struct {
|
clean::Struct {
|
||||||
struct_type: match variant.ctor_kind {
|
struct_type: variant.ctor_kind,
|
||||||
CtorKind::Fictive => StructType::Plain,
|
|
||||||
CtorKind::Fn => StructType::Tuple,
|
|
||||||
CtorKind::Const => StructType::Unit,
|
|
||||||
},
|
|
||||||
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
|
generics: (cx.tcx.generics_of(did), predicates).clean(cx),
|
||||||
fields: variant.fields.clean(cx),
|
fields: variant.fields.clean(cx),
|
||||||
fields_stripped: false,
|
fields_stripped: false,
|
||||||
|
@ -1824,19 +1824,10 @@ impl Clean<Visibility> for ty::Visibility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn struct_type_from_def(vdata: &hir::VariantData<'_>) -> StructType {
|
|
||||||
use StructType::*;
|
|
||||||
match *vdata {
|
|
||||||
hir::VariantData::Struct(..) => Plain,
|
|
||||||
hir::VariantData::Tuple(..) => Tuple,
|
|
||||||
hir::VariantData::Unit(..) => Unit,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
|
impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
|
||||||
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
|
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
|
||||||
VariantStruct {
|
VariantStruct {
|
||||||
struct_type: struct_type_from_def(self),
|
struct_type: CtorKind::from_hir(self),
|
||||||
fields: self.fields().iter().map(|x| x.clean(cx)).collect(),
|
fields: self.fields().iter().map(|x| x.clean(cx)).collect(),
|
||||||
fields_stripped: false,
|
fields_stripped: false,
|
||||||
}
|
}
|
||||||
@ -1851,7 +1842,7 @@ impl Clean<Item> for ty::VariantDef {
|
|||||||
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 => Variant::Struct(VariantStruct {
|
CtorKind::Fictive => Variant::Struct(VariantStruct {
|
||||||
struct_type: StructType::Plain,
|
struct_type: CtorKind::Fictive,
|
||||||
fields_stripped: false,
|
fields_stripped: false,
|
||||||
fields: self
|
fields: self
|
||||||
.fields
|
.fields
|
||||||
@ -2010,7 +2001,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
|
|||||||
fields_stripped: false,
|
fields_stripped: false,
|
||||||
}),
|
}),
|
||||||
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
|
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
|
||||||
struct_type: struct_type_from_def(&variant_data),
|
struct_type: CtorKind::from_hir(variant_data),
|
||||||
generics: generics.clean(cx),
|
generics: generics.clean(cx),
|
||||||
fields: variant_data.fields().clean(cx),
|
fields: variant_data.fields().clean(cx),
|
||||||
fields_stripped: false,
|
fields_stripped: false,
|
||||||
|
@ -16,7 +16,7 @@ use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
|
|||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_feature::UnstableFeatures;
|
use rustc_feature::UnstableFeatures;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::{CtorKind, Res};
|
||||||
use rustc_hir::def_id::{CrateNum, DefId};
|
use rustc_hir::def_id::{CrateNum, DefId};
|
||||||
use rustc_hir::lang_items::LangItem;
|
use rustc_hir::lang_items::LangItem;
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
@ -1682,19 +1682,9 @@ impl Visibility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
crate enum StructType {
|
|
||||||
/// A braced struct
|
|
||||||
Plain,
|
|
||||||
/// A tuple struct
|
|
||||||
Tuple,
|
|
||||||
/// A unit struct
|
|
||||||
Unit,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct Struct {
|
crate struct Struct {
|
||||||
crate struct_type: StructType,
|
crate struct_type: CtorKind,
|
||||||
crate generics: Generics,
|
crate generics: Generics,
|
||||||
crate fields: Vec<Item>,
|
crate fields: Vec<Item>,
|
||||||
crate fields_stripped: bool,
|
crate fields_stripped: bool,
|
||||||
@ -1712,7 +1702,7 @@ crate struct Union {
|
|||||||
/// only as a variant in an enum.
|
/// only as a variant in an enum.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
crate struct VariantStruct {
|
crate struct VariantStruct {
|
||||||
crate struct_type: StructType,
|
crate struct_type: CtorKind,
|
||||||
crate fields: Vec<Item>,
|
crate fields: Vec<Item>,
|
||||||
crate fields_stripped: bool,
|
crate fields_stripped: bool,
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ use rustc_attr::{Deprecation, StabilityLevel};
|
|||||||
use rustc_data_structures::flock;
|
use rustc_data_structures::flock;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
use rustc_hir::def::CtorKind;
|
||||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||||
use rustc_hir::Mutability;
|
use rustc_hir::Mutability;
|
||||||
use rustc_middle::middle::stability;
|
use rustc_middle::middle::stability;
|
||||||
@ -3100,7 +3101,7 @@ fn item_struct(
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.peekable();
|
.peekable();
|
||||||
if let clean::StructType::Plain = s.struct_type {
|
if let CtorKind::Fictive = s.struct_type {
|
||||||
if fields.peek().is_some() {
|
if fields.peek().is_some() {
|
||||||
write!(
|
write!(
|
||||||
w,
|
w,
|
||||||
@ -3350,7 +3351,7 @@ fn render_struct(
|
|||||||
w: &mut Buffer,
|
w: &mut Buffer,
|
||||||
it: &clean::Item,
|
it: &clean::Item,
|
||||||
g: Option<&clean::Generics>,
|
g: Option<&clean::Generics>,
|
||||||
ty: clean::StructType,
|
ty: CtorKind,
|
||||||
fields: &[clean::Item],
|
fields: &[clean::Item],
|
||||||
tab: &str,
|
tab: &str,
|
||||||
structhead: bool,
|
structhead: bool,
|
||||||
@ -3367,7 +3368,7 @@ fn render_struct(
|
|||||||
write!(w, "{}", g.print())
|
write!(w, "{}", g.print())
|
||||||
}
|
}
|
||||||
match ty {
|
match ty {
|
||||||
clean::StructType::Plain => {
|
CtorKind::Fictive => {
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })
|
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: true })
|
||||||
}
|
}
|
||||||
@ -3399,7 +3400,7 @@ fn render_struct(
|
|||||||
}
|
}
|
||||||
write!(w, "}}");
|
write!(w, "}}");
|
||||||
}
|
}
|
||||||
clean::StructType::Tuple => {
|
CtorKind::Fn => {
|
||||||
write!(w, "(");
|
write!(w, "(");
|
||||||
for (i, field) in fields.iter().enumerate() {
|
for (i, field) in fields.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
@ -3424,7 +3425,7 @@ fn render_struct(
|
|||||||
}
|
}
|
||||||
write!(w, ";");
|
write!(w, ";");
|
||||||
}
|
}
|
||||||
clean::StructType::Unit => {
|
CtorKind::Const => {
|
||||||
// Needed for PhantomData.
|
// Needed for PhantomData.
|
||||||
if let Some(g) = g {
|
if let Some(g) = g {
|
||||||
write!(w, "{}", WhereClause { gens: g, indent: 0, end_newline: false })
|
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
|
|||||||
let fields = get_struct_fields_name(&s.fields);
|
let fields = get_struct_fields_name(&s.fields);
|
||||||
|
|
||||||
if !fields.is_empty() {
|
if !fields.is_empty() {
|
||||||
if let clean::StructType::Plain = s.struct_type {
|
if let CtorKind::Fictive = s.struct_type {
|
||||||
sidebar.push_str(&format!(
|
sidebar.push_str(&format!(
|
||||||
"<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\
|
"<a class=\"sidebar-title\" href=\"#fields\">Fields</a>\
|
||||||
<div class=\"sidebar-links\">{}</div>",
|
<div class=\"sidebar-links\">{}</div>",
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
|
|
||||||
use rustc_ast::ast;
|
use rustc_ast::ast;
|
||||||
|
use rustc_hir::def::CtorKind;
|
||||||
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX};
|
use rustc_span::def_id::{DefId, CRATE_DEF_INDEX};
|
||||||
use rustc_span::Pos;
|
use rustc_span::Pos;
|
||||||
|
|
||||||
@ -220,13 +221,12 @@ impl From<clean::Union> for Struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<clean::StructType> for StructType {
|
impl From<CtorKind> for StructType {
|
||||||
fn from(struct_type: clean::StructType) -> Self {
|
fn from(struct_type: CtorKind) -> Self {
|
||||||
use clean::StructType::*;
|
|
||||||
match struct_type {
|
match struct_type {
|
||||||
Plain => StructType::Plain,
|
CtorKind::Fictive => StructType::Plain,
|
||||||
Tuple => StructType::Tuple,
|
CtorKind::Fn => StructType::Tuple,
|
||||||
Unit => StructType::Unit,
|
CtorKind::Const => StructType::Unit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user