From 7a5376d23cb3324edcfaa278a9387898960d5f7c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 25 Oct 2022 20:15:15 +0400 Subject: Unreserve braced enum variants in value namespace --- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 14 +++++++------- src/librustdoc/clean/types.rs | 4 ++-- src/librustdoc/html/render/mod.rs | 8 ++++---- src/librustdoc/html/render/print_item.rs | 16 ++++++++-------- src/librustdoc/json/conversions.rs | 10 +++++----- 6 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/librustdoc') diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 3fc4aae923a..e7c3e5a45e8 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -276,7 +276,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct { let variant = cx.tcx.adt_def(did).non_enum_variant(); clean::Struct { - struct_type: variant.ctor_kind, + ctor_kind: variant.ctor_kind(), generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates), fields: variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect(), } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c20595614b0..7085bc8d1be 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1842,16 +1842,16 @@ pub(crate) fn clean_field_with_def_id( } pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item { - let kind = match variant.ctor_kind { - CtorKind::Const => Variant::CLike(match variant.discr { + let kind = match variant.ctor_kind() { + Some(CtorKind::Const) => Variant::CLike(match variant.discr { ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }), ty::VariantDiscr::Relative(_) => None, }), - CtorKind::Fn => Variant::Tuple( + Some(CtorKind::Fn) => Variant::Tuple( variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(), ), - CtorKind::Fictive => Variant::Struct(VariantStruct { - struct_type: CtorKind::Fictive, + None => Variant::Struct(VariantStruct { + ctor_kind: None, fields: variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(), }), }; @@ -1865,7 +1865,7 @@ fn clean_variant_data<'tcx>( ) -> Variant { match variant { hir::VariantData::Struct(..) => Variant::Struct(VariantStruct { - struct_type: CtorKind::from_hir(variant), + ctor_kind: None, fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(), }), hir::VariantData::Tuple(..) => { @@ -2060,7 +2060,7 @@ fn clean_maybe_renamed_item<'tcx>( fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(), }), ItemKind::Struct(ref variant_data, generics) => StructItem(Struct { - struct_type: CtorKind::from_hir(variant_data), + ctor_kind: variant_data.ctor_kind(), generics: clean_generics(generics, cx), fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(), }), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 3d13f7463cb..340d6d7df18 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -2081,7 +2081,7 @@ impl From for PrimitiveType { #[derive(Clone, Debug)] pub(crate) struct Struct { - pub(crate) struct_type: CtorKind, + pub(crate) ctor_kind: Option, pub(crate) generics: Generics, pub(crate) fields: Vec, } @@ -2109,7 +2109,7 @@ impl Union { /// only as a variant in an enum. #[derive(Clone, Debug)] pub(crate) struct VariantStruct { - pub(crate) struct_type: CtorKind, + pub(crate) ctor_kind: Option, pub(crate) fields: Vec, } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 647eb69d9a6..d12874e1bfd 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -2280,12 +2280,12 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea let fields = get_struct_fields_name(&s.fields); if !fields.is_empty() { - match s.struct_type { - CtorKind::Fictive => { + match s.ctor_kind { + None => { print_sidebar_block(&mut sidebar, "fields", "Fields", fields.iter()); } - CtorKind::Fn => print_sidebar_title(&mut sidebar, "fields", "Tuple Fields"), - CtorKind::Const => {} + Some(CtorKind::Fn) => print_sidebar_title(&mut sidebar, "fields", "Tuple Fields"), + Some(CtorKind::Const) => {} } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index c95f117a205..a0e5309a70c 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1232,7 +1232,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean:: w, v, None, - s.struct_type, + s.ctor_kind, &s.fields, " ", false, @@ -1458,7 +1458,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean wrap_into_item_decl(w, |w| { wrap_item(w, "struct", |w| { render_attributes_in_code(w, it); - render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true, cx); + render_struct(w, it, Some(&s.generics), s.ctor_kind, &s.fields, "", true, cx); }); }); @@ -1472,14 +1472,14 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean _ => None, }) .peekable(); - if let CtorKind::Fictive | CtorKind::Fn = s.struct_type { + if let None | Some(CtorKind::Fn) = s.ctor_kind { if fields.peek().is_some() { write!( w, "

\ {}{}\

", - if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" }, + if s.ctor_kind.is_none() { "Fields" } else { "Tuple Fields" }, document_non_exhaustive_header(it) ); document_non_exhaustive(w, it); @@ -1739,7 +1739,7 @@ fn render_struct( w: &mut Buffer, it: &clean::Item, g: Option<&clean::Generics>, - ty: CtorKind, + ty: Option, fields: &[clean::Item], tab: &str, structhead: bool, @@ -1757,7 +1757,7 @@ fn render_struct( write!(w, "{}", g.print(cx)) } match ty { - CtorKind::Fictive => { + None => { let where_diplayed = g.map(|g| print_where_clause_and_check(w, g, cx)).unwrap_or(false); // If there wasn't a `where` clause, we add a whitespace. @@ -1799,7 +1799,7 @@ fn render_struct( } w.write_str("}"); } - CtorKind::Fn => { + Some(CtorKind::Fn) => { w.write_str("("); for (i, field) in fields.iter().enumerate() { if i > 0 { @@ -1827,7 +1827,7 @@ fn render_struct( w.write_str(";"); } } - CtorKind::Const => { + Some(CtorKind::Const) => { // Needed for PhantomData. if let Some(g) = g { write!(w, "{}", print_where_clause(g, cx, 0, Ending::NoNewline)); diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 6995778a93d..d7184053c87 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -315,15 +315,15 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum { impl FromWithTcx for Struct { fn from_tcx(struct_: clean::Struct, tcx: TyCtxt<'_>) -> Self { let fields_stripped = struct_.has_stripped_entries(); - let clean::Struct { struct_type, generics, fields } = struct_; + let clean::Struct { ctor_kind, generics, fields } = struct_; - let kind = match struct_type { - CtorKind::Fn => StructKind::Tuple(ids_keeping_stripped(fields, tcx)), - CtorKind::Const => { + let kind = match ctor_kind { + Some(CtorKind::Fn) => StructKind::Tuple(ids_keeping_stripped(fields, tcx)), + Some(CtorKind::Const) => { assert!(fields.is_empty()); StructKind::Unit } - CtorKind::Fictive => StructKind::Plain { fields: ids(fields, tcx), fields_stripped }, + None => StructKind::Plain { fields: ids(fields, tcx), fields_stripped }, }; Struct { -- cgit 1.4.1-3-g733a5