diff --git a/src/librustdoc/calculate_doc_coverage.rs b/src/librustdoc/calculate_doc_coverage.rs index 3c180d9afd25d..45e1c18051444 100644 --- a/src/librustdoc/calculate_doc_coverage.rs +++ b/src/librustdoc/calculate_doc_coverage.rs @@ -15,14 +15,15 @@ use rustc_span::{FileName, RemapPathScopeComponents}; use serde::Serialize; use tracing::debug; +use crate::clean::{self, ItemKind}; use crate::config::{OutputFormat, RenderOptions}; use crate::core::DocContext; use crate::docfs::PathError; use crate::error::Error; use crate::html::markdown::{ErrorCodes, find_testable_code}; use crate::passes::check_doc_test_visibility::{Tests, should_have_doc_example}; +use crate::try_err; use crate::visit::DocVisitor; -use crate::{clean, try_err}; pub(crate) fn run( krate: &clean::Crate, @@ -219,21 +220,17 @@ impl DocVisitor<'_> for CoverageCalculator<'_, '_> { } match i.kind { - clean::StrippedItem(..) => { - // don't count items in stripped modules - return; - } - clean::PlaceholderImplItem => { - // The "real" impl items are handled below. - return; - } + // Don't count items in stripped modules. + ItemKind::Stripped(..) => return, + // The "real" impl items are handled below. + ItemKind::PlaceholderImpl => return, // docs on `use` and `extern crate` statements are not displayed, so they're not // worth counting - clean::ImportItem(..) | clean::ExternCrateItem { .. } => {} + ItemKind::Import(..) | ItemKind::ExternCrate { .. } => {} // Don't count trait impls, the missing-docs lint doesn't so we shouldn't either. // Inherent impls *can* be documented, and those docs show up, but in most cases it // doesn't make sense, as all methods on a type are in one single impl block - clean::ImplItem(_) => {} + ItemKind::Impl(_) => {} _ => { let has_docs = !i.attrs.doc_strings.is_empty(); let mut tests = Tests { found_tests: 0 }; diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index a2771ea751535..46d4523f16566 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -121,7 +121,7 @@ fn synthesize_auto_trait_impl<'tcx>( name: None, attrs: Default::default(), stability: None, - kind: clean::ImplItem(Box::new(clean::Impl { + kind: clean::ItemKind::Impl(Box::new(clean::Impl { safety: hir::Safety::Safe, generics, trait_: Some(clean_trait_ref_with_constraints(cx, trait_ref, ThinVec::new())), diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 7b4af6ac0dbcb..bf894b8e5af63 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -89,7 +89,7 @@ pub(crate) fn synthesize_blanket_impls( item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, attrs: Default::default(), stability: None, - kind: clean::ImplItem(Box::new(clean::Impl { + kind: clean::ItemKind::Impl(Box::new(clean::Impl { safety: hir::Safety::Safe, generics: clean_ty_generics(cx, impl_def_id), // FIXME(eddyb) compute both `trait_` and `for_` from diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 2fbfae88918a0..0064f7b472b24 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -18,7 +18,7 @@ use tracing::{debug, instrument, trace}; use super::{Item, extract_cfg_from_attrs}; use crate::clean::{ - self, Attributes, CfgInfo, ImplKind, ItemId, Type, clean_bound_vars, clean_generics, + self, Attributes, CfgInfo, ImplKind, ItemId, ItemKind, Type, clean_bound_vars, clean_generics, clean_impl_item, clean_middle_assoc_item, clean_middle_field, clean_middle_ty, clean_poly_fn_sig, clean_trait_ref_with_constraints, clean_ty, clean_ty_alias_inner_type, clean_ty_generics, clean_variant_def, utils, @@ -47,7 +47,7 @@ pub(crate) fn try_inline( ) -> Option> { fn try_inline_inner( cx: &mut DocContext<'_>, - kind: clean::ItemKind, + kind: ItemKind, did: DefId, name: Symbol, import_def_id: Option, @@ -87,52 +87,52 @@ pub(crate) fn try_inline( record_extern_fqn(cx, did, ItemType::Trait); cx.with_param_env(did, |cx| { build_impls(cx, did, attrs_without_docs, &mut ret); - clean::TraitItem(Box::new(build_trait(cx, did))) + ItemKind::Trait(Box::new(build_trait(cx, did))) }) } Res::Def(DefKind::TraitAlias, did) => { record_extern_fqn(cx, did, ItemType::TraitAlias); - cx.with_param_env(did, |cx| clean::TraitAliasItem(build_trait_alias(cx, did))) + cx.with_param_env(did, |cx| ItemKind::TraitAlias(build_trait_alias(cx, did))) } Res::Def(DefKind::Fn, did) => { record_extern_fqn(cx, did, ItemType::Function); cx.with_param_env(did, |cx| { - clean::enter_impl_trait(cx, |cx| clean::FunctionItem(build_function(cx, did))) + clean::enter_impl_trait(cx, |cx| ItemKind::Fn(build_function(cx, did))) }) } Res::Def(DefKind::Struct, did) => { record_extern_fqn(cx, did, ItemType::Struct); cx.with_param_env(did, |cx| { build_impls(cx, did, attrs_without_docs, &mut ret); - clean::StructItem(build_struct(cx, did)) + ItemKind::Struct(build_struct(cx, did)) }) } Res::Def(DefKind::Union, did) => { record_extern_fqn(cx, did, ItemType::Union); cx.with_param_env(did, |cx| { build_impls(cx, did, attrs_without_docs, &mut ret); - clean::UnionItem(build_union(cx, did)) + ItemKind::Union(build_union(cx, did)) }) } Res::Def(DefKind::TyAlias, did) => { record_extern_fqn(cx, did, ItemType::TypeAlias); cx.with_param_env(did, |cx| { build_impls(cx, did, attrs_without_docs, &mut ret); - clean::TypeAliasItem(build_type_alias(cx, did, &mut ret)) + ItemKind::TyAlias(build_type_alias(cx, did, &mut ret)) }) } Res::Def(DefKind::Enum, did) => { record_extern_fqn(cx, did, ItemType::Enum); cx.with_param_env(did, |cx| { build_impls(cx, did, attrs_without_docs, &mut ret); - clean::EnumItem(build_enum(cx, did)) + ItemKind::Enum(build_enum(cx, did)) }) } Res::Def(DefKind::ForeignTy, did) => { record_extern_fqn(cx, did, ItemType::ForeignType); cx.with_param_env(did, |cx| { build_impls(cx, did, attrs_without_docs, &mut ret); - clean::ForeignTypeItem + ItemKind::ForeignTy }) } // Never inline enum variants but leave them shown as re-exports. @@ -142,19 +142,19 @@ pub(crate) fn try_inline( Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) => return Some(Vec::new()), Res::Def(DefKind::Mod, did) => { record_extern_fqn(cx, did, ItemType::Module); - clean::ModuleItem(build_module(cx, did, name, visited)) + ItemKind::Module(build_module(cx, did, name, visited)) } Res::Def(DefKind::Static { .. }, did) => { record_extern_fqn(cx, did, ItemType::Static); cx.with_param_env(did, |cx| { - clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did))) + ItemKind::Static(build_static(cx, did, cx.tcx.is_mutable_static(did))) }) } Res::Def(DefKind::Const, did) => { record_extern_fqn(cx, did, ItemType::Constant); cx.with_param_env(did, |cx| { let ct = build_const_item(cx, did); - clean::ConstantItem(Box::new(ct)) + ItemKind::Const(Box::new(ct)) }) } Res::Def(DefKind::Macro(kinds), did) => { @@ -650,7 +650,7 @@ pub(crate) fn build_impl( ret.push(clean::Item::from_def_id_and_attrs_and_parts( did, None, - clean::ImplItem(Box::new(clean::Impl { + ItemKind::Impl(Box::new(clean::Impl { safety: hir::Safety::Safe, generics, trait_, @@ -756,7 +756,7 @@ fn build_module_items( item_id: ItemId::DefId(module_def_id), attrs: Default::default(), stability: None, - kind: clean::ImportItem(clean::Import::new_simple( + kind: ItemKind::Import(clean::Import::new_simple( item.ident.name, clean::ImportSource { path: clean::Path { @@ -795,7 +795,7 @@ fn build_module_items( let item = Item::from_def_id_and_parts( module_def_id, None, - clean::ImportItem(clean::Import::new_simple( + ItemKind::Import(clean::Import::new_simple( item.ident.name, clean::ImportSource { path: clean::Path { @@ -850,7 +850,7 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant { None, None, ); - clean::Constant { generics, type_: ty, kind: clean::ConstantKind::Extern { def_id } } + clean::Constant { generics, ty, rhs: clean::ConstantKind::Extern { def_id } } } fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static { @@ -866,23 +866,17 @@ fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::St } } -fn build_macro( - tcx: TyCtxt<'_>, - def_id: DefId, - name: Symbol, - macro_kinds: MacroKinds, -) -> clean::ItemKind { +fn build_macro(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol, macro_kinds: MacroKinds) -> ItemKind { match CStore::from_tcx(tcx).load_macro_untracked(tcx, def_id) { LoadedMacro::MacroDef { def, .. } => match macro_kinds { - MacroKinds::DERIVE => clean::ProcMacroItem(clean::ProcMacro { + MacroKinds::DERIVE => ItemKind::ProcMacro(clean::ProcMacro { kind: MacroKind::Derive, helpers: Vec::new(), }), - MacroKinds::ATTR => clean::ProcMacroItem(clean::ProcMacro { - kind: MacroKind::Attr, - helpers: Vec::new(), - }), - _ => clean::MacroItem( + MacroKinds::ATTR => { + ItemKind::ProcMacro(clean::ProcMacro { kind: MacroKind::Attr, helpers: Vec::new() }) + } + _ => ItemKind::DeclMacro( clean::Macro { source: utils::display_macro_source(tcx, name, &def), macro_rules: def.macro_rules, @@ -898,7 +892,7 @@ fn build_macro( MacroKinds::DERIVE => MacroKind::Derive, _ => unreachable!(), }; - clean::ProcMacroItem(clean::ProcMacro { kind, helpers: ext.helper_attrs }) + ItemKind::ProcMacro(clean::ProcMacro { kind, helpers: ext.helper_attrs }) } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1078f48855fbf..e28e25baffac2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -166,7 +166,7 @@ pub(crate) fn clean_doc_module<'tcx>( } }); - let kind = ModuleItem(Module { items, span }); + let kind = ItemKind::Module(Module { items, span }); generate_item_with_correct_attrs( cx, kind, @@ -246,7 +246,7 @@ fn generate_item_with_correct_attrs( is_inline = is_inline || import_is_inline; attrs.extend(get_all_import_attributes(cx, import_id, def_id, is_inline)); } - let keep_target_cfg = is_inline || matches!(kind, ItemKind::TypeAliasItem(..)); + let keep_target_cfg = is_inline || matches!(kind, ItemKind::TyAlias(..)); add_without_unwanted_attributes(&mut attrs, target_attrs, keep_target_cfg, None); attrs } else { @@ -1048,17 +1048,17 @@ fn clean_proc_macro<'tcx>( tcx: TyCtxt<'tcx>, ) -> ItemKind { if kind != MacroKind::Derive { - return ProcMacroItem(ProcMacro { kind, helpers: vec![] }); + return ItemKind::ProcMacro(ProcMacro { kind, helpers: vec![] }); } let attrs = tcx.hir_attrs(item.hir_id()); let Some((trait_name, helper_attrs)) = find_attr!(attrs, ProcMacroDerive { trait_name, helper_attrs, ..} => (*trait_name, helper_attrs)) else { - return ProcMacroItem(ProcMacro { kind, helpers: vec![] }); + return ItemKind::ProcMacro(ProcMacro { kind, helpers: vec![] }); }; *name = trait_name; let helpers = helper_attrs.iter().copied().collect(); - ProcMacroItem(ProcMacro { kind, helpers }) + ItemKind::ProcMacro(ProcMacro { kind, helpers }) } fn clean_fn_or_proc_macro<'tcx>( @@ -1091,7 +1091,7 @@ fn clean_fn_or_proc_macro<'tcx>( item.owner_id.to_def_id(), ); clean_fn_decl_legacy_const_generics(&mut func, attrs); - FunctionItem(func) + ItemKind::Fn(func) } } } @@ -1276,38 +1276,30 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext let local_did = trait_item.owner_id.to_def_id(); cx.with_param_env(local_did, |cx| { let inner = match trait_item.kind { - hir::TraitItemKind::Const(ty, Some(default)) => { - ProvidedAssocConstItem(Box::new(Constant { - generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)), - kind: clean_const_item_rhs(default, local_did), - type_: clean_ty(ty, cx), - })) - } - hir::TraitItemKind::Const(ty, None) => { - let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); - RequiredAssocConstItem(generics, Box::new(clean_ty(ty, cx))) - } - hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { - let m = - clean_function(cx, sig, trait_item.generics, ParamsSrc::Body(body), local_did); - MethodItem(m, Defaultness::from_trait_item(trait_item.defaultness)) - } - hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(idents)) => { - let m = clean_function( - cx, - sig, - trait_item.generics, - ParamsSrc::Idents(idents), - local_did, - ); - RequiredMethodItem(m, Defaultness::from_trait_item(trait_item.defaultness)) + hir::TraitItemKind::Const(ty, default) => ItemKind::AssocConst(Box::new(AssocConst { + generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)), + ty: clean_ty(ty, cx), + rhs: default.map(|default| clean_const_item_rhs(default, local_did)), + })), + hir::TraitItemKind::Fn(ref sig, body) => { + let (params, body) = match body { + hir::TraitFn::Provided(body) => ( + ParamsSrc::Body(body), + Some(Defaultness::from_trait_item(trait_item.defaultness)), + ), + hir::TraitFn::Required(idents) => (ParamsSrc::Idents(idents), None), + }; + ItemKind::AssocFn( + clean_function(cx, sig, trait_item.generics, params, local_did), + body, + ) } hir::TraitItemKind::Type(bounds, Some(default)) => { let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(); let item_type = clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, default)), cx, None, None); - AssocTypeItem( + ItemKind::AssocTy( Box::new(TypeAlias { type_: clean_ty(default, cx), generics, @@ -1320,7 +1312,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext hir::TraitItemKind::Type(bounds, None) => { let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(); - RequiredAssocTypeItem(generics, bounds) + ItemKind::RequiredAssocTy(generics, bounds) } }; Item::from_def_id_and_parts(local_did, Some(trait_item.ident.name), inner, cx.tcx) @@ -1334,10 +1326,10 @@ pub(crate) fn clean_impl_item<'tcx>( let local_did = impl_.owner_id.to_def_id(); cx.with_param_env(local_did, |cx| { let inner = match impl_.kind { - hir::ImplItemKind::Const(ty, expr) => ImplAssocConstItem(Box::new(Constant { + hir::ImplItemKind::Const(ty, expr) => ItemKind::AssocConst(Box::new(AssocConst { generics: clean_generics(impl_.generics, cx), - kind: clean_const_item_rhs(expr, local_did), - type_: clean_ty(ty, cx), + ty: clean_ty(ty, cx), + rhs: Some(clean_const_item_rhs(expr, local_did)), })), hir::ImplItemKind::Fn(ref sig, body) => { let m = clean_function(cx, sig, impl_.generics, ParamsSrc::Body(body), local_did); @@ -1345,14 +1337,14 @@ pub(crate) fn clean_impl_item<'tcx>( hir::ImplItemImplKind::Inherent { .. } => hir::Defaultness::Final, hir::ImplItemImplKind::Trait { defaultness, .. } => defaultness, }; - MethodItem(m, Defaultness::from_impl_item(defaultness)) + ItemKind::AssocFn(m, Some(Defaultness::from_impl_item(defaultness))) } hir::ImplItemKind::Type(hir_ty) => { let type_ = clean_ty(hir_ty, cx); let generics = clean_generics(impl_.generics, cx); let item_type = clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None); - AssocTypeItem( + ItemKind::AssocTy( Box::new(TypeAlias { type_, generics, @@ -1384,26 +1376,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo let mut generics = clean_ty_generics(cx, assoc_item.def_id); simplify::move_bounds_to_generic_parameters(&mut generics); - match assoc_item.container { - ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => { - ImplAssocConstItem(Box::new(Constant { - generics, - kind: ConstantKind::Extern { def_id: assoc_item.def_id }, - type_: ty, - })) - } - ty::AssocContainer::Trait => { - if tcx.defaultness(assoc_item.def_id).has_value() { - ProvidedAssocConstItem(Box::new(Constant { - generics, - kind: ConstantKind::Extern { def_id: assoc_item.def_id }, - type_: ty, - })) - } else { - RequiredAssocConstItem(generics, Box::new(ty)) - } - } - } + ItemKind::AssocConst(Box::new(AssocConst { + generics, + ty, + rhs: assoc_item + .defaultness(tcx) + .has_value() + .then_some(ConstantKind::Extern { def_id: assoc_item.def_id }), + })) } ty::AssocKind::Fn { has_self, .. } => { let mut item = inline::build_function(cx, assoc_item.def_id); @@ -1435,20 +1415,14 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo } let defaultness = assoc_item.defaultness(tcx); - let (provided, defaultness) = match assoc_item.container { - ty::AssocContainer::Trait => { - (defaultness.has_value(), Defaultness::from_trait_item(defaultness)) - } + let body = match assoc_item.container { + ty::AssocContainer::Trait if !defaultness.has_value() => None, + ty::AssocContainer::Trait => Some(Defaultness::from_trait_item(defaultness)), ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => { - (true, Defaultness::from_impl_item(defaultness)) + Some(Defaultness::from_impl_item(defaultness)) } }; - - if provided { - MethodItem(item, defaultness) - } else { - RequiredMethodItem(item, defaultness) - } + ItemKind::AssocFn(item, body) } ty::AssocKind::Type { .. } => { let my_name = assoc_item.name(); @@ -1557,7 +1531,7 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo } if tcx.defaultness(assoc_item.def_id).has_value() { - AssocTypeItem( + ItemKind::AssocTy( Box::new(TypeAlias { type_: clean_middle_ty( ty::Binder::dummy( @@ -1576,10 +1550,10 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo bounds, ) } else { - RequiredAssocTypeItem(generics, bounds) + ItemKind::RequiredAssocTy(generics, bounds) } } else { - AssocTypeItem( + ItemKind::AssocTy( Box::new(TypeAlias { type_: clean_middle_ty( ty::Binder::dummy( @@ -2510,7 +2484,7 @@ pub(crate) fn clean_field_with_def_id( ty: Type, tcx: TyCtxt<'_>, ) -> Item { - Item::from_def_id_and_parts(def_id, Some(name), StructFieldItem(ty), tcx) + Item::from_def_id_and_parts(def_id, Some(name), ItemKind::StructField(ty), tcx) } pub(crate) fn clean_variant_def(variant: &ty::VariantDef, cx: &mut DocContext<'_>) -> Item { @@ -2532,7 +2506,7 @@ pub(crate) fn clean_variant_def(variant: &ty::VariantDef, cx: &mut DocContext<'_ Item::from_def_id_and_parts( variant.def_id, Some(variant.name), - VariantItem(Variant { kind, discriminant }), + ItemKind::Variant(Variant { kind, discriminant }), cx.tcx, ) } @@ -2609,7 +2583,7 @@ pub(crate) fn clean_variant_def_with_args<'tcx>( Item::from_def_id_and_parts( variant.def_id, Some(variant.name), - VariantItem(Variant { kind, discriminant }), + ItemKind::Variant(Variant { kind, discriminant }), cx.tcx, ) } @@ -2876,7 +2850,6 @@ fn clean_maybe_renamed_item<'tcx>( renamed: Option, import_ids: &[LocalDefId], ) -> Vec { - use hir::ItemKind; fn get_name(tcx: TyCtxt<'_>, item: &hir::Item<'_>, renamed: Option) -> Option { renamed.or_else(|| tcx.hir_opt_name(item.hir_id())) } @@ -2886,13 +2859,13 @@ fn clean_maybe_renamed_item<'tcx>( // These kinds of item either don't need a `name` or accept a `None` one so we handle them // before. match item.kind { - ItemKind::Impl(ref impl_) => { + hir::ItemKind::Impl(ref impl_) => { // If `renamed` is `Some()` for an `impl`, it means it's been inlined because we use // it as a marker to indicate that this is an inlined impl and that we should // generate an impl placeholder and not a "real" impl item. return clean_impl(impl_, item.owner_id.def_id, cx, renamed.is_some()); } - ItemKind::Use(path, kind) => { + hir::ItemKind::Use(path, kind) => { return clean_use_statement( item, get_name(cx.tcx, item, renamed), @@ -2908,17 +2881,17 @@ fn clean_maybe_renamed_item<'tcx>( let mut name = get_name(cx.tcx, item, renamed).unwrap(); let kind = match item.kind { - ItemKind::Static(mutability, _, ty, body_id) => StaticItem(Static { + hir::ItemKind::Static(mutability, _, ty, body_id) => ItemKind::Static(Static { type_: Box::new(clean_ty(ty, cx)), mutability, expr: Some(body_id), }), - ItemKind::Const(_, generics, ty, rhs) => ConstantItem(Box::new(Constant { + hir::ItemKind::Const(_, generics, ty, rhs) => ItemKind::Const(Box::new(Constant { generics: clean_generics(generics, cx), - type_: clean_ty(ty, cx), - kind: clean_const_item_rhs(rhs, def_id), + ty: clean_ty(ty, cx), + rhs: clean_const_item_rhs(rhs, def_id), })), - ItemKind::TyAlias(_, generics, ty) => { + hir::ItemKind::TyAlias(_, generics, ty) => { *cx.current_type_aliases.entry(def_id).or_insert(0) += 1; let rustdoc_ty = clean_ty(ty, cx); let type_ = @@ -2938,7 +2911,7 @@ fn clean_maybe_renamed_item<'tcx>( ret.push(generate_item_with_correct_attrs( cx, - TypeAliasItem(Box::new(TypeAlias { + ItemKind::TyAlias(Box::new(TypeAlias { generics, inner_type, type_: rustdoc_ty, @@ -2951,27 +2924,27 @@ fn clean_maybe_renamed_item<'tcx>( )); return ret; } - ItemKind::Enum(_, generics, def) => EnumItem(Enum { + hir::ItemKind::Enum(_, generics, def) => ItemKind::Enum(Enum { variants: def.variants.iter().map(|v| clean_variant(v, cx)).collect(), generics: clean_generics(generics, cx), }), - ItemKind::TraitAlias(_, _, generics, bounds) => TraitAliasItem(TraitAlias { + hir::ItemKind::TraitAlias(_, _, generics, bounds) => ItemKind::TraitAlias(TraitAlias { generics: clean_generics(generics, cx), bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(), }), - ItemKind::Union(_, generics, variant_data) => UnionItem(Union { + hir::ItemKind::Union(_, generics, variant_data) => ItemKind::Union(Union { generics: clean_generics(generics, cx), fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(), }), - ItemKind::Struct(_, generics, variant_data) => StructItem(Struct { + hir::ItemKind::Struct(_, generics, variant_data) => ItemKind::Struct(Struct { ctor_kind: variant_data.ctor_kind(), generics: clean_generics(generics, cx), fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(), }), - ItemKind::Macro(_, macro_def, kinds) => match kinds { + hir::ItemKind::Macro(_, macro_def, kinds) => match kinds { MacroKinds::ATTR => clean_proc_macro(item, &mut name, MacroKind::Attr, cx.tcx), MacroKinds::DERIVE => clean_proc_macro(item, &mut name, MacroKind::Derive, cx.tcx), - _ => MacroItem( + _ => ItemKind::DeclMacro( Macro { source: display_macro_source(cx.tcx, name, macro_def), macro_rules: macro_def.macro_rules, @@ -2980,24 +2953,23 @@ fn clean_maybe_renamed_item<'tcx>( ), }, // proc macros can have a name set by attributes - ItemKind::Fn { ref sig, generics, body: body_id, .. } => { + hir::ItemKind::Fn { ref sig, generics, body: body_id, .. } => { clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } - // FIXME: rustdoc will need to handle `impl` restrictions at some point - ItemKind::Trait { generics, bounds, items: item_ids, .. } => { + hir::ItemKind::Trait { generics, bounds, items: item_ids, .. } => { let items = item_ids .iter() .map(|&ti| clean_trait_item(cx.tcx.hir_trait_item(ti), cx)) .collect(); - TraitItem(Box::new(Trait { + ItemKind::Trait(Box::new(Trait { def_id, items, generics: clean_generics(generics, cx), bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(), })) } - ItemKind::ExternCrate(orig_name, _) => { + hir::ItemKind::ExternCrate(orig_name, _) => { return clean_extern_crate(item, name, orig_name, cx); } _ => span_bug!(item.span, "not yet converted"), @@ -3015,7 +2987,7 @@ fn clean_maybe_renamed_item<'tcx>( } fn clean_variant<'tcx>(variant: &hir::Variant<'tcx>, cx: &mut DocContext<'tcx>) -> Item { - let kind = VariantItem(clean_variant_data(&variant.data, &variant.disr_expr, cx)); + let kind = ItemKind::Variant(clean_variant_data(&variant.data, &variant.disr_expr, cx)); Item::from_def_id_and_parts(variant.def_id.to_def_id(), Some(variant.ident.name), kind, cx.tcx) } @@ -3036,7 +3008,7 @@ fn clean_impl<'tcx>( return vec![Item::from_def_id_and_parts( def_id.to_def_id(), None, - PlaceholderImplItem, + ItemKind::PlaceholderImpl, tcx, )]; } @@ -3073,7 +3045,7 @@ fn clean_impl<'tcx>( .lookup_deprecation(def_id.to_def_id()) .is_some_and(|deprecation| deprecation.is_in_effect()); let mut make_item = |trait_: Option, for_: Type, items: Vec| { - let kind = ImplItem(Box::new(Impl { + let kind = ItemKind::Impl(Box::new(Impl { safety: match impl_.of_trait { Some(of_trait) => of_trait.safety, None => hir::Safety::Safe, @@ -3141,7 +3113,7 @@ fn clean_extern_crate<'tcx>( vec![Item::from_def_id_and_parts( krate_owner_def_id.to_def_id(), Some(name), - ExternCrateItem { src: orig_name }, + ItemKind::ExternCrate { src: orig_name }, cx.tcx, )] } @@ -3270,7 +3242,7 @@ fn clean_use_statement_inner<'tcx>( items.push(Item::from_def_id_and_parts( import_def_id.to_def_id(), None, - ImportItem(Import::new_simple(name, resolve_use_source(cx, path), false)), + ItemKind::Import(Import::new_simple(name, resolve_use_source(cx, path), false)), cx.tcx, )); return items; @@ -3278,7 +3250,12 @@ fn clean_use_statement_inner<'tcx>( Import::new_simple(name, resolve_use_source(cx, path), true) }; - vec![Item::from_def_id_and_parts(import_def_id.to_def_id(), None, ImportItem(inner), cx.tcx)] + vec![Item::from_def_id_and_parts( + import_def_id.to_def_id(), + None, + ItemKind::Import(inner), + cx.tcx, + )] } fn clean_maybe_renamed_foreign_item<'tcx>( @@ -3290,15 +3267,15 @@ fn clean_maybe_renamed_foreign_item<'tcx>( let def_id = item.owner_id.to_def_id(); cx.with_param_env(def_id, |cx| { let kind = match item.kind { - hir::ForeignItemKind::Fn(sig, idents, generics) => ForeignFunctionItem( + hir::ForeignItemKind::Fn(sig, idents, generics) => ItemKind::ForeignFn( clean_function(cx, &sig, generics, ParamsSrc::Idents(idents), def_id), sig.header.safety(), ), - hir::ForeignItemKind::Static(ty, mutability, safety) => ForeignStaticItem( + hir::ForeignItemKind::Static(ty, mutability, safety) => ItemKind::ForeignStatic( Static { type_: Box::new(clean_ty(ty, cx)), mutability, expr: None }, safety, ), - hir::ForeignItemKind::Type => ForeignTypeItem, + hir::ForeignItemKind::Type => ItemKind::ForeignTy, }; let mut clean_item = generate_item_with_correct_attrs( diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 1b5968e20e4b4..eb9d498014ec8 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -30,7 +30,6 @@ use rustc_span::symbol::{Symbol, kw, sym}; use rustc_span::{DUMMY_SP, FileName, Ident, Loc, RemapPathScopeComponents, span_bug}; use tracing::{debug, trace}; -pub(crate) use self::ItemKind::*; pub(crate) use self::Type::{ Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath, RawPointer, SelfTy, Slice, Tuple, UnsafeBinder, @@ -452,7 +451,7 @@ impl Item { pub(crate) fn is_exported_macro(&self) -> bool { match self.kind { - ItemKind::MacroItem(..) => find_attr!(&self.attrs.other_attrs, MacroExport { .. }), + ItemKind::DeclMacro(..) => find_attr!(&self.attrs.other_attrs, MacroExport { .. }), _ => false, } } @@ -471,7 +470,7 @@ impl Item { /// Returns true if item is an associated function with a `self` parameter. pub(crate) fn has_self_param(&self) -> bool { - if let ItemKind::MethodItem(Function { decl, .. }, _) = &self.inner.kind { + if let ItemKind::AssocFn(Function { decl, .. }, _) = &self.inner.kind { decl.receiver_type().is_some() } else { false @@ -480,13 +479,13 @@ impl Item { pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Option { let kind = match &self.kind { - ItemKind::StrippedItem(k) => k, + ItemKind::Stripped(k) => k, _ => &self.kind, }; match kind { - ItemKind::ModuleItem(Module { span, .. }) => Some(*span), - ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => None, - ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => { + ItemKind::Module(Module { span, .. }) => Some(*span), + ItemKind::Impl(Impl { kind: ImplKind::Auto, .. }) => None, + ItemKind::Impl(Impl { kind: ImplKind::Blanket(_), .. }) => { if let ItemId::Blanket { impl_id, .. } = self.item_id { Some(rustc_span(impl_id, tcx)) } else { @@ -647,21 +646,21 @@ impl Item { self.type_() == ItemType::Variant } pub(crate) fn is_associated_type(&self) -> bool { - matches!(self.kind, AssocTypeItem(..) | StrippedItem(AssocTypeItem(..))) + matches!(self.kind, ItemKind::AssocTy(..) | ItemKind::Stripped(ItemKind::AssocTy(..))) } pub(crate) fn is_required_associated_type(&self) -> bool { - matches!(self.kind, RequiredAssocTypeItem(..) | StrippedItem(RequiredAssocTypeItem(..))) - } - pub(crate) fn is_associated_const(&self) -> bool { matches!( self.kind, - ProvidedAssocConstItem(..) - | ImplAssocConstItem(..) - | StrippedItem(ProvidedAssocConstItem(..) | ImplAssocConstItem(..)) + ItemKind::RequiredAssocTy(..) | ItemKind::Stripped(ItemKind::RequiredAssocTy(..)) ) } - pub(crate) fn is_required_associated_const(&self) -> bool { - matches!(self.kind, RequiredAssocConstItem(..) | StrippedItem(RequiredAssocConstItem(..))) + pub(crate) fn is_assoc_const_with_body(&self) -> bool { + let kind = if let ItemKind::Stripped(kind) = &self.kind { kind } else { &self.kind }; + matches!(kind, ItemKind::AssocConst(AssocConst { rhs: Some(_), .. })) + } + pub(crate) fn is_assoc_const_without_body(&self) -> bool { + let kind = if let ItemKind::Stripped(kind) = &self.kind { kind } else { &self.kind }; + matches!(kind, ItemKind::AssocConst(AssocConst { rhs: None, .. })) } pub(crate) fn is_method(&self) -> bool { self.type_() == ItemType::Method @@ -700,18 +699,18 @@ impl Item { } pub(crate) fn is_stripped(&self) -> bool { match self.kind { - StrippedItem(..) => true, - ImportItem(ref i) => !i.should_be_displayed, + ItemKind::Stripped(..) => true, + ItemKind::Import(ref i) => !i.should_be_displayed, _ => false, } } pub(crate) fn has_stripped_entries(&self) -> Option { match self.kind { - StructItem(ref struct_) => Some(struct_.has_stripped_entries()), - UnionItem(ref union_) => Some(union_.has_stripped_entries()), - EnumItem(ref enum_) => Some(enum_.has_stripped_entries()), - VariantItem(ref v) => v.has_stripped_entries(), - TypeAliasItem(ref type_alias) => { + ItemKind::Struct(ref struct_) => Some(struct_.has_stripped_entries()), + ItemKind::Union(ref union_) => Some(union_.has_stripped_entries()), + ItemKind::Enum(ref enum_) => Some(enum_.has_stripped_entries()), + ItemKind::Variant(ref v) => v.has_stripped_entries(), + ItemKind::TyAlias(ref type_alias) => { type_alias.inner_type.as_ref().and_then(|t| t.has_stripped_entries()) } _ => None, @@ -753,7 +752,7 @@ impl Item { /// Returns an item types. There is only one case where it can return more than one kind: /// for `macro_rules!` items which contain an attr/derive kind. pub(crate) fn types(&self) -> impl Iterator { - if let ItemKind::MacroItem(_, macro_kinds) = self.kind { + if let ItemKind::DeclMacro(_, macro_kinds) = self.kind { Either::Right(macro_kinds.iter().map(|kind| match kind { MacroKinds::ATTR => ItemType::DeclMacroAttribute, MacroKinds::DERIVE => ItemType::DeclMacroDerive, @@ -767,16 +766,7 @@ impl Item { /// Returns true if this a macro declared with the `macro` keyword or with `macro_rules!. pub(crate) fn is_decl_macro(&self) -> bool { - matches!(self.kind, ItemKind::MacroItem(..)) - } - - pub(crate) fn defaultness(&self) -> Option { - match self.kind { - ItemKind::MethodItem(_, defaultness) | ItemKind::RequiredMethodItem(_, defaultness) => { - Some(defaultness) - } - _ => None, - } + matches!(self.kind, ItemKind::DeclMacro(..)) } /// Generates the HTML file name based on the item kind. @@ -823,7 +813,7 @@ impl Item { } } let header = match self.kind { - ItemKind::ForeignFunctionItem(_, safety) => { + ItemKind::ForeignFn(_, safety) => { let def_id = self.def_id().unwrap(); let abi = tcx.fn_sig(def_id).skip_binder().abi(); hir::FnHeader { @@ -838,9 +828,7 @@ impl Item { asyncness: hir::IsAsync::NotAsync, } } - ItemKind::FunctionItem(_) - | ItemKind::MethodItem(..) - | ItemKind::RequiredMethodItem(..) => { + ItemKind::Fn(_) | ItemKind::AssocFn(..) => { let def_id = self.def_id().unwrap(); build_fn_header(def_id, tcx, tcx.asyncness(def_id)) } @@ -862,23 +850,20 @@ impl Item { // Primitives and Keywords are written in the source code as private modules. // The modules need to be private so that nobody actually uses them, but the // keywords and primitives that they are documenting are public. - ItemKind::KeywordItem | ItemKind::PrimitiveItem(_) | ItemKind::AttributeItem => { + ItemKind::Keyword | ItemKind::Primitive(_) | ItemKind::Attribute => { return Some(Visibility::Public); } // Variant fields inherit their enum's visibility. - StructFieldItem(..) if is_field_vis_inherited(tcx, def_id) => { + ItemKind::StructField(..) if is_field_vis_inherited(tcx, def_id) => { return None; } // Variants always inherit visibility - VariantItem(..) | ImplItem(..) => return None, + ItemKind::Variant(..) | ItemKind::Impl(..) => return None, // Trait items inherit the trait's visibility - RequiredAssocConstItem(..) - | ProvidedAssocConstItem(..) - | ImplAssocConstItem(..) - | AssocTypeItem(..) - | RequiredAssocTypeItem(..) - | RequiredMethodItem(..) - | MethodItem(..) => { + ItemKind::AssocConst(..) + | ItemKind::AssocTy(..) + | ItemKind::RequiredAssocTy(..) + | ItemKind::AssocFn(..) => { match tcx.associated_item(def_id).container { // Trait impl items always inherit the impl's visibility -- // we don't want to show `pub`. @@ -908,68 +893,58 @@ impl Item { #[derive(Clone, Debug)] pub(crate) enum ItemKind { - ExternCrateItem { + ExternCrate { /// The crate's name, *not* the name it's imported as. src: Option, }, - ImportItem(Import), - StructItem(Struct), - UnionItem(Union), - EnumItem(Enum), - FunctionItem(Box), - ModuleItem(Module), - TypeAliasItem(Box), - StaticItem(Static), - TraitItem(Box), - TraitAliasItem(TraitAlias), - ImplItem(Box), + Import(Import), + Struct(Struct), + Union(Union), + Enum(Enum), + Fn(Box), + Module(Module), + TyAlias(Box), + Static(Static), + Trait(Box), + TraitAlias(TraitAlias), + Impl(Box), /// This variant is used only as a placeholder for trait impls in order to correctly compute /// `doc_cfg` as trait impls are added to `clean::Crate` after we went through the whole tree. - PlaceholderImplItem, - /// A required method in a trait declaration meaning it's only a function signature. - RequiredMethodItem(Box, Defaultness), - /// A method in a trait impl or a provided method in a trait declaration. - /// - /// Compared to [RequiredMethodItem], it also contains a method body. - MethodItem(Box, Defaultness), - StructFieldItem(Type), - VariantItem(Variant), + PlaceholderImpl, + AssocFn(Box, Option), + StructField(Type), + Variant(Variant), /// `fn`s from an extern block - ForeignFunctionItem(Box, hir::Safety), + ForeignFn(Box, hir::Safety), /// `static`s from an extern block - ForeignStaticItem(Static, hir::Safety), + ForeignStatic(Static, hir::Safety), /// `type`s from an extern block - ForeignTypeItem, + ForeignTy, /// A macro defined with `macro_rules` or the `macro` keyword. It can be multiple things (macro, /// derive and attribute, potentially multiple at once). Don't forget to look into the ///`MacroKinds` values. /// /// If a `macro_rules!` only contains a `attr`/`derive` branch, then it's not stored in this /// variant but in the `ProcMacroItem` variant. - MacroItem(Macro, MacroKinds), - ProcMacroItem(ProcMacro), - PrimitiveItem(PrimitiveType), - /// A required associated constant in a trait declaration. - RequiredAssocConstItem(Generics, Box), - ConstantItem(Box), - /// An associated constant in a trait declaration with provided default value. - ProvidedAssocConstItem(Box), - /// An associated constant in an inherent impl or trait impl. - ImplAssocConstItem(Box), + DeclMacro(Macro, MacroKinds), + ProcMacro(ProcMacro), + Primitive(PrimitiveType), + Const(Box), + AssocConst(Box), /// A required associated type in a trait declaration. /// /// The bounds may be non-empty if there is a `where` clause. - RequiredAssocTypeItem(Generics, Vec), + RequiredAssocTy(Generics, Vec), /// An associated type in a trait impl or a provided one in a trait declaration. - AssocTypeItem(Box, Vec), + AssocTy(Box, Vec), /// An item that has been stripped by a rustdoc pass - StrippedItem(Box), + Stripped(Box), /// This item represents an anonymous constant with a `#[doc(keyword = "...")]` attribute which is used /// to generate documentation for Rust keywords. - KeywordItem, + Keyword, /// This item represents an anonymous constant with a `#[doc(attribute = "...")]` attribute which is used /// to generate documentation for Rust builtin attributes. - AttributeItem, + Attribute, } impl ItemKind { @@ -977,42 +952,39 @@ impl ItemKind { /// (for their variants). This method returns those contained items. pub(crate) fn inner_items(&self) -> impl Iterator { match self { - StructItem(s) => s.fields.iter(), - UnionItem(u) => u.fields.iter(), - VariantItem(v) => match &v.kind { + Self::Struct(s) => s.fields.iter(), + Self::Union(u) => u.fields.iter(), + Self::Variant(v) => match &v.kind { VariantKind::CLike => [].iter(), VariantKind::Tuple(t) => t.iter(), VariantKind::Struct(s) => s.fields.iter(), }, - EnumItem(e) => e.variants.iter(), - TraitItem(t) => t.items.iter(), - ImplItem(i) => i.items.iter(), - ModuleItem(m) => m.items.iter(), - ExternCrateItem { .. } - | ImportItem(_) - | FunctionItem(_) - | TypeAliasItem(_) - | StaticItem(_) - | ConstantItem(_) - | TraitAliasItem(_) - | RequiredMethodItem(..) - | MethodItem(..) - | StructFieldItem(_) - | ForeignFunctionItem(_, _) - | ForeignStaticItem(_, _) - | ForeignTypeItem - | MacroItem(..) - | ProcMacroItem(_) - | PrimitiveItem(_) - | RequiredAssocConstItem(..) - | ProvidedAssocConstItem(..) - | ImplAssocConstItem(..) - | RequiredAssocTypeItem(..) - | AssocTypeItem(..) - | StrippedItem(_) - | KeywordItem - | AttributeItem - | PlaceholderImplItem => [].iter(), + Self::Enum(e) => e.variants.iter(), + Self::Trait(t) => t.items.iter(), + Self::Impl(i) => i.items.iter(), + Self::Module(m) => m.items.iter(), + Self::ExternCrate { .. } + | Self::Import(_) + | Self::Fn(_) + | Self::TyAlias(_) + | Self::Static(_) + | Self::Const(_) + | Self::TraitAlias(_) + | Self::AssocFn(..) + | Self::StructField(_) + | Self::ForeignFn(_, _) + | Self::ForeignStatic(_, _) + | Self::ForeignTy + | Self::DeclMacro(..) + | Self::ProcMacro(_) + | Self::Primitive(_) + | Self::AssocConst(..) + | Self::RequiredAssocTy(..) + | Self::AssocTy(..) + | Self::Stripped(_) + | Self::Keyword + | Self::Attribute + | Self::PlaceholderImpl => [].iter(), } } } @@ -2287,11 +2259,18 @@ pub(crate) struct Static { pub(crate) expr: Option, } -#[derive(Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Clone, Debug)] pub(crate) struct Constant { pub(crate) generics: Generics, - pub(crate) kind: ConstantKind, - pub(crate) type_: Type, + pub(crate) ty: Type, + pub(crate) rhs: ConstantKind, +} + +#[derive(Clone, Debug)] +pub(crate) struct AssocConst { + pub(crate) generics: Generics, + pub(crate) ty: Type, + pub(crate) rhs: Option, } #[derive(Clone, PartialEq, Eq, Hash, Debug)] diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 012c4997db9c1..fbe0bf0ccfffa 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -44,7 +44,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate { let mut module = clean_doc_module(&module, cx); match module.kind { - ItemKind::ModuleItem(ref module) => { + ItemKind::Module(ref module) => { for it in &module.items { // `compiler_builtins` should be masked too, but we can't apply // `#[doc(masked)]` to the injected `extern crate` because it's unstable. @@ -68,20 +68,20 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate { let keywords = local_crate.keywords(cx.tcx); let documented_attributes = local_crate.documented_attributes(cx.tcx); { - let ItemKind::ModuleItem(m) = &mut module.inner.kind else { unreachable!() }; + let ItemKind::Module(m) = &mut module.inner.kind else { unreachable!() }; m.items.extend(primitives.map(|(def_id, prim)| { Item::from_def_id_and_parts( def_id, Some(prim.as_sym()), - ItemKind::PrimitiveItem(prim), + ItemKind::Primitive(prim), cx.tcx, ) })); m.items.extend(keywords.map(|(def_id, kw)| { - Item::from_def_id_and_parts(def_id, Some(kw), ItemKind::KeywordItem, cx.tcx) + Item::from_def_id_and_parts(def_id, Some(kw), ItemKind::Keyword, cx.tcx) })); m.items.extend(documented_attributes.into_iter().map(|(def_id, kw)| { - Item::from_def_id_and_parts(def_id, Some(kw), ItemKind::AttributeItem, cx.tcx) + Item::from_def_id_and_parts(def_id, Some(kw), ItemKind::Attribute, cx.tcx) })); } @@ -277,7 +277,7 @@ pub(crate) fn build_deref_target_impls( for item in items { let target = match item.kind { - ItemKind::AssocTypeItem(ref t, _) => &t.type_, + ItemKind::AssocTy(ref t, _) => &t.type_, _ => continue, }; diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index e8755ccd76a3a..7c9504d6163f4 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -3,8 +3,8 @@ use std::mem; use crate::clean::*; pub(crate) fn strip_item(mut item: Item) -> Item { - if !matches!(item.inner.kind, StrippedItem(..)) { - item.inner.kind = StrippedItem(Box::new(item.inner.kind)); + if !matches!(item.inner.kind, ItemKind::Stripped(..)) { + item.inner.kind = ItemKind::Stripped(Box::new(item.inner.kind)); } item } @@ -17,29 +17,29 @@ pub(crate) trait DocFolder: Sized { /// don't override! fn fold_inner_recur(&mut self, kind: ItemKind) -> ItemKind { match kind { - StrippedItem(..) => unreachable!(), - ModuleItem(i) => ModuleItem(self.fold_mod(i)), - StructItem(mut i) => { + ItemKind::Stripped(..) => unreachable!(), + ItemKind::Module(i) => ItemKind::Module(self.fold_mod(i)), + ItemKind::Struct(mut i) => { i.fields = i.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); - StructItem(i) + ItemKind::Struct(i) } - UnionItem(mut i) => { + ItemKind::Union(mut i) => { i.fields = i.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); - UnionItem(i) + ItemKind::Union(i) } - EnumItem(mut i) => { + ItemKind::Enum(mut i) => { i.variants = i.variants.into_iter().filter_map(|x| self.fold_item(x)).collect(); - EnumItem(i) + ItemKind::Enum(i) } - TraitItem(mut i) => { + ItemKind::Trait(mut i) => { i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect(); - TraitItem(i) + ItemKind::Trait(i) } - ImplItem(mut i) => { + ItemKind::Impl(mut i) => { i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect(); - ImplItem(i) + ItemKind::Impl(i) } - VariantItem(Variant { kind, discriminant }) => { + ItemKind::Variant(Variant { kind, discriminant }) => { let kind = match kind { VariantKind::Struct(mut j) => { j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect(); @@ -52,9 +52,9 @@ pub(crate) trait DocFolder: Sized { VariantKind::CLike => VariantKind::CLike, }; - VariantItem(Variant { kind, discriminant }) + ItemKind::Variant(Variant { kind, discriminant }) } - TypeAliasItem(mut typealias) => { + ItemKind::TyAlias(mut typealias) => { typealias.inner_type = typealias.inner_type.map(|inner_type| match inner_type { TypeAliasInnerType::Enum { variants, is_non_exhaustive } => { let variants = variants @@ -74,38 +74,35 @@ pub(crate) trait DocFolder: Sized { } }); - TypeAliasItem(typealias) + ItemKind::TyAlias(typealias) } - ExternCrateItem { src: _ } - | ImportItem(_) - | FunctionItem(_) - | StaticItem(_) - | ConstantItem(..) - | TraitAliasItem(_) - | RequiredMethodItem(..) - | MethodItem(..) - | StructFieldItem(_) - | ForeignFunctionItem(..) - | ForeignStaticItem(..) - | ForeignTypeItem - | MacroItem(..) - | ProcMacroItem(_) - | PrimitiveItem(_) - | RequiredAssocConstItem(..) - | ProvidedAssocConstItem(..) - | ImplAssocConstItem(..) - | RequiredAssocTypeItem(..) - | AssocTypeItem(..) - | KeywordItem - | AttributeItem - | PlaceholderImplItem => kind, + ItemKind::ExternCrate { src: _ } + | ItemKind::Import(_) + | ItemKind::Fn(_) + | ItemKind::Static(_) + | ItemKind::Const(..) + | ItemKind::TraitAlias(_) + | ItemKind::AssocFn(..) + | ItemKind::StructField(_) + | ItemKind::ForeignFn(..) + | ItemKind::ForeignStatic(..) + | ItemKind::ForeignTy + | ItemKind::DeclMacro(..) + | ItemKind::ProcMacro(_) + | ItemKind::Primitive(_) + | ItemKind::AssocConst(..) + | ItemKind::RequiredAssocTy(..) + | ItemKind::AssocTy(..) + | ItemKind::Keyword + | ItemKind::Attribute + | ItemKind::PlaceholderImpl => kind, } } /// don't override! fn fold_item_recur(&mut self, mut item: Item) -> Item { item.inner.kind = match item.inner.kind { - StrippedItem(i) => StrippedItem(Box::new(self.fold_inner_recur(*i))), + ItemKind::Stripped(i) => ItemKind::Stripped(Box::new(self.fold_inner_recur(*i))), _ => self.fold_inner_recur(item.inner.kind), }; item diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index c89c3dbd3fbf5..059b8de520bbe 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -9,7 +9,7 @@ use rustc_span::Symbol; use tracing::debug; use crate::clean::types::ExternalLocation; -use crate::clean::{self, ExternalCrate, ItemId, PrimitiveType}; +use crate::clean::{self, ExternalCrate, ItemId, ItemKind, PrimitiveType}; use crate::config::RenderOptions; use crate::core::DocContext; use crate::fold::DocFolder; @@ -311,7 +311,7 @@ impl DocFolder for CacheBuilder<'_, '_> { // If this is a stripped module, // we don't want it or its children in the search index. let orig_stripped_mod = match item.kind { - clean::StrippedItem(clean::ModuleItem(..)) => { + ItemKind::Stripped(ItemKind::Module(..)) => { mem::replace(&mut self.cache.stripped_mod, true) } _ => self.cache.stripped_mod, @@ -326,7 +326,7 @@ impl DocFolder for CacheBuilder<'_, '_> { // If the impl is from a masked crate or references something from a // masked crate then remove it completely. - if let clean::ImplItem(ref i) = item.kind + if let ItemKind::Impl(ref i) = item.kind && (self.cache.masked_crates.contains(&item.item_id.krate()) || i.trait_ .as_ref() @@ -340,9 +340,9 @@ impl DocFolder for CacheBuilder<'_, '_> { // Propagate a trait method's documentation to all implementors of the // trait. - if let clean::TraitItem(ref t) = item.kind { + if let ItemKind::Trait(ref t) = item.kind { self.cache.traits.entry(item.item_id.expect_def_id()).or_insert_with(|| (**t).clone()); - } else if let clean::ImplItem(ref i) = item.kind + } else if let ItemKind::Impl(ref i) = item.kind && let Some(trait_) = &i.trait_ && !i.kind.is_blanket() { @@ -357,7 +357,7 @@ impl DocFolder for CacheBuilder<'_, '_> { // Index this method for searching later on. let search_name = if !item.is_stripped() { item.name.or_else(|| { - if let clean::ImportItem(ref i) = item.kind + if let ItemKind::Import(ref i) = item.kind && let clean::ImportKind::Simple(s) = i.kind { Some(s) @@ -382,23 +382,23 @@ impl DocFolder for CacheBuilder<'_, '_> { }; match item.kind { - clean::StructItem(..) - | clean::EnumItem(..) - | clean::TypeAliasItem(..) - | clean::TraitItem(..) - | clean::TraitAliasItem(..) - | clean::FunctionItem(..) - | clean::ModuleItem(..) - | clean::ForeignFunctionItem(..) - | clean::ForeignStaticItem(..) - | clean::ConstantItem(..) - | clean::StaticItem(..) - | clean::UnionItem(..) - | clean::ForeignTypeItem - | clean::MacroItem(..) - | clean::ProcMacroItem(..) - | clean::VariantItem(..) - | clean::PrimitiveItem(..) => { + ItemKind::Struct(..) + | ItemKind::Enum(..) + | ItemKind::TyAlias(..) + | ItemKind::Trait(..) + | ItemKind::TraitAlias(..) + | ItemKind::Fn(..) + | ItemKind::Module(..) + | ItemKind::ForeignFn(..) + | ItemKind::ForeignStatic(..) + | ItemKind::Const(..) + | ItemKind::Static(..) + | ItemKind::Union(..) + | ItemKind::ForeignTy + | ItemKind::DeclMacro(..) + | ItemKind::ProcMacro(..) + | ItemKind::Variant(..) + | ItemKind::Primitive(..) => { use rustc_data_structures::fx::IndexEntry as Entry; let skip_because_unstable = matches!( @@ -442,39 +442,36 @@ impl DocFolder for CacheBuilder<'_, '_> { } } - clean::ExternCrateItem { .. } - | clean::ImportItem(..) - | clean::ImplItem(..) - | clean::RequiredMethodItem(..) - | clean::MethodItem(..) - | clean::StructFieldItem(..) - | clean::RequiredAssocConstItem(..) - | clean::ProvidedAssocConstItem(..) - | clean::ImplAssocConstItem(..) - | clean::RequiredAssocTypeItem(..) - | clean::AssocTypeItem(..) - | clean::StrippedItem(..) - | clean::KeywordItem - | clean::AttributeItem => { + ItemKind::ExternCrate { .. } + | ItemKind::Import(..) + | ItemKind::Impl(..) + | ItemKind::AssocFn(..) + | ItemKind::StructField(..) + | ItemKind::AssocConst(..) + | ItemKind::RequiredAssocTy(..) + | ItemKind::AssocTy(..) + | ItemKind::Stripped(..) + | ItemKind::Keyword + | ItemKind::Attribute => { // FIXME: Do these need handling? // The person writing this comment doesn't know. // So would rather leave them to an expert, // as at least the list is better than `_ => {}`. } - clean::PlaceholderImplItem => return None, + ItemKind::PlaceholderImpl => return None, } // Maintain the parent stack. let (item, parent_pushed) = match item.kind { - clean::TraitItem(..) - | clean::EnumItem(..) - | clean::ForeignTypeItem - | clean::StructItem(..) - | clean::UnionItem(..) - | clean::VariantItem(..) - | clean::TypeAliasItem(..) - | clean::ImplItem(..) => { + ItemKind::Trait(..) + | ItemKind::Enum(..) + | ItemKind::ForeignTy + | ItemKind::Struct(..) + | ItemKind::Union(..) + | ItemKind::Variant(..) + | ItemKind::TyAlias(..) + | ItemKind::Impl(..) => { self.cache.parent_stack.push(ParentStackItem::new(&item)); (self.fold_item_recur(item), true) } @@ -484,7 +481,7 @@ impl DocFolder for CacheBuilder<'_, '_> { // Once we've recursively found all the generics, hoard off all the // implementations elsewhere. let ret = - if let clean::Item { inner: clean::ItemInner { kind: clean::ImplItem(ref i), .. } } = + if let clean::Item { inner: clean::ItemInner { kind: ItemKind::Impl(ref i), .. } } = item { // Figure out the id of this impl. This may map to a @@ -549,20 +546,18 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It // Item has a name, so it must also have a DefId (can't be an impl, let alone a blanket or auto impl). let item_def_id = item.item_id.as_def_id().unwrap(); let (parent_did, parent_path) = match item.kind { - clean::StrippedItem(..) => return, - clean::ProvidedAssocConstItem(..) - | clean::ImplAssocConstItem(..) - | clean::AssocTypeItem(..) + ItemKind::Stripped(..) => return, + ItemKind::AssocConst(clean::AssocConst { rhs: Some(_), .. }) | ItemKind::AssocTy(..) if cache.parent_stack.last().is_some_and(|parent| parent.is_trait_impl()) => { // skip associated items in trait impls return; } - clean::RequiredMethodItem(..) - | clean::RequiredAssocConstItem(..) - | clean::RequiredAssocTypeItem(..) - | clean::StructFieldItem(..) - | clean::VariantItem(..) => { + ItemKind::AssocFn(_, None) + | ItemKind::AssocConst(clean::AssocConst { rhs: None, .. }) + | ItemKind::RequiredAssocTy(..) + | ItemKind::StructField(..) + | ItemKind::Variant(..) => { // Don't index if containing module is stripped (i.e., private), // or if item is tuple struct/variant field (name is a number -> not useful for search). if cache.stripped_mod @@ -576,10 +571,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It let parent_path = &cache.stack[..cache.stack.len() - 1]; (Some(parent_did), parent_path) } - clean::MethodItem(..) - | clean::ProvidedAssocConstItem(..) - | clean::ImplAssocConstItem(..) - | clean::AssocTypeItem(..) => { + ItemKind::AssocFn(..) | ItemKind::AssocConst(..) | ItemKind::AssocTy(..) => { let last = cache.parent_stack.last().expect("parent_stack is empty 2"); let parent_did = match last { // impl Trait for &T { fn method(self); } @@ -645,7 +637,7 @@ fn add_item_to_search_index(tcx: TyCtxt<'_>, cache: &mut Cache, item: &clean::It // - It's got the same name // - Both of them have the same exact path let defid = match &item.kind { - clean::ItemKind::ImportItem(import) => import.source.did.unwrap_or(item_def_id), + ItemKind::Import(import) => import.source.did.unwrap_or(item_def_id), _ => item_def_id, }; let (impl_id, trait_parent) = cache.parent_stack_last_impl_and_trait_id(); @@ -722,7 +714,7 @@ enum ParentStackItem { impl ParentStackItem { fn new(item: &clean::Item) -> Self { match &item.kind { - clean::ItemKind::ImplItem(clean::Impl { for_, trait_, generics, kind, .. }) => { + ItemKind::Impl(clean::Impl { for_, trait_, generics, kind, .. }) => { ParentStackItem::Impl { for_: for_.clone(), trait_: trait_.clone(), diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index 5d2638a33cb30..c4e9a78bf2037 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::TyCtxt; use rustc_span::hygiene::MacroKind; use serde::{Deserialize, Deserializer, Serialize, Serializer, de}; -use crate::clean; +use crate::clean::{self, ItemKind}; macro_rules! item_type { ($($variant:ident = $number:literal,)+) => { @@ -112,45 +112,43 @@ item_type! { impl<'a> From<&'a clean::Item> for ItemType { fn from(item: &'a clean::Item) -> ItemType { let kind = match &item.kind { - clean::StrippedItem(item) => item, + ItemKind::Stripped(item) => item, kind => kind, }; match kind { - clean::ModuleItem(..) => ItemType::Module, - clean::ExternCrateItem { .. } => ItemType::ExternCrate, - clean::ImportItem(..) => ItemType::Import, - clean::StructItem(..) => ItemType::Struct, - clean::UnionItem(..) => ItemType::Union, - clean::EnumItem(..) => ItemType::Enum, - clean::FunctionItem(..) => ItemType::Function, - clean::TypeAliasItem(..) => ItemType::TypeAlias, - clean::StaticItem(..) => ItemType::Static, - clean::ConstantItem(..) => ItemType::Constant, - clean::TraitItem(..) => ItemType::Trait, - clean::ImplItem(..) | clean::PlaceholderImplItem => ItemType::Impl, - clean::RequiredMethodItem(..) => ItemType::TyMethod, - clean::MethodItem(..) => ItemType::Method, - clean::StructFieldItem(..) => ItemType::StructField, - clean::VariantItem(..) => ItemType::Variant, - clean::ForeignFunctionItem(..) => ItemType::Function, // no ForeignFunction - clean::ForeignStaticItem(..) => ItemType::Static, // no ForeignStatic - clean::MacroItem(..) => ItemType::Macro, - clean::PrimitiveItem(..) => ItemType::Primitive, - clean::RequiredAssocConstItem(..) - | clean::ProvidedAssocConstItem(..) - | clean::ImplAssocConstItem(..) => ItemType::AssocConst, - clean::RequiredAssocTypeItem(..) | clean::AssocTypeItem(..) => ItemType::AssocType, - clean::ForeignTypeItem => ItemType::ForeignType, - clean::KeywordItem => ItemType::Keyword, - clean::AttributeItem => ItemType::Attribute, - clean::TraitAliasItem(..) => ItemType::TraitAlias, - clean::ProcMacroItem(mac) => match mac.kind { + ItemKind::Module(..) => ItemType::Module, + ItemKind::ExternCrate { .. } => ItemType::ExternCrate, + ItemKind::Import(..) => ItemType::Import, + ItemKind::Struct(..) => ItemType::Struct, + ItemKind::Union(..) => ItemType::Union, + ItemKind::Enum(..) => ItemType::Enum, + ItemKind::Fn(..) => ItemType::Function, + ItemKind::TyAlias(..) => ItemType::TypeAlias, + ItemKind::Static(..) => ItemType::Static, + ItemKind::Const(..) => ItemType::Constant, + ItemKind::Trait(..) => ItemType::Trait, + ItemKind::Impl(..) | ItemKind::PlaceholderImpl => ItemType::Impl, + ItemKind::AssocFn(_, None) => ItemType::TyMethod, + ItemKind::AssocFn(_, Some(_)) => ItemType::Method, + ItemKind::StructField(..) => ItemType::StructField, + ItemKind::Variant(..) => ItemType::Variant, + ItemKind::ForeignFn(..) => ItemType::Function, // no ForeignFunction + ItemKind::ForeignStatic(..) => ItemType::Static, // no ForeignStatic + ItemKind::DeclMacro(..) => ItemType::Macro, + ItemKind::Primitive(..) => ItemType::Primitive, + ItemKind::AssocConst(..) => ItemType::AssocConst, + ItemKind::RequiredAssocTy(..) | ItemKind::AssocTy(..) => ItemType::AssocType, + ItemKind::ForeignTy => ItemType::ForeignType, + ItemKind::Keyword => ItemType::Keyword, + ItemKind::Attribute => ItemType::Attribute, + ItemKind::TraitAlias(..) => ItemType::TraitAlias, + ItemKind::ProcMacro(mac) => match mac.kind { MacroKind::Bang => ItemType::Macro, MacroKind::Attr => ItemType::ProcAttribute, MacroKind::Derive => ItemType::ProcDerive, }, - clean::StrippedItem(..) => unreachable!(), + ItemKind::Stripped(..) => unreachable!(), } } } diff --git a/src/librustdoc/formats/mod.rs b/src/librustdoc/formats/mod.rs index 80c110ec07f56..e9cbefea4a982 100644 --- a/src/librustdoc/formats/mod.rs +++ b/src/librustdoc/formats/mod.rs @@ -17,7 +17,7 @@ pub(crate) struct Impl { impl Impl { pub(crate) fn inner_impl(&self) -> &clean::Impl { match self.impl_item.kind { - clean::ImplItem(ref impl_) => impl_, + clean::ItemKind::Impl(ref impl_) => impl_, _ => panic!("non-impl item found in impl"), } } diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index bb2ccf0d4a354..9ade29697eed0 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -1,7 +1,7 @@ use rustc_data_structures::profiling::SelfProfilerRef; use rustc_middle::ty::TyCtxt; -use crate::clean; +use crate::clean::{self, ItemKind}; use crate::config::{EmitType, RenderOptions}; use crate::error::Error; use crate::formats::cache::Cache; @@ -75,7 +75,7 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>( prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string()); cx.mod_item_in(item)?; - let (clean::StrippedItem(clean::ModuleItem(ref module)) | clean::ModuleItem(ref module)) = + let (ItemKind::Stripped(ItemKind::Module(ref module)) | ItemKind::Module(ref module)) = item.inner.kind else { unreachable!() diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index d00b705d3766c..7dd0fcca49f07 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -23,7 +23,7 @@ use super::sidebar::{ModuleLike, Sidebar, print_sidebar, sidebar_module_like}; use super::{AllTypes, StylePath}; use crate::clean::types::ExternalLocation; use crate::clean::utils::has_doc_flag; -use crate::clean::{self, ExternalCrate}; +use crate::clean::{self, ExternalCrate, ItemKind}; use crate::config::{EmitType, ModuleSorting, RenderOptions}; use crate::docfs::{DocFS, PathError}; use crate::error::Error; @@ -748,8 +748,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { // Render sidebar-items.js used throughout this module. if !self.info.render_redirect_pages { - let (clean::StrippedItem(clean::ModuleItem(ref module)) - | clean::ModuleItem(ref module)) = item.kind + let (ItemKind::Stripped(ItemKind::Module(ref module)) | ItemKind::Module(ref module)) = + item.kind else { unreachable!() }; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index a9ecf6d66d001..c0b410c920fa6 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -65,7 +65,7 @@ use tracing::{debug, info}; pub(crate) use self::context::*; pub(crate) use self::write_shared::*; -use crate::clean::{self, Defaultness, Item, ItemId, RenderedLink}; +use crate::clean::{self, Defaultness, Item, ItemId, ItemKind, RenderedLink}; use crate::display::{Joined as _, MaybeDisplay as _}; use crate::error::Error; use crate::formats::Impl; @@ -818,11 +818,11 @@ fn document_full_inner( } let kind = match &item.kind { - clean::ItemKind::StrippedItem(kind) => kind, + ItemKind::Stripped(kind) => kind, kind => kind, }; - if let clean::ItemKind::FunctionItem(..) | clean::ItemKind::MethodItem(..) = kind { + if let ItemKind::Fn(..) | ItemKind::AssocFn(..) = kind { render_call_locations(f, cx, item)?; } Ok(()) @@ -1072,24 +1072,13 @@ fn assoc_href_attr( Some(fmt::from_fn(move |f| write!(f, " href=\"{href}\""))) } -#[derive(Debug)] -enum AssocConstValue<'a> { - // In trait definitions, it is relevant for the public API whether an - // associated constant comes with a default value, so even if we cannot - // render its value, the presence of a value must be shown using `= _`. - TraitDefault(&'a clean::ConstantKind), - // In impls, there is no need to show `= _`. - Impl(&'a clean::ConstantKind), - None, -} - fn assoc_const( it: &clean::Item, - generics: &clean::Generics, - ty: &clean::Type, - value: AssocConstValue<'_>, + ct: &clean::AssocConst, + parent: ItemType, link: AssocItemLink<'_>, indent: usize, + ending: Ending, cx: &Context<'_>, ) -> impl fmt::Display { let tcx = cx.tcx(); @@ -1102,22 +1091,23 @@ fn assoc_const( vis = visibility_print_with_space(it, cx), href = assoc_href_attr(it, link, cx).maybe_display(), name = it.name.as_ref().unwrap(), - generics = print_generics(generics, cx), - ty = print_type(ty, cx), + generics = print_generics(&ct.generics, cx), + ty = print_type(&ct.ty, cx), )?; - if let AssocConstValue::TraitDefault(konst) | AssocConstValue::Impl(konst) = value { - let repr = konst.expr(tcx); - if match value { - AssocConstValue::TraitDefault(_) => true, // always show - // FIXME: Comparing against the special string "_" denoting overly complex const exprs - // is rather hacky; `ConstKind::expr` should have a richer return type. - AssocConstValue::Impl(_) => repr != "_", // show if there is a meaningful value to show - AssocConstValue::None => unreachable!(), - } { + if let Some(rhs) = &ct.rhs { + let repr = rhs.expr(tcx); + // In trait definitions, it is relevant for the public API whether an assoc const comes + // with a default value, so even if we cannot render its value, the presence of a value + // must be shown using `= _`. In impls, there is no need to show `= _`. + // + // FIXME: Comparing against the special string "_" (which denotes overly complex const + // exprs) is rather hacky; `ConstantKind::expr` should have a richer return type. + if parent == ItemType::Trait || repr != "_" { write!(w, " = {}", Escape(&repr))?; } } - write!(w, "{}", print_where_clause(generics, cx, indent, Ending::NoNewline).maybe_display()) + let where_clause = print_where_clause(&ct.generics, cx, indent, ending).maybe_display(); + write!(w, "{where_clause}") }) } @@ -1128,6 +1118,7 @@ fn assoc_type( default: Option<&clean::Type>, link: AssocItemLink<'_>, indent: usize, + ending: Ending, cx: &Context<'_>, ) -> impl fmt::Display { fmt::from_fn(move |w| { @@ -1148,48 +1139,53 @@ fn assoc_type( if let Some(default) = default { write!(w, " = {}", print_type(default, cx))?; } - write!(w, "{}", print_where_clause(generics, cx, indent, Ending::NoNewline).maybe_display()) + write!(w, "{}", print_where_clause(generics, cx, indent, ending).maybe_display()) }) } fn assoc_method( - meth: &clean::Item, - g: &clean::Generics, - d: &clean::FnDecl, + it: &clean::Item, + fn_: &clean::Function, + body: Option, link: AssocItemLink<'_>, - parent: ItemType, - cx: &Context<'_>, + indent: usize, + ending: Ending, render_mode: RenderMode, + cx: &Context<'_>, ) -> impl fmt::Display { let tcx = cx.tcx(); - let header = meth.fn_header(tcx).expect("Trying to get header from a non-function item"); - let name = meth.name.as_ref().unwrap(); - let vis = visibility_print_with_space(meth, cx).to_string(); - let defaultness = match meth.defaultness().expect("Expected assoc method to have defaultness") { - Defaultness::Implicit => "", - Defaultness::Final => "final ", - Defaultness::Default => "default ", + let header = it.fn_header(tcx).expect("Trying to get header from a non-function item"); + let name = it.name.as_ref().unwrap(); + let vis = visibility_print_with_space(it, cx).to_string(); + let defaultness = match body { + Some(Defaultness::Implicit) | None => "", + Some(Defaultness::Final) => "final ", + Some(Defaultness::Default) => "default ", }; // FIXME: Once https://github.com/rust-lang/rust/issues/143874 is implemented, we can remove // this condition. let constness = match render_mode { RenderMode::Normal => print_constness_with_space( &header.constness, - meth.stable_since(tcx), - meth.const_stability(tcx), + it.stable_since(tcx), + it.const_stability(tcx), ), RenderMode::ForDeref { .. } => "", }; fmt::from_fn(move |w| { + let indent_str = " ".repeat(indent); + render_attributes_in_code(w, it, &indent_str, cx)?; + let asyncness = header.asyncness.print_with_space(); let safety = header.safety.print_with_space(); let abi = print_abi_with_space(header.abi).to_string(); - let href = assoc_href_attr(meth, link, cx).maybe_display(); + let href = assoc_href_attr(it, link, cx).maybe_display(); // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`. - let generics_len = format!("{:#}", print_generics(g, cx)).len(); - let mut header_len = "fn ".len() + let generics_len = format!("{:#}", print_generics(&fn_.generics, cx)).len(); + let header_len = indent + + "fn ".len() + vis.len() + defaultness.len() + constness.len() @@ -1199,25 +1195,16 @@ fn assoc_method( + name.as_str().len() + generics_len; - let notable_traits = notable_traits_button(&d.output, cx).maybe_display(); + let notable_traits = notable_traits_button(&fn_.decl.output, cx).maybe_display(); - let (indent, indent_str, end_newline) = if parent == ItemType::Trait { - header_len += 4; - let indent_str = " "; - render_attributes_in_code(w, meth, indent_str, cx)?; - (4, indent_str, Ending::NoNewline) - } else { - render_attributes_in_code(w, meth, "", cx)?; - (0, "", Ending::Newline) - }; write!( w, "{indent}{vis}{defaultness}{constness}{asyncness}{safety}{abi}fn \ {name}{generics}{decl}{notable_traits}{where_clause}", indent = indent_str, - generics = print_generics(g, cx), - decl = full_print_fn_decl(d, header_len, indent, cx), - where_clause = print_where_clause(g, cx, indent, end_newline).maybe_display(), + generics = print_generics(&fn_.generics, cx), + decl = full_print_fn_decl(&fn_.decl, header_len, indent, cx), + where_clause = print_where_clause(&fn_.generics, cx, indent, ending).maybe_display(), ) }) } @@ -1315,61 +1302,28 @@ fn render_assoc_item( item: &clean::Item, link: AssocItemLink<'_>, parent: ItemType, - cx: &Context<'_>, + indent: usize, + ending: Ending, render_mode: RenderMode, + cx: &Context<'_>, ) -> impl fmt::Display { fmt::from_fn(move |f| match &item.kind { - clean::StrippedItem(..) => Ok(()), - clean::RequiredMethodItem(m, _) | clean::MethodItem(m, _) => { - assoc_method(item, &m.generics, &m.decl, link, parent, cx, render_mode).fmt(f) + ItemKind::Stripped(..) => Ok(()), + ItemKind::AssocFn(fn_, body) => { + assoc_method(item, fn_, *body, link, indent, ending, render_mode, cx).fmt(f) } - clean::RequiredAssocConstItem(generics, ty) => assoc_const( - item, - generics, - ty, - AssocConstValue::None, - link, - if parent == ItemType::Trait { 4 } else { 0 }, - cx, - ) - .fmt(f), - clean::ProvidedAssocConstItem(ci) => assoc_const( - item, - &ci.generics, - &ci.type_, - AssocConstValue::TraitDefault(&ci.kind), - link, - if parent == ItemType::Trait { 4 } else { 0 }, - cx, - ) - .fmt(f), - clean::ImplAssocConstItem(ci) => assoc_const( - item, - &ci.generics, - &ci.type_, - AssocConstValue::Impl(&ci.kind), - link, - if parent == ItemType::Trait { 4 } else { 0 }, - cx, - ) - .fmt(f), - clean::RequiredAssocTypeItem(generics, bounds) => assoc_type( - item, - generics, - bounds, - None, - link, - if parent == ItemType::Trait { 4 } else { 0 }, - cx, - ) - .fmt(f), - clean::AssocTypeItem(ty, bounds) => assoc_type( + ItemKind::AssocConst(ct) => assoc_const(item, ct, parent, link, indent, ending, cx).fmt(f), + ItemKind::RequiredAssocTy(generics, bounds) => { + assoc_type(item, generics, bounds, None, link, indent, ending, cx).fmt(f) + } + ItemKind::AssocTy(ty, bounds) => assoc_type( item, &ty.generics, bounds, Some(ty.item_type.as_ref().unwrap_or(&ty.type_)), link, - if parent == ItemType::Trait { 4 } else { 0 }, + indent, + ending, cx, ) .fmt(f), @@ -1610,7 +1564,7 @@ fn render_deref_methods( .items .iter() .find_map(|item| match item.kind { - clean::AssocTypeItem(ref t, _) => Some(match *t { + ItemKind::AssocTy(ref t, _) => Some(match *t { clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), }), @@ -1641,28 +1595,21 @@ fn render_deref_methods( } fn should_render_item(item: &clean::Item, deref_mut_: bool, tcx: TyCtxt<'_>) -> bool { - let self_type_opt = match item.kind { - clean::MethodItem(ref method, _) => method.decl.receiver_type(), - clean::RequiredMethodItem(ref method, _) => method.decl.receiver_type(), - _ => None, - }; + let ItemKind::AssocFn(item, _) = &item.kind else { return false }; + let Some(self_ty) = item.decl.receiver_type() else { return false }; - if let Some(self_ty) = self_type_opt { - let (by_mut_ref, by_box, by_value) = match *self_ty { - clean::Type::BorrowedRef { mutability, .. } => { - (mutability == Mutability::Mut, false, false) - } - clean::Type::Path { ref path } => { - (false, Some(path.def_id()) == tcx.lang_items().owned_box(), false) - } - clean::Type::SelfTy => (false, false, true), - _ => (false, false, false), - }; + let (by_mut_ref, by_box, by_value) = match *self_ty { + clean::Type::BorrowedRef { mutability, .. } => { + (mutability == Mutability::Mut, false, false) + } + clean::Type::Path { ref path } => { + (false, Some(path.def_id()) == tcx.lang_items().owned_box(), false) + } + clean::Type::SelfTy => (false, false, true), + _ => (false, false, false), + }; - (deref_mut_ || !by_mut_ref) && !by_box && !by_value - } else { - false - } + (deref_mut_ || !by_mut_ref) && !by_box && !by_value } /// `Box` has pass-through impls for `Read`, `Write`, `Iterator`, and `Future` when the @@ -1754,7 +1701,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { for (impl_, trait_did) in notable_impls { write!(f, "
{}
", print_impl(impl_, false, cx))?; for it in &impl_.items { - let clean::AssocTypeItem(tydef, ..) = &it.kind else { + let ItemKind::AssocTy(tydef, ..) = &it.kind else { continue; }; @@ -1771,6 +1718,7 @@ fn notable_traits_decl(ty: &clean::Type, cx: &Context<'_>) -> (String, String) { Some(&tydef.type_), src_link, 0, + Ending::Newline, cx, ) )?; @@ -1959,7 +1907,7 @@ fn render_impl( deprecation_class = ""; } match &item.kind { - clean::MethodItem(..) | clean::RequiredMethodItem(..) => { + ItemKind::AssocFn(..) => { // Only render when the method is not static or we allow static methods if render_method_item { let id = cx.derive_id(format!("{item_type}.{name}")); @@ -1988,40 +1936,15 @@ fn render_impl( item, link.anchor(source_id.as_ref().unwrap_or(&id)), ItemType::Impl, - cx, + 0, + Ending::Newline, render_mode, + cx, ), )?; } } - clean::RequiredAssocConstItem(generics, ty) => { - let source_id = format!("{item_type}.{name}"); - let id = cx.derive_id(&source_id); - write!( - w, - "
\ - {}", - render_rightside(cx, item, render_mode) - )?; - if trait_.is_some() { - // Anchors are only used on trait impls. - write!(w, "§")?; - } - write!( - w, - "

{}

", - assoc_const( - item, - generics, - ty, - AssocConstValue::None, - link.anchor(if trait_.is_some() { &source_id } else { &id }), - 0, - cx, - ), - )?; - } - clean::ProvidedAssocConstItem(ci) | clean::ImplAssocConstItem(ci) => { + ItemKind::AssocConst(ct) => { let source_id = format!("{item_type}.{name}"); let id = cx.derive_id(&source_id); write!( @@ -2039,21 +1962,16 @@ fn render_impl( "

{}

", assoc_const( item, - &ci.generics, - &ci.type_, - match item.kind { - clean::ProvidedAssocConstItem(_) => - AssocConstValue::TraitDefault(&ci.kind), - clean::ImplAssocConstItem(_) => AssocConstValue::Impl(&ci.kind), - _ => unreachable!(), - }, + ct, + ItemType::Impl, link.anchor(if trait_.is_some() { &source_id } else { &id }), 0, + Ending::Newline, cx, ), )?; } - clean::RequiredAssocTypeItem(generics, bounds) => { + ItemKind::RequiredAssocTy(generics, bounds) => { let source_id = format!("{item_type}.{name}"); let id = cx.derive_id(&source_id); write!( @@ -2076,11 +1994,12 @@ fn render_impl( None, link.anchor(if trait_.is_some() { &source_id } else { &id }), 0, + Ending::Newline, cx, ), )?; } - clean::AssocTypeItem(tydef, _bounds) => { + ItemKind::AssocTy(tydef, _bounds) => { let source_id = format!("{item_type}.{name}"); let id = cx.derive_id(&source_id); write!( @@ -2103,11 +2022,12 @@ fn render_impl( Some(tydef.item_type.as_ref().unwrap_or(&tydef.type_)), link.anchor(if trait_.is_some() { &source_id } else { &id }), 0, + Ending::Newline, cx, ), )?; } - clean::StrippedItem(..) => return Ok(()), + ItemKind::Stripped(..) => return Ok(()), _ => panic!("can't make docs for trait item with name {:?}", item.name), } @@ -2137,15 +2057,11 @@ fn render_impl( if !impl_.is_negative_trait_impl() { for impl_item in &impl_.items { match impl_item.kind { - clean::MethodItem(..) | clean::RequiredMethodItem(..) => { - methods.push(impl_item) - } - clean::RequiredAssocTypeItem(..) | clean::AssocTypeItem(..) => { + ItemKind::AssocFn(..) => methods.push(impl_item), + ItemKind::RequiredAssocTy(..) | ItemKind::AssocTy(..) => { assoc_types.push(impl_item) } - clean::RequiredAssocConstItem(..) - | clean::ProvidedAssocConstItem(_) - | clean::ImplAssocConstItem(_) => { + ItemKind::AssocConst(_) => { // We render it directly since they're supposed to come first. doc_impl_item( &mut default_impl_items, @@ -2407,7 +2323,7 @@ fn render_impl_summary( write!(w, "{}", print_impl(inner_impl, use_absolute, cx))?; if show_def_docs { for it in &inner_impl.items { - if let clean::AssocTypeItem(ref tydef, ref _bounds) = it.kind { + if let ItemKind::AssocTy(ref tydef, ref _bounds) = it.kind { write!( w, "
{};
", @@ -2418,6 +2334,7 @@ fn render_impl_summary( Some(&tydef.type_), AssocItemLink::Anchor(None), 0, + Ending::Newline, cx, ) )?; @@ -2541,7 +2458,7 @@ fn get_id_for_impl(tcx: TyCtxt<'_>, impl_id: ItemId) -> String { fn extract_for_impl_name(item: &clean::Item, cx: &Context<'_>) -> Option<(String, String)> { match item.kind { - clean::ItemKind::ImplItem(ref i) if i.trait_.is_some() => { + clean::ItemKind::Impl(ref i) if i.trait_.is_some() => { // Alternative format produces no URLs, // so this parameter does nothing. Some(( diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 46dba0253766a..2207cab45a8de 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -27,7 +27,7 @@ use super::{ render_repr_attribute_in_code, render_rightside, render_stability_since_raw, render_stability_since_raw_with_extra, write_section_heading, }; -use crate::clean; +use crate::clean::{self, ItemKind}; use crate::config::ModuleSorting; use crate::display::{Joined as _, MaybeDisplay as _}; use crate::formats::Impl; @@ -79,32 +79,27 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item) -> impl fmt::Disp fmt::from_fn(|buf| { let typ = match item.kind { - clean::ModuleItem(_) => { - if item.is_crate() { - "Crate " - } else { - "Module " - } - } - clean::FunctionItem(..) | clean::ForeignFunctionItem(..) => "Function ", - clean::TraitItem(..) => "Trait ", - clean::StructItem(..) => "Struct ", - clean::UnionItem(..) => "Union ", - clean::EnumItem(..) => "Enum ", - clean::TypeAliasItem(..) => "Type Alias ", - clean::MacroItem(..) => "Macro ", - clean::ProcMacroItem(ref mac) => match mac.kind { + ItemKind::Module(_) if item.is_crate() => "Crate ", + ItemKind::Module(_) => "Module ", + ItemKind::Fn(..) | ItemKind::ForeignFn(..) => "Function ", + ItemKind::Trait(..) => "Trait ", + ItemKind::Struct(..) => "Struct ", + ItemKind::Union(..) => "Union ", + ItemKind::Enum(..) => "Enum ", + ItemKind::TyAlias(..) => "Type Alias ", + ItemKind::DeclMacro(..) => "Macro ", + ItemKind::ProcMacro(ref mac) => match mac.kind { MacroKind::Bang => "Macro ", MacroKind::Attr => "Attribute Macro ", MacroKind::Derive => "Derive Macro ", }, - clean::PrimitiveItem(..) => "Primitive Type ", - clean::StaticItem(..) | clean::ForeignStaticItem(..) => "Static ", - clean::ConstantItem(..) => "Constant ", - clean::ForeignTypeItem => "Foreign Type ", - clean::KeywordItem => "Keyword ", - clean::AttributeItem => "Attribute ", - clean::TraitAliasItem(..) => "Trait Alias ", + ItemKind::Primitive(..) => "Primitive Type ", + ItemKind::Static(..) | ItemKind::ForeignStatic(..) => "Static ", + ItemKind::Const(..) => "Constant ", + ItemKind::ForeignTy => "Foreign Type ", + ItemKind::Keyword => "Keyword ", + ItemKind::Attribute => "Attribute ", + ItemKind::TraitAlias(..) => "Trait Alias ", _ => { // We don't generate pages for any other type. unreachable!(); @@ -173,48 +168,46 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item) -> impl fmt::Disp item_vars.render_into(buf).unwrap(); match &item.kind { - clean::ModuleItem(m) => { + ItemKind::Module(m) => { write!(buf, "{}", item_module(cx, item, &m.items)) } - clean::FunctionItem(f) | clean::ForeignFunctionItem(f, _) => { + ItemKind::Fn(f) | ItemKind::ForeignFn(f, _) => { write!(buf, "{}", item_function(cx, item, f)) } - clean::TraitItem(t) => write!(buf, "{}", item_trait(cx, item, t)), - clean::StructItem(s) => { + ItemKind::Trait(t) => write!(buf, "{}", item_trait(cx, item, t)), + ItemKind::Struct(s) => { write!(buf, "{}", item_struct(cx, item, s)) } - clean::UnionItem(s) => write!(buf, "{}", item_union(cx, item, s)), - clean::EnumItem(e) => write!(buf, "{}", item_enum(cx, item, e)), - clean::TypeAliasItem(t) => { + ItemKind::Union(s) => write!(buf, "{}", item_union(cx, item, s)), + ItemKind::Enum(e) => write!(buf, "{}", item_enum(cx, item, e)), + ItemKind::TyAlias(t) => { write!(buf, "{}", item_type_alias(cx, item, t)) } - clean::MacroItem(m, kinds) => write!(buf, "{}", item_macro(cx, item, m, *kinds)), - clean::ProcMacroItem(m) => { + ItemKind::DeclMacro(m, kinds) => write!(buf, "{}", item_macro(cx, item, m, *kinds)), + ItemKind::ProcMacro(m) => { write!(buf, "{}", item_proc_macro(cx, item, m)) } - clean::PrimitiveItem(_) => write!(buf, "{}", item_primitive(cx, item)), - clean::StaticItem(i) => { + ItemKind::Primitive(_) => write!(buf, "{}", item_primitive(cx, item)), + ItemKind::Static(i) => { write!(buf, "{}", item_static(cx, item, i, None)) } - clean::ForeignStaticItem(i, safety) => { + ItemKind::ForeignStatic(i, safety) => { write!(buf, "{}", item_static(cx, item, i, Some(*safety))) } - clean::ConstantItem(ci) => { - write!(buf, "{}", item_constant(cx, item, &ci.generics, &ci.type_, &ci.kind)) + ItemKind::Const(ci) => { + write!(buf, "{}", item_constant(cx, item, &ci.generics, &ci.ty, &ci.rhs)) } - clean::ForeignTypeItem => { + ItemKind::ForeignTy => { write!(buf, "{}", item_foreign_type(cx, item)) } - clean::KeywordItem | clean::AttributeItem => { + ItemKind::Keyword | ItemKind::Attribute => { write!(buf, "{}", item_keyword_or_attribute(cx, item)) } - clean::TraitAliasItem(ta) => { + ItemKind::TraitAlias(ta) => { write!(buf, "{}", item_trait_alias(cx, item, ta)) } - _ => { - // We don't generate pages for any other type. - unreachable!(); - } + // We don't generate pages for any other type. + _ => unreachable!(), }?; // Render notable-traits.js used for all methods in this module. @@ -386,7 +379,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i }; match myitem.kind { - clean::ExternCrateItem { ref src } => { + ItemKind::ExternCrate { ref src } => { use crate::html::format::print_anchor; let visibility_and_hidden = visibility_and_hidden(myitem); @@ -424,7 +417,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i } write!(w, "{visibility_and_hidden}")? } - clean::ImportItem(ref import) => { + ItemKind::Import(ref import) => { let (stab_tags, deprecation) = match import.source.did { Some(import_def_id) => { let stab_tags = @@ -464,13 +457,13 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i let Some(item_name) = myitem.name else { continue }; let unsafety_flag = match myitem.kind { - clean::FunctionItem(_) | clean::ForeignFunctionItem(..) + ItemKind::Fn(_) | ItemKind::ForeignFn(..) if myitem.fn_header(tcx).unwrap().safety == hir::HeaderSafety::Normal(hir::Safety::Unsafe) => { "" } - clean::ForeignStaticItem(_, hir::Safety::Unsafe) => { + ItemKind::ForeignStatic(_, hir::Safety::Unsafe) => { "" } _ => "", @@ -651,9 +644,9 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: t.items.iter().filter(|m| m.is_required_associated_type()).collect::>(); let provided_types = t.items.iter().filter(|m| m.is_associated_type()).collect::>(); let required_consts = - t.items.iter().filter(|m| m.is_required_associated_const()).collect::>(); + t.items.iter().filter(|m| m.is_assoc_const_without_body()).collect::>(); let provided_consts = - t.items.iter().filter(|m| m.is_associated_const()).collect::>(); + t.items.iter().filter(|m| m.is_assoc_const_with_body()).collect::>(); let required_methods = t.items.iter().filter(|m| m.is_ty_method()).collect::>(); let provided_methods = t.items.iter().filter(|m| m.is_method()).collect::>(); let count_types = required_types.len() + provided_types.len(); @@ -708,17 +701,17 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: } for types in [&required_types, &provided_types] { for t in types { - writeln!( - w, - "{};", - render_assoc_item( - t, - AssocItemLink::Anchor(None), - ItemType::Trait, - cx, - RenderMode::Normal, - ) - )?; + render_assoc_item( + t, + AssocItemLink::Anchor(None), + ItemType::Trait, + 4, + Ending::NoNewline, + RenderMode::Normal, + cx, + ) + .fmt(w)?; + w.write_str(";\n")?; } } // If there are too many associated constants, hide everything after them @@ -742,17 +735,17 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: } for consts in [&required_consts, &provided_consts] { for c in consts { - writeln!( - w, - "{};", - render_assoc_item( - c, - AssocItemLink::Anchor(None), - ItemType::Trait, - cx, - RenderMode::Normal, - ) - )?; + render_assoc_item( + c, + AssocItemLink::Anchor(None), + ItemType::Trait, + 4, + Ending::NoNewline, + RenderMode::Normal, + cx, + ) + .fmt(w)?; + w.write_str(";\n")?; } } if !toggle && should_hide_fields(count_methods) { @@ -767,17 +760,17 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: writeln!(w, " // Required method{}", pluralize(required_methods.len()))?; } for (pos, m) in required_methods.iter().enumerate() { - writeln!( - w, - "{};", - render_assoc_item( - m, - AssocItemLink::Anchor(None), - ItemType::Trait, - cx, - RenderMode::Normal, - ) - )?; + render_assoc_item( + m, + AssocItemLink::Anchor(None), + ItemType::Trait, + 4, + Ending::NoNewline, + RenderMode::Normal, + cx, + ) + .fmt(w)?; + w.write_str(";\n")?; if pos < required_methods.len() - 1 { w.write_str("")?; @@ -798,8 +791,10 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: m, AssocItemLink::Anchor(None), ItemType::Trait, - cx, + 4, + Ending::NoNewline, RenderMode::Normal, + cx, ) )?; @@ -867,9 +862,11 @@ fn item_trait(cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) -> impl fmt: render_assoc_item( m, AssocItemLink::Anchor(Some(&id)), - ItemType::Impl, - cx, + ItemType::Trait, + 0, + Ending::Newline, RenderMode::Normal, + cx, ) )?; document_item_info(cx, m, Some(t)).render_into(w).unwrap(); @@ -1542,7 +1539,7 @@ impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> { // And update `item_union.html`. fn fields_iter(&self) -> impl Iterator { self.fields.iter().filter_map(|f| match f.kind { - clean::StructFieldItem(ref ty) => Some((f, ty)), + ItemKind::StructField(ref ty) => Some((f, ty)), _ => None, }) } @@ -1567,7 +1564,7 @@ fn print_tuple_struct_fields(cx: &Context<'_>, s: &[clean::Item]) -> impl Displa fmt::from_fn(|f| { if !s.is_empty() && s.iter() - .all(|field| matches!(field.kind, clean::StrippedItem(clean::StructFieldItem(..)))) + .all(|field| matches!(field.kind, ItemKind::Stripped(ItemKind::StructField(..)))) { return f.write_str("/* private fields */"); } @@ -1575,8 +1572,8 @@ fn print_tuple_struct_fields(cx: &Context<'_>, s: &[clean::Item]) -> impl Displa s.iter() .map(|ty| { fmt::from_fn(|f| match ty.kind { - clean::StrippedItem(clean::StructFieldItem(_)) => f.write_str("_"), - clean::StructFieldItem(ref ty) => write!(f, "{}", print_type(ty, cx)), + ItemKind::Stripped(ItemKind::StructField(_)) => f.write_str("_"), + ItemKind::StructField(ref ty) => write!(f, "{}", print_type(ty, cx)), _ => unreachable!(), }) }) @@ -1672,7 +1669,7 @@ fn should_show_enum_discriminant( ) -> bool { let mut has_variants_with_value = false; for variant in variants { - if let clean::VariantItem(ref var) = variant.kind + if let ItemKind::Variant(ref var) = variant.kind && matches!(var.kind, clean::VariantKind::CLike) { has_variants_with_value |= var.discriminant.is_some(); @@ -1750,7 +1747,7 @@ fn render_enum_fields( render_attributes_in_code(w, v, TAB, cx)?; w.write_str(TAB)?; match v.kind { - clean::VariantItem(ref var) => match var.kind { + ItemKind::Variant(ref var) => match var.kind { clean::VariantKind::CLike => { write!( w, @@ -1832,16 +1829,15 @@ fn item_variants( .maybe_display() )?; render_attributes_in_code(w, variant, "", cx)?; - if let clean::VariantItem(ref var) = variant.kind - && let clean::VariantKind::CLike = var.kind - { + let ItemKind::Variant(variant_data) = &variant.kind else { unreachable!() }; + if let clean::VariantKind::CLike = variant_data.kind { write!( w, "{}", display_c_like_variant( cx, variant, - var, + variant_data, index, should_show_enum_discriminant, enum_def_id, @@ -1851,8 +1847,6 @@ fn item_variants( w.write_str(variant.name.unwrap().as_str())?; } - let clean::VariantItem(variant_data) = &variant.kind else { unreachable!() }; - if let clean::VariantKind::Tuple(ref s) = variant_data.kind { write!(w, "({})", print_tuple_struct_fields(cx, s))?; } @@ -1893,8 +1887,8 @@ fn item_variants( )?; for field in fields { match field.kind { - clean::StrippedItem(clean::StructFieldItem(_)) => {} - clean::StructFieldItem(ref ty) => { + ItemKind::Stripped(ItemKind::StructField(_)) => {} + ItemKind::StructField(ref ty) => { let id = cx.derive_id(format!( "variant.{}.field.{}", variant.name.unwrap(), @@ -2127,7 +2121,7 @@ fn item_fields( let mut fields = fields .iter() .filter_map(|f| match f.kind { - clean::StructFieldItem(ref ty) => Some((f, ty)), + ItemKind::StructField(ref ty) => Some((f, ty)), _ => None, }) .peekable(); @@ -2323,7 +2317,7 @@ pub(super) fn full_path(cx: &Context<'_>, item: &clean::Item) -> String { pub(super) fn print_item_path(item: &clean::Item) -> impl Display { fmt::from_fn(move |f| match item.kind { - clean::ItemKind::ModuleItem(..) => { + ItemKind::Module(..) => { write!(f, "{}index.html", ensure_trailing_slash(item.name.unwrap().as_str())) } _ => f.write_str(&item.html_filename()), @@ -2473,14 +2467,14 @@ fn render_union( writeln!(f, "{{")?; let count_fields = - fields.iter().filter(|field| matches!(field.kind, clean::StructFieldItem(..))).count(); + fields.iter().filter(|field| matches!(field.kind, ItemKind::StructField(..))).count(); let toggle = should_hide_fields(count_fields); if toggle { toggle_open(&mut f, format_args!("{count_fields} fields")); } for field in fields { - if let clean::StructFieldItem(ref ty) = field.kind { + if let ItemKind::StructField(ref ty) = field.kind { render_attributes_in_code(&mut f, field, " ", cx)?; writeln!( f, @@ -2567,7 +2561,7 @@ fn render_struct_fields( w.write_str("{")?; } let count_fields = - fields.iter().filter(|f| matches!(f.kind, clean::StructFieldItem(..))).count(); + fields.iter().filter(|f| matches!(f.kind, ItemKind::StructField(..))).count(); let has_visible_fields = count_fields > 0; let toggle = should_hide_fields(count_fields); if toggle { @@ -2577,7 +2571,7 @@ fn render_struct_fields( writeln!(w)?; } for field in fields { - if let clean::StructFieldItem(ref ty) = field.kind { + if let ItemKind::StructField(ref ty) = field.kind { render_attributes_in_code(w, field, format_args!("{tab} "), cx)?; writeln!( w, @@ -2609,7 +2603,7 @@ fn render_struct_fields( w.write_str("(")?; if !fields.is_empty() && fields.iter().all(|field| { - matches!(field.kind, clean::StrippedItem(clean::StructFieldItem(..))) + matches!(field.kind, ItemKind::Stripped(ItemKind::StructField(..))) }) { write!(w, "/* private fields */")?; @@ -2619,10 +2613,10 @@ fn render_struct_fields( w.write_str(", ")?; } match field.kind { - clean::StrippedItem(clean::StructFieldItem(..)) => { + ItemKind::Stripped(ItemKind::StructField(..)) => { write!(w, "_")?; } - clean::StructFieldItem(ref ty) => { + ItemKind::StructField(ref ty) => { write!( w, "{}{}", diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index b459ead9481cb..1848810c7f62b 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -22,7 +22,7 @@ use rustc_span::symbol::{Symbol, kw}; use stringdex::internals as stringdex_internals; use tracing::instrument; -use crate::clean::types::{Function, Generics, ItemId, Type, WherePredicate}; +use crate::clean::types::{Function, Generics, ItemId, ItemKind, Type, WherePredicate}; use crate::clean::{self, ExternalLocation, utils}; use crate::config::ShouldMerge; use crate::error::Error; @@ -2009,15 +2009,12 @@ pub(crate) fn get_function_type_for_search( } }); let (mut inputs, mut output, param_names, where_clause) = match item.kind { - clean::ForeignFunctionItem(ref f, _) - | clean::FunctionItem(ref f) - | clean::MethodItem(ref f, _) - | clean::RequiredMethodItem(ref f, _) => { + ItemKind::ForeignFn(ref f, _) | ItemKind::Fn(ref f) | ItemKind::AssocFn(ref f, _) => { get_fn_inputs_and_outputs(f, tcx, impl_or_trait_generics, cache) } - clean::ConstantItem(ref c) => make_nullary_fn(&c.type_), - clean::StaticItem(ref s) => make_nullary_fn(&s.type_), - clean::StructFieldItem(ref t) if let Some(parent) = parent => { + ItemKind::Const(ref c) => make_nullary_fn(&c.ty), + ItemKind::Static(ref s) => make_nullary_fn(&s.type_), + ItemKind::StructField(ref t) if let Some(parent) = parent => { let mut rgen: FxIndexMap)> = Default::default(); let output = get_index_type(t, vec![], &mut rgen); @@ -2338,8 +2335,7 @@ fn simplify_fn_type<'a, 'tcx>( && trait_.items.iter().any(|at| at.is_required_associated_type()) { for assoc_ty in &trait_.items { - if let clean::ItemKind::RequiredAssocTypeItem(_generics, bounds) = - &assoc_ty.kind + if let clean::ItemKind::RequiredAssocTy(_generics, bounds) = &assoc_ty.kind && let Some(name) = assoc_ty.name { let idx = -isize::try_from(rgen.len() + 1).unwrap(); diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 6fa033f927c85..87ba5df5c5879 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt; use tracing::debug; use super::{Context, ItemSection, impl_trait_key, item_ty_to_section}; -use crate::clean; +use crate::clean::{self, ItemKind}; use crate::formats::Impl; use crate::formats::item_type::ItemType; use crate::html::format::{print_path, print_type}; @@ -148,16 +148,16 @@ pub(super) fn print_sidebar( let mut blocks: Vec> = docblock_toc(cx, it, &mut ids).into_iter().collect(); let deref_id_map = cx.deref_id_map.borrow(); match it.kind { - clean::StructItem(ref s) => sidebar_struct(cx, it, s, &mut blocks, &deref_id_map), - clean::TraitItem(ref t) => sidebar_trait(cx, it, t, &mut blocks, &deref_id_map), - clean::PrimitiveItem(_) => sidebar_primitive(cx, it, &mut blocks, &deref_id_map), - clean::UnionItem(ref u) => sidebar_union(cx, it, u, &mut blocks, &deref_id_map), - clean::EnumItem(ref e) => sidebar_enum(cx, it, e, &mut blocks, &deref_id_map), - clean::TypeAliasItem(ref t) => sidebar_type_alias(cx, it, t, &mut blocks, &deref_id_map), - clean::ModuleItem(ref m) => { + ItemKind::Struct(ref s) => sidebar_struct(cx, it, s, &mut blocks, &deref_id_map), + ItemKind::Trait(ref t) => sidebar_trait(cx, it, t, &mut blocks, &deref_id_map), + ItemKind::Primitive(_) => sidebar_primitive(cx, it, &mut blocks, &deref_id_map), + ItemKind::Union(ref u) => sidebar_union(cx, it, u, &mut blocks, &deref_id_map), + ItemKind::Enum(ref e) => sidebar_enum(cx, it, e, &mut blocks, &deref_id_map), + ItemKind::TyAlias(ref t) => sidebar_type_alias(cx, it, t, &mut blocks, &deref_id_map), + ItemKind::Module(ref m) => { blocks.push(sidebar_module(&m.items, &mut ids, ModuleLike::from(it))) } - clean::ForeignTypeItem => sidebar_foreign_type(cx, it, &mut blocks, &deref_id_map), + ItemKind::ForeignTy => sidebar_foreign_type(cx, it, &mut blocks, &deref_id_map), _ => {} } // The sidebar is designed to display sibling functions, modules and @@ -172,7 +172,7 @@ pub(super) fn print_sidebar( let (title_prefix, title) = if !blocks.is_empty() && !it.is_crate() { ( match it.kind { - clean::ModuleItem(..) => "Module ", + ItemKind::Module(..) => "Module ", _ => "", }, it.name.as_ref().unwrap().as_str(), @@ -210,7 +210,7 @@ pub(super) fn print_sidebar( fn get_struct_fields_name<'a>(fields: &'a [clean::Item]) -> Vec> { let mut fields = fields .iter() - .filter(|f| matches!(f.kind, clean::StructFieldItem(..))) + .filter(|f| matches!(f.kind, ItemKind::StructField(..))) .filter_map(|f| { f.name.as_ref().map(|name| Link::new(format!("structfield.{name}"), name.as_str())) }) @@ -314,9 +314,9 @@ fn sidebar_trait<'a>( let req_assoc = filter_items(&t.items, |m| m.is_required_associated_type(), "associatedtype"); let prov_assoc = filter_items(&t.items, |m| m.is_associated_type(), "associatedtype"); let req_assoc_const = - filter_items(&t.items, |m| m.is_required_associated_const(), "associatedconstant"); + filter_items(&t.items, |m| m.is_assoc_const_without_body(), "associatedconstant"); let prov_assoc_const = - filter_items(&t.items, |m| m.is_associated_const(), "associatedconstant"); + filter_items(&t.items, |m| m.is_assoc_const_with_body(), "associatedconstant"); let req_method = filter_items(&t.items, |m| m.is_ty_method(), "tymethod"); let prov_method = filter_items(&t.items, |m| m.is_method(), "method"); let mut foreign_impls = vec![]; @@ -532,7 +532,7 @@ fn sidebar_deref_methods<'a>( debug!("found Deref: {impl_:?}"); if let Some((target, real_target)) = impl_.inner_impl().items.iter().find_map(|item| match item.kind { - clean::AssocTypeItem(ref t, _) => Some(match *t { + ItemKind::AssocTy(ref t, _) => Some(match *t { clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_), _ => (&t.type_, &t.type_), }), @@ -672,7 +672,7 @@ fn sidebar_module( && it .name .or_else(|| { - if let clean::ImportItem(ref i) = it.kind + if let ItemKind::Import(ref i) = it.kind && let clean::ImportKind::Simple(s) = i.kind { Some(s) @@ -806,7 +806,7 @@ fn get_associated_constants<'a>( ) -> impl Iterator> { i.items.iter().filter_map(|item| { if let Some(ref name) = item.name - && item.is_associated_const() + && item.is_assoc_const_with_body() { Some(Link::new( get_next_url(used_links, format!("{typ}.{name}", typ = ItemType::AssocConst)), diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 258970bbb3b8f..7ccf9aad949d5 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -986,7 +986,7 @@ impl<'item> DocVisitor<'item> for TypeImplCollector<'_, '_, 'item> { fn visit_item(&mut self, it: &'item Item) { self.visit_item_recur(it); let cache = &self.cx.shared.cache; - let ItemKind::TypeAliasItem(ref t) = it.kind else { return }; + let ItemKind::TyAlias(ref t) = it.kind else { return }; let Some(self_did) = it.item_id.as_def_id() else { return }; if !self.visited_aliases.insert(self_did) { return; diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 588a61f8ad3cc..ccb49e2841398 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -56,13 +56,13 @@ impl JsonRenderer<'_> { let clean::ItemInner { name, item_id, .. } = *item.inner; let id = self.id_from_item(item); let inner = match item.kind { - clean::KeywordItem | clean::AttributeItem => return None, - clean::StrippedItem(ref inner) => { + clean::ItemKind::Keyword | clean::ItemKind::Attribute => return None, + clean::ItemKind::Stripped(ref inner) => { match &**inner { // We document stripped modules as with `Module::is_stripped` set to // `true`, to prevent contained items from being orphaned for downstream users, // as JSON does no inlining. - clean::ModuleItem(_) + clean::ItemKind::Module(_) if self.imported_items.contains(&item_id.expect_def_id()) => { from_clean_item(item, self) @@ -87,7 +87,7 @@ impl JsonRenderer<'_> { // JSON consumers already have to do path-based reasoning to reconstruct item reachability, // names, and stability. Keeping component-wise stability allows them to easily reconstruct // stability from the module, use item, and target item records. - let stability_def_id = if matches!(&item.kind, clean::ImportItem(_)) { + let stability_def_id = if matches!(&item.kind, clean::ItemKind::Import(_)) { item.inline_stmt_id .map(|def_id| def_id.to_def_id()) .or_else(|| item.item_id.as_def_id()) @@ -350,86 +350,76 @@ impl FromClean for AssocItemConstraintKind { } fn from_clean_item(item: &clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum { - use clean::ItemKind::*; + use clean::ItemKind; let name = item.name; let is_crate = item.is_crate(); let header = item.fn_header(renderer.tcx); match &item.inner.kind { - ModuleItem(m) => { + ItemKind::Module(m) => { ItemEnum::Module(Module { is_crate, items: renderer.ids(&m.items), is_stripped: false }) } - ImportItem(i) => ItemEnum::Use(i.into_json(renderer)), - StructItem(s) => ItemEnum::Struct(s.into_json(renderer)), - UnionItem(u) => ItemEnum::Union(u.into_json(renderer)), - StructFieldItem(f) => ItemEnum::StructField(f.into_json(renderer)), - EnumItem(e) => ItemEnum::Enum(e.into_json(renderer)), - VariantItem(v) => ItemEnum::Variant(v.into_json(renderer)), - FunctionItem(f) => { + ItemKind::Import(i) => ItemEnum::Use(i.into_json(renderer)), + ItemKind::Struct(s) => ItemEnum::Struct(s.into_json(renderer)), + ItemKind::Union(u) => ItemEnum::Union(u.into_json(renderer)), + ItemKind::StructField(f) => ItemEnum::StructField(f.into_json(renderer)), + ItemKind::Enum(e) => ItemEnum::Enum(e.into_json(renderer)), + ItemKind::Variant(v) => ItemEnum::Variant(v.into_json(renderer)), + ItemKind::Fn(f) => { ItemEnum::Function(from_clean_function(f, true, None, header.unwrap(), renderer)) } - ForeignFunctionItem(f, _) => { + ItemKind::ForeignFn(f, _) => { ItemEnum::Function(from_clean_function(f, false, None, header.unwrap(), renderer)) } - TraitItem(t) => ItemEnum::Trait(t.into_json(renderer)), - TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_json(renderer)), - MethodItem(m, _) => ItemEnum::Function(from_clean_function( + ItemKind::Trait(t) => ItemEnum::Trait(t.into_json(renderer)), + ItemKind::TraitAlias(t) => ItemEnum::TraitAlias(t.into_json(renderer)), + ItemKind::AssocFn(m, body) => ItemEnum::Function(from_clean_function( m, - true, + body.is_some(), default_body_stability_for_def_id(renderer.tcx, item.item_id.expect_def_id()) .map(|stab| stab.into_json(renderer)), header.unwrap(), renderer, )), - RequiredMethodItem(m, _) => { - ItemEnum::Function(from_clean_function(m, false, None, header.unwrap(), renderer)) + ItemKind::Impl(i) => ItemEnum::Impl(i.into_json(renderer)), + ItemKind::Static(s) => { + ItemEnum::Static(from_clean_static(s, rustc_hir::Safety::Safe, renderer)) } - ImplItem(i) => ItemEnum::Impl(i.into_json(renderer)), - StaticItem(s) => ItemEnum::Static(from_clean_static(s, rustc_hir::Safety::Safe, renderer)), - ForeignStaticItem(s, safety) => ItemEnum::Static(from_clean_static(s, *safety, renderer)), - ForeignTypeItem => ItemEnum::ExternType, - TypeAliasItem(t) => ItemEnum::TypeAlias(t.into_json(renderer)), + ItemKind::ForeignStatic(s, safety) => { + ItemEnum::Static(from_clean_static(s, *safety, renderer)) + } + ItemKind::ForeignTy => ItemEnum::ExternType, + ItemKind::TyAlias(t) => ItemEnum::TypeAlias(t.into_json(renderer)), // FIXME(generic_const_items): Add support for generic free consts - ConstantItem(ci) => ItemEnum::Constant { - type_: ci.type_.into_json(renderer), - const_: ci.kind.into_json(renderer), + ItemKind::Const(ci) => ItemEnum::Constant { + type_: ci.ty.into_json(renderer), + const_: ci.rhs.into_json(renderer), }, - MacroItem(m, _) => ItemEnum::Macro(m.source.clone()), - ProcMacroItem(m) => ItemEnum::ProcMacro(m.into_json(renderer)), - PrimitiveItem(p) => { + ItemKind::DeclMacro(m, _) => ItemEnum::Macro(m.source.clone()), + ItemKind::ProcMacro(m) => ItemEnum::ProcMacro(m.into_json(renderer)), + ItemKind::Primitive(p) => { ItemEnum::Primitive(Primitive { name: p.as_sym().to_string(), impls: Vec::new(), // Added in JsonRenderer::item }) } // FIXME(generic_const_items): Add support for generic associated consts. - RequiredAssocConstItem(_generics, ty) => ItemEnum::AssocConst { - type_: ty.into_json(renderer), - value: None, - default_unstable: None, - }, - // FIXME(generic_const_items): Add support for generic associated consts. - ProvidedAssocConstItem(ci) => ItemEnum::AssocConst { - type_: ci.type_.into_json(renderer), - value: Some(ci.kind.expr(renderer.tcx)), + ItemKind::AssocConst(ct) => ItemEnum::AssocConst { + type_: ct.ty.into_json(renderer), + value: ct.rhs.as_ref().map(|rhs| rhs.expr(renderer.tcx)), default_unstable: default_body_stability_for_def_id( renderer.tcx, item.item_id.expect_def_id(), ) .map(|stab| stab.into_json(renderer)), }, - ImplAssocConstItem(ci) => ItemEnum::AssocConst { - type_: ci.type_.into_json(renderer), - value: Some(ci.kind.expr(renderer.tcx)), - default_unstable: None, - }, - RequiredAssocTypeItem(g, b) => ItemEnum::AssocType { + ItemKind::RequiredAssocTy(g, b) => ItemEnum::AssocType { generics: g.into_json(renderer), bounds: b.into_json(renderer), type_: None, default_unstable: None, }, - AssocTypeItem(t, b) => ItemEnum::AssocType { + ItemKind::AssocTy(t, b) => ItemEnum::AssocType { generics: t.generics.into_json(renderer), bounds: b.into_json(renderer), type_: Some(t.item_type.as_ref().unwrap_or(&t.type_).into_json(renderer)), @@ -441,10 +431,10 @@ fn from_clean_item(item: &clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum }, // `convert_item` early returns `None` for stripped items, keywords, attributes and // "special" macro rules. - KeywordItem | AttributeItem => unreachable!(), - StrippedItem(inner) => { + ItemKind::Keyword | ItemKind::Attribute => unreachable!(), + ItemKind::Stripped(inner) => { match inner.as_ref() { - ModuleItem(m) => ItemEnum::Module(Module { + ItemKind::Module(m) => ItemEnum::Module(Module { is_crate, items: renderer.ids(&m.items), is_stripped: true, @@ -453,12 +443,12 @@ fn from_clean_item(item: &clean::Item, renderer: &JsonRenderer<'_>) -> ItemEnum _ => unreachable!(), } } - ExternCrateItem { src } => ItemEnum::ExternCrate { + ItemKind::ExternCrate { src } => ItemEnum::ExternCrate { name: name.as_ref().unwrap().to_string(), rename: src.map(|x| x.to_string()), }, // All placeholder impl items should have been removed in the stripper passes. - PlaceholderImplItem => unreachable!(), + ItemKind::PlaceholderImpl => unreachable!(), } } diff --git a/src/librustdoc/json/ids.rs b/src/librustdoc/json/ids.rs index 31043b8028f02..30ddee24df383 100644 --- a/src/librustdoc/json/ids.rs +++ b/src/librustdoc/json/ids.rs @@ -107,7 +107,7 @@ impl JsonRenderer<'_> { pub(crate) fn id_from_item(&self, item: &clean::Item) -> types::Id { match item.kind { - clean::ItemKind::ImportItem(ref import) => { + clean::ItemKind::Import(ref import) => { let imported_id = import.source.did; self.id_from_item_inner(item.item_id, item.name, imported_id) } diff --git a/src/librustdoc/json/import_finder.rs b/src/librustdoc/json/import_finder.rs index e21fe9668d400..657555b155375 100644 --- a/src/librustdoc/json/import_finder.rs +++ b/src/librustdoc/json/import_finder.rs @@ -25,7 +25,9 @@ struct ImportFinder { impl DocFolder for ImportFinder { fn fold_item(&mut self, i: Item) -> Option { match i.kind { - clean::ImportItem(Import { source: ImportSource { did: Some(did), .. }, .. }) => { + clean::ItemKind::Import(Import { + source: ImportSource { did: Some(did), .. }, .. + }) => { self.imported.insert(did); Some(i) } diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index bdd2b7d416d80..ae489d09a1388 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -89,7 +89,7 @@ impl<'tcx> JsonRenderer<'tcx> { // document primitive items in an arbitrary crate by using // `rustc_doc_primitive`. let mut is_primitive_impl = false; - if let clean::types::ItemKind::ImplItem(ref impl_) = item.kind + if let clean::types::ItemKind::Impl(ref impl_) = item.kind && impl_.trait_.is_none() && let clean::types::Type::Primitive(_) = impl_.for_ { @@ -253,7 +253,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { // Flatten items that recursively store other items. We include orphaned items from // stripped modules and etc that are otherwise reachable. - if let ItemKind::StrippedItem(inner) = &item.kind { + if let ItemKind::Stripped(inner) = &item.kind { inner.inner_items().for_each(|i| self.item(i).unwrap()); } diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs index 17f69b68b537d..1e9d7bf9f5a07 100644 --- a/src/librustdoc/passes/check_doc_test_visibility.rs +++ b/src/librustdoc/passes/check_doc_test_visibility.rs @@ -53,28 +53,26 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) - || item.is_exported_macro()) || matches!( item.kind, - clean::StructFieldItem(_) - | clean::VariantItem(_) - | clean::TypeAliasItem(_) - | clean::StaticItem(_) - | clean::ConstantItem(..) - | clean::ExternCrateItem { .. } - | clean::ImportItem(_) - | clean::PrimitiveItem(_) - | clean::KeywordItem - | clean::AttributeItem - | clean::ModuleItem(_) - | clean::TraitAliasItem(_) - | clean::ForeignFunctionItem(..) - | clean::ForeignStaticItem(..) - | clean::ForeignTypeItem - | clean::AssocTypeItem(..) - | clean::RequiredAssocConstItem(..) - | clean::ProvidedAssocConstItem(..) - | clean::ImplAssocConstItem(..) - | clean::RequiredAssocTypeItem(..) - | clean::ImplItem(_) - | clean::PlaceholderImplItem + ItemKind::StructField(_) + | ItemKind::Variant(_) + | ItemKind::TyAlias(_) + | ItemKind::Static(_) + | ItemKind::Const(..) + | ItemKind::ExternCrate { .. } + | ItemKind::Import(_) + | ItemKind::Primitive(_) + | ItemKind::Keyword + | ItemKind::Attribute + | ItemKind::Module(_) + | ItemKind::TraitAlias(_) + | ItemKind::ForeignFn(..) + | ItemKind::ForeignStatic(..) + | ItemKind::ForeignTy + | ItemKind::AssocTy(..) + | ItemKind::AssocConst(..) + | ItemKind::RequiredAssocTy(..) + | ItemKind::Impl(_) + | ItemKind::PlaceholderImpl ) { return false; diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 1bfac8e67748c..38960b628edf1 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -145,7 +145,7 @@ pub(super) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> } }); - if let ModuleItem(Module { items, .. }) = &mut krate.module.inner.kind { + if let ItemKind::Module(Module { items, .. }) = &mut krate.module.inner.kind { items.extend(synth_impls); items.extend(new_items_external); items.extend(new_items_local); @@ -303,7 +303,7 @@ impl DocVisitor<'_> for ItemAndAliasCollector<'_> { fn visit_item(&mut self, i: &Item) { self.items.insert(i.item_id); - if let TypeAliasItem(alias) = &i.inner.kind + if let ItemKind::TyAlias(alias) = &i.inner.kind && let Some(did) = alias.type_.def_id(self.cache) { self.items.insert(ItemId::DefId(did)); diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs index 0d16141fa09a1..e3a0bb9df829e 100644 --- a/src/librustdoc/passes/propagate_doc_cfg.rs +++ b/src/librustdoc/passes/propagate_doc_cfg.rs @@ -77,7 +77,7 @@ impl CfgPropagator<'_, '_> { // Same if it's an inlined item: we need to get the full original `cfg`. // // Otherwise, `cfg_info` already tracks everything we need so nothing else to do! - if matches!(item.kind, ItemKind::ImplItem(_)) || item.inline_stmt_id.is_some() { + if matches!(item.kind, ItemKind::Impl(_)) || item.inline_stmt_id.is_some() { if let Some(mut next_def_id) = item.item_id.as_local_def_id() { while let Some(parent_def_id) = self.cx.tcx.opt_local_parent(next_def_id) { let x = load_attrs(self.cx.tcx, parent_def_id.to_def_id()); @@ -88,7 +88,7 @@ impl CfgPropagator<'_, '_> { } // We also need to merge an item attributes with its parent's in case it's a macro with // the `#[macro_export]` attribute, because it might not be defined at crate root. - else if matches!(item.kind, ItemKind::MacroItem(_, _)) + else if matches!(item.kind, ItemKind::DeclMacro(_, _)) && item.inner.attrs.other_attrs.iter().any(|attr| { matches!( attr, @@ -124,12 +124,12 @@ impl DocFolder for CfgPropagator<'_, '_> { // If we have an impl, we check if it has an associated `cfg` "context", and if so we will // use that context instead of the actual (wrong) one. - if let ItemKind::ImplItem(_) = item.kind + if let ItemKind::Impl(_) = item.kind && let Some(cfg_info) = self.impl_cfg_info.remove(&item.item_id) { self.cfg_info = cfg_info; } - if let ItemKind::PlaceholderImplItem = item.kind { + if let ItemKind::PlaceholderImpl = item.kind { if let Some(impl_def_id) = item.item_id.as_def_id() { let tcx = self.cx.tcx; let expn_data = tcx.expn_that_defined(impl_def_id).expn_data(); diff --git a/src/librustdoc/passes/propagate_stability.rs b/src/librustdoc/passes/propagate_stability.rs index 9afde1e6195e7..10cc6b38f7460 100644 --- a/src/librustdoc/passes/propagate_stability.rs +++ b/src/librustdoc/passes/propagate_stability.rs @@ -63,29 +63,29 @@ impl DocFolder for StabilityPropagator<'_, '_> { }; let kind = match &item.kind { - ItemKind::StrippedItem(kind) => kind, + ItemKind::Stripped(kind) => kind, kind => kind, }; match kind { - ItemKind::ExternCrateItem { .. } - | ItemKind::ImportItem(..) - | ItemKind::StructItem(..) - | ItemKind::UnionItem(..) - | ItemKind::EnumItem(..) - | ItemKind::FunctionItem(..) - | ItemKind::ModuleItem(..) - | ItemKind::TypeAliasItem(..) - | ItemKind::StaticItem(..) - | ItemKind::TraitItem(..) - | ItemKind::TraitAliasItem(..) - | ItemKind::StructFieldItem(..) - | ItemKind::VariantItem(..) - | ItemKind::ForeignFunctionItem(..) - | ItemKind::ForeignStaticItem(..) - | ItemKind::ForeignTypeItem - | ItemKind::MacroItem(..) - | ItemKind::ProcMacroItem(..) - | ItemKind::ConstantItem(..) => { + ItemKind::ExternCrate { .. } + | ItemKind::Import(..) + | ItemKind::Struct(..) + | ItemKind::Union(..) + | ItemKind::Enum(..) + | ItemKind::Fn(..) + | ItemKind::Module(..) + | ItemKind::TyAlias(..) + | ItemKind::Static(..) + | ItemKind::Trait(..) + | ItemKind::TraitAlias(..) + | ItemKind::StructField(..) + | ItemKind::Variant(..) + | ItemKind::ForeignFn(..) + | ItemKind::ForeignStatic(..) + | ItemKind::ForeignTy + | ItemKind::DeclMacro(..) + | ItemKind::ProcMacro(..) + | ItemKind::Const(..) => { // If any of the item's parents was stabilized later or is still unstable, // then use the parent's stability instead. merge_stability(own_stability, parent_stability) @@ -93,20 +93,17 @@ impl DocFolder for StabilityPropagator<'_, '_> { // Don't inherit the parent's stability for these items, because they // are potentially accessible even if the parent is more unstable. - ItemKind::ImplItem(..) - | ItemKind::RequiredMethodItem(..) - | ItemKind::MethodItem(..) - | ItemKind::RequiredAssocConstItem(..) - | ItemKind::ProvidedAssocConstItem(..) - | ItemKind::ImplAssocConstItem(..) - | ItemKind::RequiredAssocTypeItem(..) - | ItemKind::AssocTypeItem(..) - | ItemKind::PrimitiveItem(..) - | ItemKind::KeywordItem - | ItemKind::AttributeItem - | ItemKind::PlaceholderImplItem => own_stability, + ItemKind::Impl(..) + | ItemKind::AssocFn(..) + | ItemKind::AssocConst(..) + | ItemKind::RequiredAssocTy(..) + | ItemKind::AssocTy(..) + | ItemKind::Primitive(..) + | ItemKind::Keyword + | ItemKind::Attribute + | ItemKind::PlaceholderImpl => own_stability, - ItemKind::StrippedItem(..) => unreachable!(), + ItemKind::Stripped(..) => unreachable!(), } } ItemId::Auto { .. } | ItemId::Blanket { .. } => { diff --git a/src/librustdoc/passes/strip_aliased_non_local.rs b/src/librustdoc/passes/strip_aliased_non_local.rs index 06418bf97ed2b..a963fb0243e88 100644 --- a/src/librustdoc/passes/strip_aliased_non_local.rs +++ b/src/librustdoc/passes/strip_aliased_non_local.rs @@ -22,7 +22,7 @@ struct AliasedNonLocalStripper<'tcx> { impl DocFolder for AliasedNonLocalStripper<'_> { fn fold_item(&mut self, i: Item) -> Option { Some(match i.kind { - clean::TypeAliasItem(..) => { + clean::ItemKind::TyAlias(..) => { let mut stripper = NonLocalStripper { tcx: self.tcx }; // don't call `fold_item` as that could strip the type alias itself // which we don't want to strip out diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index 95219d5e10a63..27670d0b299aa 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::TyCtxt; use tracing::debug; use crate::clean::utils::inherits_doc_hidden; -use crate::clean::{self, Item, ItemIdSet, reexport_chain}; +use crate::clean::{self, Item, ItemIdSet, ItemKind, reexport_chain}; use crate::core::DocContext; use crate::fold::{DocFolder, strip_item}; use crate::passes::ImplStripper; @@ -85,7 +85,7 @@ impl DocFolder for Stripper<'_, '_> { fn fold_item(&mut self, i: Item) -> Option { let has_doc_hidden = i.is_doc_hidden(); - if let clean::ImportItem(clean::Import { source, .. }) = &i.kind + if let ItemKind::Import(clean::Import { source, .. }) = &i.kind && let Some(source_did) = source.did { if self.tcx.is_doc_hidden(source_did) { @@ -106,10 +106,10 @@ impl DocFolder for Stripper<'_, '_> { } let is_impl_or_exported_macro = match i.kind { - clean::ImplItem(..) => true, + ItemKind::Impl(..) => true, // If the macro has the `#[macro_export]` attribute, it means it's accessible at the // crate level so it should be handled differently. - clean::MacroItem(..) => i.is_exported_macro(), + ItemKind::DeclMacro(..) => i.is_exported_macro(), _ => false, }; let mut is_hidden = has_doc_hidden; @@ -153,7 +153,7 @@ impl DocFolder for Stripper<'_, '_> { // not included in the final docs, but since they still have an effect // on the final doc, cannot be completely removed from the Clean IR. match i.kind { - clean::StructFieldItem(..) | clean::ModuleItem(..) | clean::VariantItem(..) => { + ItemKind::StructField(..) | ItemKind::Module(..) | ItemKind::Variant(..) => { // We need to recurse into stripped modules to // strip things like impl methods but when doing so // we must not add any items to the `retained` set. diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 4c6d62917ab24..fe3e73f43745f 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::{TyCtxt, Visibility}; use tracing::debug; use crate::clean::utils::inherits_doc_hidden; -use crate::clean::{self, Item, ItemId, ItemIdSet}; +use crate::clean::{self, Item, ItemId, ItemIdSet, ItemKind}; use crate::fold::{DocFolder, strip_item}; use crate::formats::cache::Cache; use crate::visit_lib::RustdocEffectiveVisibilities; @@ -40,7 +40,7 @@ fn is_item_reachable( impl DocFolder for Stripper<'_, '_> { fn fold_item(&mut self, i: Item) -> Option { match i.kind { - clean::StrippedItem(..) => { + ItemKind::Stripped(..) => { // We need to recurse into stripped modules to strip things // like impl methods but when doing so we must not add any // items to the `retained` set. @@ -51,20 +51,20 @@ impl DocFolder for Stripper<'_, '_> { return Some(ret); } // These items can all get re-exported - clean::TypeAliasItem(..) - | clean::StaticItem(..) - | clean::StructItem(..) - | clean::EnumItem(..) - | clean::TraitItem(..) - | clean::FunctionItem(..) - | clean::VariantItem(..) - | clean::ForeignFunctionItem(..) - | clean::ForeignStaticItem(..) - | clean::ConstantItem(..) - | clean::UnionItem(..) - | clean::TraitAliasItem(..) - | clean::MacroItem(..) - | clean::ForeignTypeItem => { + ItemKind::TyAlias(..) + | ItemKind::Static(..) + | ItemKind::Struct(..) + | ItemKind::Enum(..) + | ItemKind::Trait(..) + | ItemKind::Fn(..) + | ItemKind::Variant(..) + | ItemKind::ForeignFn(..) + | ItemKind::ForeignStatic(..) + | ItemKind::Const(..) + | ItemKind::Union(..) + | ItemKind::TraitAlias(..) + | ItemKind::DeclMacro(..) + | ItemKind::ForeignTy => { let item_id = i.item_id; if item_id.is_local() && !is_item_reachable( @@ -79,10 +79,9 @@ impl DocFolder for Stripper<'_, '_> { } } - clean::MethodItem(..) - | clean::ProvidedAssocConstItem(..) - | clean::ImplAssocConstItem(..) - | clean::AssocTypeItem(..) => { + ItemKind::AssocFn(_, Some(_)) + | ItemKind::AssocConst(clean::AssocConst { rhs: Some(_), .. }) + | ItemKind::AssocTy(..) => { let item_id = i.item_id; if item_id.is_local() && !self.effective_visibilities.is_reachable(self.tcx, item_id.expect_def_id()) @@ -92,13 +91,13 @@ impl DocFolder for Stripper<'_, '_> { } } - clean::StructFieldItem(..) => { + ItemKind::StructField(..) => { if i.visibility(self.tcx) != Some(Visibility::Public) { return Some(strip_item(i)); } } - clean::ModuleItem(..) => { + ItemKind::Module(..) => { if i.item_id.is_local() && !is_item_reachable( self.tcx, @@ -116,40 +115,40 @@ impl DocFolder for Stripper<'_, '_> { } // handled in the `strip-priv-imports` pass - clean::ExternCrateItem { .. } | clean::ImportItem(_) => {} + ItemKind::ExternCrate { .. } | ItemKind::Import(_) => {} - clean::ImplItem(..) => {} + ItemKind::Impl(..) => {} // Since the `doc_cfg` propagation was handled before the current pass, we can (and // should) remove all placeholder impl items. - clean::PlaceholderImplItem => return None, + ItemKind::PlaceholderImpl => return None, - // tymethods etc. have no control over privacy - clean::RequiredMethodItem(..) - | clean::RequiredAssocConstItem(..) - | clean::RequiredAssocTypeItem(..) => {} + // They have no control over privacy + ItemKind::AssocFn(_, None) + | ItemKind::AssocConst(clean::AssocConst { rhs: None, .. }) + | ItemKind::RequiredAssocTy(..) => {} // Proc-macros are always public - clean::ProcMacroItem(..) => {} + ItemKind::ProcMacro(..) => {} // Primitives are never stripped - clean::PrimitiveItem(..) => {} + ItemKind::Primitive(..) => {} // Keywords are never stripped - clean::KeywordItem => {} + ItemKind::Keyword => {} // Attributes are never stripped - clean::AttributeItem => {} + ItemKind::Attribute => {} } let fastreturn = match i.kind { // nothing left to do for traits (don't want to filter their // methods out, visibility controlled by the trait) - clean::TraitItem(..) => true, + ItemKind::Trait(..) => true, // implementations of traits are always public. - clean::ImplItem(ref imp) if imp.trait_.is_some() => true, + ItemKind::Impl(ref imp) if imp.trait_.is_some() => true, // Variant fields have inherited visibility - clean::VariantItem(clean::Variant { + ItemKind::Variant(clean::Variant { kind: clean::VariantKind::Struct(..) | clean::VariantKind::Tuple(..), .. }) => true, @@ -206,7 +205,7 @@ impl ImplStripper<'_, '_> { impl DocFolder for ImplStripper<'_, '_> { fn fold_item(&mut self, i: Item) -> Option { - if let clean::ImplItem(ref imp) = i.kind { + if let ItemKind::Impl(ref imp) = i.kind { // Impl blocks can be skipped if they are: empty; not a trait impl; and have no // documentation. // @@ -284,14 +283,14 @@ impl ImportStripper<'_> { impl DocFolder for ImportStripper<'_> { fn fold_item(&mut self, i: Item) -> Option { match &i.kind { - clean::ImportItem(imp) + ItemKind::Import(imp) if !self.document_hidden && self.import_should_be_hidden(&i, imp) => { debug!("ImportStripper: stripping {:?}", i.name); None } - // clean::ImportItem(_) if !self.document_hidden && i.is_doc_hidden() => None, - clean::ExternCrateItem { .. } | clean::ImportItem(..) + // ItemKind::ImportItem(_) if !self.document_hidden && i.is_doc_hidden() => None, + ItemKind::ExternCrate { .. } | ItemKind::Import(..) if i.visibility(self.tcx) != Some(Visibility::Public) => { debug!("ImportStripper: stripping {:?}", i.name); diff --git a/src/librustdoc/visit.rs b/src/librustdoc/visit.rs index 86115f3853011..796c9f1c350c5 100644 --- a/src/librustdoc/visit.rs +++ b/src/librustdoc/visit.rs @@ -14,51 +14,48 @@ pub(crate) trait DocVisitor<'a>: Sized { /// Don't override! fn visit_inner_recur(&mut self, kind: &'a ItemKind) { match kind { - StrippedItem(..) => unreachable!(), - ModuleItem(i) => { + ItemKind::Stripped(..) => unreachable!(), + ItemKind::Module(i) => { self.visit_mod(i); } - StructItem(i) => i.fields.iter().for_each(|x| self.visit_item(x)), - UnionItem(i) => i.fields.iter().for_each(|x| self.visit_item(x)), - EnumItem(i) => i.variants.iter().for_each(|x| self.visit_item(x)), - TraitItem(i) => i.items.iter().for_each(|x| self.visit_item(x)), - ImplItem(i) => i.items.iter().for_each(|x| self.visit_item(x)), - VariantItem(i) => match &i.kind { + ItemKind::Struct(i) => i.fields.iter().for_each(|x| self.visit_item(x)), + ItemKind::Union(i) => i.fields.iter().for_each(|x| self.visit_item(x)), + ItemKind::Enum(i) => i.variants.iter().for_each(|x| self.visit_item(x)), + ItemKind::Trait(i) => i.items.iter().for_each(|x| self.visit_item(x)), + ItemKind::Impl(i) => i.items.iter().for_each(|x| self.visit_item(x)), + ItemKind::Variant(i) => match &i.kind { VariantKind::Struct(j) => j.fields.iter().for_each(|x| self.visit_item(x)), VariantKind::Tuple(fields) => fields.iter().for_each(|x| self.visit_item(x)), VariantKind::CLike => {} }, - ExternCrateItem { src: _ } - | ImportItem(_) - | FunctionItem(_) - | TypeAliasItem(_) - | StaticItem(_) - | ConstantItem(..) - | TraitAliasItem(_) - | RequiredMethodItem(..) - | MethodItem(..) - | StructFieldItem(_) - | ForeignFunctionItem(..) - | ForeignStaticItem(..) - | ForeignTypeItem - | MacroItem(..) - | ProcMacroItem(_) - | PrimitiveItem(_) - | RequiredAssocConstItem(..) - | ProvidedAssocConstItem(..) - | ImplAssocConstItem(..) - | RequiredAssocTypeItem(..) - | AssocTypeItem(..) - | KeywordItem - | AttributeItem - | PlaceholderImplItem => {} + ItemKind::ExternCrate { src: _ } + | ItemKind::Import(_) + | ItemKind::Fn(_) + | ItemKind::TyAlias(_) + | ItemKind::Static(_) + | ItemKind::Const(..) + | ItemKind::TraitAlias(_) + | ItemKind::AssocFn(..) + | ItemKind::StructField(_) + | ItemKind::ForeignFn(..) + | ItemKind::ForeignStatic(..) + | ItemKind::ForeignTy + | ItemKind::DeclMacro(..) + | ItemKind::ProcMacro(_) + | ItemKind::Primitive(_) + | ItemKind::AssocConst(..) + | ItemKind::RequiredAssocTy(..) + | ItemKind::AssocTy(..) + | ItemKind::Keyword + | ItemKind::Attribute + | ItemKind::PlaceholderImpl => {} } } /// Don't override! fn visit_item_recur(&mut self, item: &'a Item) { match &item.kind { - StrippedItem(i) => self.visit_inner_recur(i), + ItemKind::Stripped(i) => self.visit_inner_recur(i), _ => self.visit_inner_recur(&item.kind), } } diff --git a/tests/rustdoc-html/constant/generic-const-items.rs b/tests/rustdoc-html/constant/generic-const-items.rs index 31c300f2ff1e1..27719f5a8df6d 100644 --- a/tests/rustdoc-html/constant/generic-const-items.rs +++ b/tests/rustdoc-html/constant/generic-const-items.rs @@ -13,9 +13,9 @@ where //@ has generic_const_items/trait.Trait.html pub trait Trait { //@ has - '//*[@id="associatedconstant.C"]' \ - // "const C<'a>: &'a T \ + // "const C<'a>: &'a T\ // where \ - // T: 'a + Eq" + // T: 'a + Eq," const C<'a>: &'a T where T: 'a + Eq; @@ -27,7 +27,7 @@ pub struct Implementor; //@ has - '//h3[@class="code-header"]' 'impl Trait for Implementor' impl Trait for Implementor { //@ has - '//*[@id="associatedconstant.C"]' \ - // "const C<'a>: &'a str = \"C\" \ + // "const C<'a>: &'a str = \"C\"\ // where \ // str: 'a" const C<'a>: &'a str = "C" diff --git a/tests/rustdoc-html/generic-associated-types/gats.rs b/tests/rustdoc-html/generic-associated-types/gats.rs index ecfa1796e7274..ec57609e98b49 100644 --- a/tests/rustdoc-html/generic-associated-types/gats.rs +++ b/tests/rustdoc-html/generic-associated-types/gats.rs @@ -2,7 +2,7 @@ //@ has foo/trait.LendingIterator.html pub trait LendingIterator { - //@ has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' "type Item<'a> where Self: 'a" + //@ has - '//*[@id="associatedtype.Item"]//h4[@class="code-header"]' "type Item<'a>where Self: 'a" type Item<'a> where Self: 'a; //@ has - '//*[@id="tymethod.next"]//h4[@class="code-header"]' \ @@ -23,7 +23,7 @@ impl LendingIterator for () { pub struct Infinite(T); //@ has foo/trait.LendingIterator.html -//@ has - '//*[@id="associatedtype.Item-2"]//h4[@class="code-header"]' "type Item<'a> = &'a T where Self: 'a" +//@ has - '//*[@id="associatedtype.Item-2"]//h4[@class="code-header"]' "type Item<'a> = &'a Twhere Self: 'a" impl LendingIterator for Infinite { type Item<'a> = &'a T where Self: 'a; diff --git a/tests/rustdoc-html/inline_cross/assoc_item_trait_bounds.rs b/tests/rustdoc-html/inline_cross/assoc_item_trait_bounds.rs index d301c35599427..c15131dd8f7fa 100644 --- a/tests/rustdoc-html/inline_cross/assoc_item_trait_bounds.rs +++ b/tests/rustdoc-html/inline_cross/assoc_item_trait_bounds.rs @@ -50,7 +50,7 @@ pub use aux::Aid; //@ has main/struct.Implementor.html //@ has - '//*[@id="associatedtype.Alias"]' \ -// "type Alias = T \ +// "type Alias = T\ // where \ // String: From, \ // ::Alias: From<::Alias>" diff --git a/tests/rustdoc-html/inline_cross/generic-const-items.rs b/tests/rustdoc-html/inline_cross/generic-const-items.rs index 70018b6ddb556..1397ad52203d7 100644 --- a/tests/rustdoc-html/inline_cross/generic-const-items.rs +++ b/tests/rustdoc-html/inline_cross/generic-const-items.rs @@ -12,7 +12,7 @@ pub use generic_const_items::K; //@ has user/trait.Trait.html //@ has - '//*[@id="associatedconstant.C"]' \ -// "const C<'a>: &'a T \ +// "const C<'a>: &'a T\ // where \ // T: 'a + Eq" pub use generic_const_items::Trait; @@ -20,7 +20,7 @@ pub use generic_const_items::Trait; //@ has user/struct.Implementor.html //@ has - '//h3[@class="code-header"]' 'impl Trait for Implementor' //@ has - '//*[@id="associatedconstant.C"]' \ -// "const C<'a>: &'a str = \"C\" \ +// "const C<'a>: &'a str = \"C\"\ // where \ // str: 'a" pub use generic_const_items::Implementor;