diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index fffd9499209..27fb4709982 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -20,12 +20,12 @@ struct RegionDeps<'tcx> { smaller: FxHashSet>, } -crate struct AutoTraitFinder<'a, 'tcx> { - crate cx: &'a mut core::DocContext<'tcx>, +pub(crate) struct AutoTraitFinder<'a, 'tcx> { + pub(crate) cx: &'a mut core::DocContext<'tcx>, } impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { - crate fn new(cx: &'a mut core::DocContext<'tcx>) -> Self { + pub(crate) fn new(cx: &'a mut core::DocContext<'tcx>) -> Self { AutoTraitFinder { cx } } @@ -130,7 +130,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { }) } - crate fn get_auto_trait_impls(&mut self, item_def_id: DefId) -> Vec { + pub(crate) fn get_auto_trait_impls(&mut self, item_def_id: DefId) -> Vec { let tcx = self.cx.tcx; let param_env = tcx.param_env(item_def_id); let ty = tcx.type_of(item_def_id); diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 805cc5c71d8..c591c591331 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -8,12 +8,12 @@ use rustc_span::DUMMY_SP; use super::*; -crate struct BlanketImplFinder<'a, 'tcx> { - crate cx: &'a mut core::DocContext<'tcx>, +pub(crate) struct BlanketImplFinder<'a, 'tcx> { + pub(crate) cx: &'a mut core::DocContext<'tcx>, } impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { - crate fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec { + pub(crate) fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec { let param_env = self.cx.tcx.param_env(item_def_id); let ty = self.cx.tcx.bound_type_of(item_def_id); diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 9e9c4dfb506..deac1723b26 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -21,7 +21,7 @@ use crate::html::escape::Escape; mod tests; #[derive(Clone, Debug, PartialEq, Eq, Hash)] -crate enum Cfg { +pub(crate) enum Cfg { /// Accepts all configurations. True, /// Denies all configurations. @@ -37,9 +37,9 @@ crate enum Cfg { } #[derive(PartialEq, Debug)] -crate struct InvalidCfgError { - crate msg: &'static str, - crate span: Span, +pub(crate) struct InvalidCfgError { + pub(crate) msg: &'static str, + pub(crate) span: Span, } impl Cfg { @@ -56,7 +56,7 @@ impl Cfg { } } - crate fn parse_without( + pub(crate) fn parse_without( cfg: &MetaItem, exclude: &FxHashSet, ) -> Result, InvalidCfgError> { @@ -117,7 +117,7 @@ impl Cfg { /// /// If the content is not properly formatted, it will return an error indicating what and where /// the error is. - crate fn parse(cfg: &MetaItem) -> Result { + pub(crate) fn parse(cfg: &MetaItem) -> Result { Self::parse_without(cfg, &FxHashSet::default()).map(|ret| ret.unwrap()) } @@ -125,7 +125,7 @@ impl Cfg { /// /// Equivalent to `attr::cfg_matches`. // FIXME: Actually make use of `features`. - crate fn matches(&self, parse_sess: &ParseSess, features: Option<&Features>) -> bool { + pub(crate) fn matches(&self, parse_sess: &ParseSess, features: Option<&Features>) -> bool { match *self { Cfg::False => false, Cfg::True => true, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 9a579cb5311..1b6658bb4ca 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -38,7 +38,7 @@ type Attrs<'hir> = &'hir [ast::Attribute]; /// and `Some` of a vector of items if it was successfully expanded. /// /// `parent_module` refers to the parent of the *re-export*, not the original item. -crate fn try_inline( +pub(crate) fn try_inline( cx: &mut DocContext<'_>, parent_module: DefId, import_def_id: Option, @@ -134,7 +134,7 @@ crate fn try_inline( Some(ret) } -crate fn try_inline_glob( +pub(crate) fn try_inline_glob( cx: &mut DocContext<'_>, res: Res, visited: &mut FxHashSet, @@ -154,7 +154,7 @@ crate fn try_inline_glob( } } -crate fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> { +pub(crate) fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> { cx.tcx.get_attrs_unchecked(did) } @@ -162,7 +162,7 @@ crate fn load_attrs<'hir>(cx: &DocContext<'hir>, did: DefId) -> Attrs<'hir> { /// /// These names are used later on by HTML rendering to generate things like /// source links back to the original item. -crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) { +pub(crate) fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) { let crate_name = cx.tcx.crate_name(did.krate); let relative = @@ -190,7 +190,7 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType) } } -crate fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait { +pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Trait { let trait_items = cx .tcx .associated_items(did) @@ -274,7 +274,7 @@ fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef { } /// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport. -crate fn build_impls( +pub(crate) fn build_impls( cx: &mut DocContext<'_>, parent_module: Option, did: DefId, @@ -318,7 +318,7 @@ fn merge_attrs( } /// Inline an `impl`, inherent or of a trait. The `did` must be for an `impl`. -crate fn build_impl( +pub(crate) fn build_impl( cx: &mut DocContext<'_>, parent_module: Option, did: DefId, @@ -565,7 +565,7 @@ fn build_module( clean::Module { items, span } } -crate fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String { +pub(crate) fn print_inlined_const(tcx: TyCtxt<'_>, did: DefId) -> String { if let Some(did) = did.as_local() { let hir_id = tcx.hir().local_def_id_to_hir_id(did); rustc_hir_pretty::id_to_string(&tcx.hir(), hir_id) @@ -670,7 +670,7 @@ fn separate_supertrait_bounds( (g, ty_bounds) } -crate fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) { +pub(crate) fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) { if did.is_local() { return; } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6e18f381c59..4f66b4a240c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -3,12 +3,12 @@ mod auto_trait; mod blanket_impl; -crate mod cfg; -crate mod inline; +pub(crate) mod cfg; +pub(crate) mod inline; mod render_macro_matchers; mod simplify; -crate mod types; -crate mod utils; +pub(crate) mod types; +pub(crate) mod utils; use rustc_ast as ast; use rustc_attr as attr; @@ -41,10 +41,10 @@ use crate::visit_ast::Module as DocModule; use utils::*; -crate use self::types::*; -crate use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res}; +pub(crate) use self::types::*; +pub(crate) use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res}; -crate trait Clean { +pub(crate) trait Clean { fn clean(&self, cx: &mut DocContext<'_>) -> T; } diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 194c25a795a..af7813a7740 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -21,7 +21,7 @@ use crate::clean::GenericArgs as PP; use crate::clean::WherePredicate as WP; use crate::core::DocContext; -crate fn where_clauses(cx: &DocContext<'_>, clauses: Vec) -> Vec { +pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: Vec) -> Vec { // First, partition the where clause into its separate components. // // We use `FxIndexMap` so that the insertion order is preserved to prevent messing up to @@ -79,7 +79,7 @@ crate fn where_clauses(cx: &DocContext<'_>, clauses: Vec) -> Vec { clauses } -crate fn merge_bounds( +pub(crate) fn merge_bounds( cx: &clean::DocContext<'_>, bounds: &mut Vec, trait_did: DefId, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 456d860f125..edf7ddb30db 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -44,22 +44,22 @@ use crate::formats::item_type::ItemType; use crate::html::render::Context; use crate::passes::collect_intra_doc_links::UrlFragment; -crate use self::FnRetTy::*; -crate use self::ItemKind::*; -crate use self::SelfTy::*; -crate use self::Type::{ +pub(crate) use self::FnRetTy::*; +pub(crate) use self::ItemKind::*; +pub(crate) use self::SelfTy::*; +pub(crate) use self::Type::{ Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath, RawPointer, Slice, Tuple, }; -crate use self::Visibility::{Inherited, Public}; +pub(crate) use self::Visibility::{Inherited, Public}; #[cfg(test)] mod tests; -crate type ItemIdSet = FxHashSet; +pub(crate) type ItemIdSet = FxHashSet; #[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] -crate enum ItemId { +pub(crate) enum ItemId { /// A "normal" item that uses a [`DefId`] for identification. DefId(DefId), /// Identifier that is used for auto traits. @@ -72,7 +72,7 @@ crate enum ItemId { impl ItemId { #[inline] - crate fn is_local(self) -> bool { + pub(crate) fn is_local(self) -> bool { match self { ItemId::Auto { for_: id, .. } | ItemId::Blanket { for_: id, .. } @@ -83,13 +83,13 @@ impl ItemId { #[inline] #[track_caller] - crate fn expect_def_id(self) -> DefId { + pub(crate) fn expect_def_id(self) -> DefId { self.as_def_id() .unwrap_or_else(|| panic!("ItemId::expect_def_id: `{:?}` isn't a DefId", self)) } #[inline] - crate fn as_def_id(self) -> Option { + pub(crate) fn as_def_id(self) -> Option { match self { ItemId::DefId(id) => Some(id), _ => None, @@ -97,7 +97,7 @@ impl ItemId { } #[inline] - crate fn krate(self) -> CrateNum { + pub(crate) fn krate(self) -> CrateNum { match self { ItemId::Auto { for_: id, .. } | ItemId::Blanket { for_: id, .. } @@ -115,11 +115,11 @@ impl From for ItemId { /// The crate currently being documented. #[derive(Clone, Debug)] -crate struct Crate { - crate module: Item, - crate primitives: ThinVec<(DefId, PrimitiveType)>, +pub(crate) struct Crate { + pub(crate) module: Item, + pub(crate) primitives: ThinVec<(DefId, PrimitiveType)>, /// Only here so that they can be filtered through the rustdoc passes. - crate external_traits: Rc>>, + pub(crate) external_traits: Rc>>, } // `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger. @@ -127,45 +127,45 @@ crate struct Crate { rustc_data_structures::static_assert_size!(Crate, 72); impl Crate { - crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol { + pub(crate) fn name(&self, tcx: TyCtxt<'_>) -> Symbol { ExternalCrate::LOCAL.name(tcx) } - crate fn src(&self, tcx: TyCtxt<'_>) -> FileName { + pub(crate) fn src(&self, tcx: TyCtxt<'_>) -> FileName { ExternalCrate::LOCAL.src(tcx) } } /// This struct is used to wrap additional information added by rustdoc on a `trait` item. #[derive(Clone, Debug)] -crate struct TraitWithExtraInfo { - crate trait_: Trait, - crate is_notable: bool, +pub(crate) struct TraitWithExtraInfo { + pub(crate) trait_: Trait, + pub(crate) is_notable: bool, } #[derive(Copy, Clone, Debug)] -crate struct ExternalCrate { - crate crate_num: CrateNum, +pub(crate) struct ExternalCrate { + pub(crate) crate_num: CrateNum, } impl ExternalCrate { const LOCAL: Self = Self { crate_num: LOCAL_CRATE }; #[inline] - crate fn def_id(&self) -> DefId { + pub(crate) fn def_id(&self) -> DefId { self.crate_num.as_def_id() } - crate fn src(&self, tcx: TyCtxt<'_>) -> FileName { + pub(crate) fn src(&self, tcx: TyCtxt<'_>) -> FileName { let krate_span = tcx.def_span(self.def_id()); tcx.sess.source_map().span_to_filename(krate_span) } - crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol { + pub(crate) fn name(&self, tcx: TyCtxt<'_>) -> Symbol { tcx.crate_name(self.crate_num) } - crate fn src_root(&self, tcx: TyCtxt<'_>) -> PathBuf { + pub(crate) fn src_root(&self, tcx: TyCtxt<'_>) -> PathBuf { match self.src(tcx) { FileName::Real(ref p) => match p.local_path_if_available().parent() { Some(p) => p.to_path_buf(), @@ -177,7 +177,7 @@ impl ExternalCrate { /// Attempts to find where an external crate is located, given that we're /// rendering in to the specified source destination. - crate fn location( + pub(crate) fn location( &self, extern_url: Option<&str>, extern_url_takes_precedence: bool, @@ -221,7 +221,7 @@ impl ExternalCrate { .unwrap_or(Unknown) // Well, at least we tried. } - crate fn keywords(&self, tcx: TyCtxt<'_>) -> ThinVec<(DefId, Symbol)> { + pub(crate) fn keywords(&self, tcx: TyCtxt<'_>) -> ThinVec<(DefId, Symbol)> { let root = self.def_id(); let as_keyword = |res: Res| { @@ -268,7 +268,7 @@ impl ExternalCrate { } } - crate fn primitives(&self, tcx: TyCtxt<'_>) -> ThinVec<(DefId, PrimitiveType)> { + pub(crate) fn primitives(&self, tcx: TyCtxt<'_>) -> ThinVec<(DefId, PrimitiveType)> { let root = self.def_id(); // Collect all inner modules which are tagged as implementations of @@ -341,7 +341,7 @@ impl ExternalCrate { /// Indicates where an external crate can be found. #[derive(Debug)] -crate enum ExternalLocation { +pub(crate) enum ExternalLocation { /// Remote URL root of the external crate Remote(String), /// This external crate can be found in the local doc/ folder @@ -354,18 +354,18 @@ crate enum ExternalLocation { /// name. That is, anything that can be documented. This doesn't correspond /// directly to the AST's concept of an item; it's a strict superset. #[derive(Clone)] -crate struct Item { +pub(crate) struct Item { /// The name of this item. /// Optional because not every item has a name, e.g. impls. - crate name: Option, - crate attrs: Box, - crate visibility: Visibility, + pub(crate) name: Option, + pub(crate) attrs: Box, + pub(crate) visibility: Visibility, /// Information about this item that is specific to what kind of item it is. /// E.g., struct vs enum vs function. - crate kind: Box, - crate item_id: ItemId, + pub(crate) kind: Box, + pub(crate) item_id: ItemId, - crate cfg: Option>, + pub(crate) cfg: Option>, } /// NOTE: this does NOT unconditionally print every item, to avoid thousands of lines of logs. @@ -393,7 +393,7 @@ impl fmt::Debug for Item { #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] rustc_data_structures::static_assert_size!(Item, 56); -crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { +pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { Span::new(def_id.as_local().map_or_else( || tcx.def_span(def_id), |local| { @@ -404,26 +404,26 @@ crate fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { } impl Item { - crate fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option { + pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option { self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did)) } - crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option { + pub(crate) fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option { self.item_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did)) } - crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn deprecation(&self, tcx: TyCtxt<'_>) -> Option { self.item_id.as_def_id().and_then(|did| tcx.lookup_deprecation(did)) } - crate fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool { + pub(crate) fn inner_docs(&self, tcx: TyCtxt<'_>) -> bool { self.item_id .as_def_id() .map(|did| tcx.get_attrs_unchecked(did).inner_docs()) .unwrap_or(false) } - crate fn span(&self, tcx: TyCtxt<'_>) -> Span { + pub(crate) fn span(&self, tcx: TyCtxt<'_>) -> Span { let kind = match &*self.kind { ItemKind::StrippedItem(k) => k, _ => &*self.kind, @@ -444,19 +444,19 @@ impl Item { } } - crate fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span { + pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span { crate::passes::span_of_attrs(&self.attrs).unwrap_or_else(|| self.span(tcx).inner()) } /// Finds the `doc` attribute as a NameValue and returns the corresponding /// value found. - crate fn doc_value(&self) -> Option { + pub(crate) fn doc_value(&self) -> Option { self.attrs.doc_value() } /// Convenience wrapper around [`Self::from_def_id_and_parts`] which converts /// `hir_id` to a [`DefId`] - crate fn from_hir_id_and_parts( + pub(crate) fn from_hir_id_and_parts( hir_id: hir::HirId, name: Option, kind: ItemKind, @@ -465,7 +465,7 @@ impl Item { Item::from_def_id_and_parts(cx.tcx.hir().local_def_id(hir_id).to_def_id(), name, kind, cx) } - crate fn from_def_id_and_parts( + pub(crate) fn from_def_id_and_parts( def_id: DefId, name: Option, kind: ItemKind, @@ -483,7 +483,7 @@ impl Item { ) } - crate fn from_def_id_and_attrs_and_parts( + pub(crate) fn from_def_id_and_attrs_and_parts( def_id: DefId, name: Option, kind: ItemKind, @@ -508,11 +508,11 @@ impl Item { /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined /// with newlines. - crate fn collapsed_doc_value(&self) -> Option { + pub(crate) fn collapsed_doc_value(&self) -> Option { self.attrs.collapsed_doc_value() } - crate fn links(&self, cx: &Context<'_>) -> Vec { + pub(crate) fn links(&self, cx: &Context<'_>) -> Vec { use crate::html::format::href; cx.cache() @@ -544,7 +544,7 @@ impl Item { /// This is used for generating summary text, which does not include /// the link text, but does need to know which `[]`-bracketed names /// are actually links. - crate fn link_names(&self, cache: &Cache) -> Vec { + pub(crate) fn link_names(&self, cache: &Cache) -> Vec { cache .intra_doc_links .get(&self.item_id) @@ -558,68 +558,68 @@ impl Item { .collect() } - crate fn is_crate(&self) -> bool { + pub(crate) fn is_crate(&self) -> bool { self.is_mod() && self.item_id.as_def_id().map_or(false, |did| did.is_crate_root()) } - crate fn is_mod(&self) -> bool { + pub(crate) fn is_mod(&self) -> bool { self.type_() == ItemType::Module } - crate fn is_trait(&self) -> bool { + pub(crate) fn is_trait(&self) -> bool { self.type_() == ItemType::Trait } - crate fn is_struct(&self) -> bool { + pub(crate) fn is_struct(&self) -> bool { self.type_() == ItemType::Struct } - crate fn is_enum(&self) -> bool { + pub(crate) fn is_enum(&self) -> bool { self.type_() == ItemType::Enum } - crate fn is_variant(&self) -> bool { + pub(crate) fn is_variant(&self) -> bool { self.type_() == ItemType::Variant } - crate fn is_associated_type(&self) -> bool { + pub(crate) fn is_associated_type(&self) -> bool { matches!(&*self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..))) } - crate fn is_ty_associated_type(&self) -> bool { + pub(crate) fn is_ty_associated_type(&self) -> bool { matches!(&*self.kind, TyAssocTypeItem(..) | StrippedItem(box TyAssocTypeItem(..))) } - crate fn is_associated_const(&self) -> bool { + pub(crate) fn is_associated_const(&self) -> bool { matches!(&*self.kind, AssocConstItem(..) | StrippedItem(box AssocConstItem(..))) } - crate fn is_ty_associated_const(&self) -> bool { + pub(crate) fn is_ty_associated_const(&self) -> bool { matches!(&*self.kind, TyAssocConstItem(..) | StrippedItem(box TyAssocConstItem(..))) } - crate fn is_method(&self) -> bool { + pub(crate) fn is_method(&self) -> bool { self.type_() == ItemType::Method } - crate fn is_ty_method(&self) -> bool { + pub(crate) fn is_ty_method(&self) -> bool { self.type_() == ItemType::TyMethod } - crate fn is_typedef(&self) -> bool { + pub(crate) fn is_typedef(&self) -> bool { self.type_() == ItemType::Typedef } - crate fn is_primitive(&self) -> bool { + pub(crate) fn is_primitive(&self) -> bool { self.type_() == ItemType::Primitive } - crate fn is_union(&self) -> bool { + pub(crate) fn is_union(&self) -> bool { self.type_() == ItemType::Union } - crate fn is_import(&self) -> bool { + pub(crate) fn is_import(&self) -> bool { self.type_() == ItemType::Import } - crate fn is_extern_crate(&self) -> bool { + pub(crate) fn is_extern_crate(&self) -> bool { self.type_() == ItemType::ExternCrate } - crate fn is_keyword(&self) -> bool { + pub(crate) fn is_keyword(&self) -> bool { self.type_() == ItemType::Keyword } - crate fn is_stripped(&self) -> bool { + pub(crate) fn is_stripped(&self) -> bool { match *self.kind { StrippedItem(..) => true, ImportItem(ref i) => !i.should_be_displayed, _ => false, } } - crate fn has_stripped_fields(&self) -> Option { + pub(crate) fn has_stripped_fields(&self) -> Option { match *self.kind { StructItem(ref _struct) => Some(_struct.fields_stripped), UnionItem(ref union) => Some(union.fields_stripped), @@ -628,7 +628,7 @@ impl Item { } } - crate fn stability_class(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn stability_class(&self, tcx: TyCtxt<'_>) -> Option { self.stability(tcx).as_ref().and_then(|s| { let mut classes = Vec::with_capacity(2); @@ -645,30 +645,30 @@ impl Item { }) } - crate fn stable_since(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn stable_since(&self, tcx: TyCtxt<'_>) -> Option { match self.stability(tcx)?.level { StabilityLevel::Stable { since, .. } => Some(since), StabilityLevel::Unstable { .. } => None, } } - crate fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option { match self.const_stability(tcx)?.level { StabilityLevel::Stable { since, .. } => Some(since), StabilityLevel::Unstable { .. } => None, } } - crate fn is_non_exhaustive(&self) -> bool { + pub(crate) fn is_non_exhaustive(&self) -> bool { self.attrs.other_attrs.iter().any(|a| a.has_name(sym::non_exhaustive)) } /// Returns a documentation-level item type from the item. - crate fn type_(&self) -> ItemType { + pub(crate) fn type_(&self) -> ItemType { ItemType::from(self) } - crate fn is_default(&self) -> bool { + pub(crate) fn is_default(&self) -> bool { match *self.kind { ItemKind::MethodItem(_, Some(defaultness)) => { defaultness.has_value() && !defaultness.is_final() @@ -678,7 +678,7 @@ impl Item { } /// Returns a `FnHeader` if `self` is a function item, otherwise returns `None`. - crate fn fn_header(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn fn_header(&self, tcx: TyCtxt<'_>) -> Option { fn build_fn_header( def_id: DefId, tcx: TyCtxt<'_>, @@ -721,7 +721,7 @@ impl Item { } #[derive(Clone, Debug)] -crate enum ItemKind { +pub(crate) enum ItemKind { ExternCrateItem { /// The crate's name, *not* the name it's imported as. src: Option, @@ -774,7 +774,7 @@ crate enum ItemKind { impl ItemKind { /// Some items contain others such as structs (for their fields) and Enums /// (for their variants). This method returns those contained items. - crate fn inner_items(&self) -> impl Iterator { + pub(crate) fn inner_items(&self) -> impl Iterator { match self { StructItem(s) => s.fields.iter(), UnionItem(u) => u.fields.iter(), @@ -813,12 +813,12 @@ impl ItemKind { } #[derive(Clone, Debug)] -crate struct Module { - crate items: Vec, - crate span: Span, +pub(crate) struct Module { + pub(crate) items: Vec, + pub(crate) span: Span, } -crate trait AttributesExt { +pub(crate) trait AttributesExt { type AttributeIterator<'a>: Iterator where Self: 'a; @@ -949,7 +949,7 @@ impl AttributesExt for [ast::Attribute] { } } -crate trait NestedAttributesExt { +pub(crate) trait NestedAttributesExt { /// Returns `true` if the attribute list contains a specific `word` fn has_word(self, word: Symbol) -> bool where @@ -978,16 +978,16 @@ impl> NestedAttributesExt for I { /// information can be given when a doctest fails. Sugared doc comments and "raw" doc comments are /// kept separate because of issue #42760. #[derive(Clone, PartialEq, Eq, Debug)] -crate struct DocFragment { - crate span: rustc_span::Span, +pub(crate) struct DocFragment { + pub(crate) span: rustc_span::Span, /// The module this doc-comment came from. /// /// This allows distinguishing between the original documentation and a pub re-export. /// If it is `None`, the item was not re-exported. - crate parent_module: Option, - crate doc: Symbol, - crate kind: DocFragmentKind, - crate indent: usize, + pub(crate) parent_module: Option, + pub(crate) doc: Symbol, + pub(crate) kind: DocFragmentKind, + pub(crate) indent: usize, } // `DocFragment` is used a lot. Make sure it doesn't unintentionally get bigger. @@ -995,7 +995,7 @@ crate struct DocFragment { rustc_data_structures::static_assert_size!(DocFragment, 32); #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] -crate enum DocFragmentKind { +pub(crate) enum DocFragmentKind { /// A doc fragment created from a `///` or `//!` doc comment. SugaredDoc, /// A doc fragment created from a "raw" `#[doc=""]` attribute. @@ -1027,7 +1027,7 @@ fn add_doc_fragment(out: &mut String, frag: &DocFragment) { /// Collapse a collection of [`DocFragment`]s into one string, /// handling indentation and newlines as needed. -crate fn collapse_doc_fragments(doc_strings: &[DocFragment]) -> String { +pub(crate) fn collapse_doc_fragments(doc_strings: &[DocFragment]) -> String { let mut acc = String::new(); for frag in doc_strings { add_doc_fragment(&mut acc, frag); @@ -1120,44 +1120,44 @@ fn unindent_doc_fragments(docs: &mut Vec) { /// /// This link will be turned into a rendered link by [`Item::links`]. #[derive(Clone, Debug, PartialEq, Eq)] -crate struct ItemLink { +pub(crate) struct ItemLink { /// The original link written in the markdown - crate link: String, + pub(crate) link: String, /// The link text displayed in the HTML. /// /// This may not be the same as `link` if there was a disambiguator /// in an intra-doc link (e.g. \[`fn@f`\]) - crate link_text: String, - crate did: DefId, + pub(crate) link_text: String, + pub(crate) did: DefId, /// The url fragment to append to the link - crate fragment: Option, + pub(crate) fragment: Option, } pub struct RenderedLink { /// The text the link was original written as. /// /// This could potentially include disambiguators and backticks. - crate original_text: String, + pub(crate) original_text: String, /// The text to display in the HTML - crate new_text: String, + pub(crate) new_text: String, /// The URL to put in the `href` - crate href: String, + pub(crate) href: String, } /// The attributes on an [`Item`], including attributes like `#[derive(...)]` and `#[inline]`, /// as well as doc comments. #[derive(Clone, Debug, Default)] -crate struct Attributes { - crate doc_strings: Vec, - crate other_attrs: Vec, +pub(crate) struct Attributes { + pub(crate) doc_strings: Vec, + pub(crate) other_attrs: Vec, } impl Attributes { - crate fn lists(&self, name: Symbol) -> impl Iterator + '_ { + pub(crate) fn lists(&self, name: Symbol) -> impl Iterator + '_ { self.other_attrs.lists(name) } - crate fn has_doc_flag(&self, flag: Symbol) -> bool { + pub(crate) fn has_doc_flag(&self, flag: Symbol) -> bool { for attr in &self.other_attrs { if !attr.has_name(sym::doc) { continue; @@ -1173,7 +1173,7 @@ impl Attributes { false } - crate fn from_ast( + pub(crate) fn from_ast( attrs: &[ast::Attribute], additional_attrs: Option<(&[ast::Attribute], DefId)>, ) -> Attributes { @@ -1185,7 +1185,7 @@ impl Attributes { Attributes::from_ast_iter(attrs1.chain(attrs2), false) } - crate fn from_ast_iter<'a>( + pub(crate) fn from_ast_iter<'a>( attrs: impl Iterator)>, doc_only: bool, ) -> Attributes { @@ -1214,7 +1214,7 @@ impl Attributes { /// Finds the `doc` attribute as a NameValue and returns the corresponding /// value found. - crate fn doc_value(&self) -> Option { + pub(crate) fn doc_value(&self) -> Option { let mut iter = self.doc_strings.iter(); let ori = iter.next()?; @@ -1232,7 +1232,7 @@ impl Attributes { /// /// The last newline is not trimmed so the produced strings are reusable between /// early and late doc link resolution regardless of their position. - crate fn prepare_to_doc_link_resolution(&self) -> FxHashMap, String> { + pub(crate) fn prepare_to_doc_link_resolution(&self) -> FxHashMap, String> { let mut res = FxHashMap::default(); for fragment in &self.doc_strings { let out_str = res.entry(fragment.parent_module).or_default(); @@ -1243,7 +1243,7 @@ impl Attributes { /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined /// with newlines. - crate fn collapsed_doc_value(&self) -> Option { + pub(crate) fn collapsed_doc_value(&self) -> Option { if self.doc_strings.is_empty() { None } else { @@ -1251,7 +1251,7 @@ impl Attributes { } } - crate fn get_doc_aliases(&self) -> Box<[Symbol]> { + pub(crate) fn get_doc_aliases(&self) -> Box<[Symbol]> { let mut aliases = FxHashSet::default(); for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) { @@ -1286,13 +1286,13 @@ impl PartialEq for Attributes { impl Eq for Attributes {} #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum GenericBound { +pub(crate) enum GenericBound { TraitBound(PolyTrait, hir::TraitBoundModifier), Outlives(Lifetime), } impl GenericBound { - crate fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound { + pub(crate) fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound { let did = cx.tcx.require_lang_item(LangItem::Sized, None); let empty = cx.tcx.intern_substs(&[]); let path = external_path(cx, did, false, vec![], empty); @@ -1303,7 +1303,7 @@ impl GenericBound { ) } - crate fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool { + pub(crate) fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool { use rustc_hir::TraitBoundModifier as TBM; if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self { if Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait() { @@ -1313,14 +1313,14 @@ impl GenericBound { false } - crate fn get_poly_trait(&self) -> Option { + pub(crate) fn get_poly_trait(&self) -> Option { if let GenericBound::TraitBound(ref p, _) = *self { return Some(p.clone()); } None } - crate fn get_trait_path(&self) -> Option { + pub(crate) fn get_trait_path(&self) -> Option { if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, _) = *self { Some(trait_.clone()) } else { @@ -1330,27 +1330,27 @@ impl GenericBound { } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct Lifetime(pub Symbol); +pub(crate) struct Lifetime(pub Symbol); impl Lifetime { - crate fn statik() -> Lifetime { + pub(crate) fn statik() -> Lifetime { Lifetime(kw::StaticLifetime) } - crate fn elided() -> Lifetime { + pub(crate) fn elided() -> Lifetime { Lifetime(kw::UnderscoreLifetime) } } #[derive(Clone, Debug)] -crate enum WherePredicate { +pub(crate) enum WherePredicate { BoundPredicate { ty: Type, bounds: Vec, bound_params: Vec }, RegionPredicate { lifetime: Lifetime, bounds: Vec }, EqPredicate { lhs: Type, rhs: Term }, } impl WherePredicate { - crate fn get_bounds(&self) -> Option<&[GenericBound]> { + pub(crate) fn get_bounds(&self) -> Option<&[GenericBound]> { match *self { WherePredicate::BoundPredicate { ref bounds, .. } => Some(bounds), WherePredicate::RegionPredicate { ref bounds, .. } => Some(bounds), @@ -1360,22 +1360,22 @@ impl WherePredicate { } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum GenericParamDefKind { +pub(crate) enum GenericParamDefKind { Lifetime { outlives: Vec }, Type { did: DefId, bounds: Vec, default: Option>, synthetic: bool }, Const { did: DefId, ty: Box, default: Option> }, } impl GenericParamDefKind { - crate fn is_type(&self) -> bool { + pub(crate) fn is_type(&self) -> bool { matches!(self, GenericParamDefKind::Type { .. }) } } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct GenericParamDef { - crate name: Symbol, - crate kind: GenericParamDefKind, +pub(crate) struct GenericParamDef { + pub(crate) name: Symbol, + pub(crate) kind: GenericParamDefKind, } // `GenericParamDef` is used in many places. Make sure it doesn't unintentionally get bigger. @@ -1383,18 +1383,18 @@ crate struct GenericParamDef { rustc_data_structures::static_assert_size!(GenericParamDef, 56); impl GenericParamDef { - crate fn is_synthetic_type_param(&self) -> bool { + pub(crate) fn is_synthetic_type_param(&self) -> bool { match self.kind { GenericParamDefKind::Lifetime { .. } | GenericParamDefKind::Const { .. } => false, GenericParamDefKind::Type { synthetic, .. } => synthetic, } } - crate fn is_type(&self) -> bool { + pub(crate) fn is_type(&self) -> bool { self.kind.is_type() } - crate fn get_bounds(&self) -> Option<&[GenericBound]> { + pub(crate) fn get_bounds(&self) -> Option<&[GenericBound]> { match self.kind { GenericParamDefKind::Type { ref bounds, .. } => Some(bounds), _ => None, @@ -1404,26 +1404,26 @@ impl GenericParamDef { // maybe use a Generic enum and use Vec? #[derive(Clone, Debug, Default)] -crate struct Generics { - crate params: Vec, - crate where_predicates: Vec, +pub(crate) struct Generics { + pub(crate) params: Vec, + pub(crate) where_predicates: Vec, } #[derive(Clone, Debug)] -crate struct Function { - crate decl: FnDecl, - crate generics: Generics, +pub(crate) struct Function { + pub(crate) decl: FnDecl, + pub(crate) generics: Generics, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct FnDecl { - crate inputs: Arguments, - crate output: FnRetTy, - crate c_variadic: bool, +pub(crate) struct FnDecl { + pub(crate) inputs: Arguments, + pub(crate) output: FnRetTy, + pub(crate) c_variadic: bool, } impl FnDecl { - crate fn self_type(&self) -> Option { + pub(crate) fn self_type(&self) -> Option { self.inputs.values.get(0).and_then(|v| v.to_self()) } @@ -1436,7 +1436,7 @@ impl FnDecl { /// /// This function will panic if the return type does not match the expected sugaring for async /// functions. - crate fn sugared_async_return_type(&self) -> FnRetTy { + pub(crate) fn sugared_async_return_type(&self) -> FnRetTy { match &self.output { FnRetTy::Return(Type::ImplTrait(bounds)) => match &bounds[0] { GenericBound::TraitBound(PolyTrait { trait_, .. }, ..) => { @@ -1453,28 +1453,28 @@ impl FnDecl { } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct Arguments { - crate values: Vec, +pub(crate) struct Arguments { + pub(crate) values: Vec, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct Argument { - crate type_: Type, - crate name: Symbol, +pub(crate) struct Argument { + pub(crate) type_: Type, + pub(crate) name: Symbol, /// This field is used to represent "const" arguments from the `rustc_legacy_const_generics` /// feature. More information in . - crate is_const: bool, + pub(crate) is_const: bool, } #[derive(Clone, PartialEq, Debug)] -crate enum SelfTy { +pub(crate) enum SelfTy { SelfValue, SelfBorrowed(Option, Mutability), SelfExplicit(Type), } impl Argument { - crate fn to_self(&self) -> Option { + pub(crate) fn to_self(&self) -> Option { if self.name != kw::SelfLower { return None; } @@ -1491,13 +1491,13 @@ impl Argument { } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum FnRetTy { +pub(crate) enum FnRetTy { Return(Type), DefaultReturn, } impl FnRetTy { - crate fn as_return(&self) -> Option<&Type> { + pub(crate) fn as_return(&self) -> Option<&Type> { match self { Return(ret) => Some(ret), DefaultReturn => None, @@ -1506,30 +1506,30 @@ impl FnRetTy { } #[derive(Clone, Debug)] -crate struct Trait { - crate unsafety: hir::Unsafety, - crate items: Vec, - crate generics: Generics, - crate bounds: Vec, - crate is_auto: bool, +pub(crate) struct Trait { + pub(crate) unsafety: hir::Unsafety, + pub(crate) items: Vec, + pub(crate) generics: Generics, + pub(crate) bounds: Vec, + pub(crate) is_auto: bool, } #[derive(Clone, Debug)] -crate struct TraitAlias { - crate generics: Generics, - crate bounds: Vec, +pub(crate) struct TraitAlias { + pub(crate) generics: Generics, + pub(crate) bounds: Vec, } /// A trait reference, which may have higher ranked lifetimes. #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct PolyTrait { - crate trait_: Path, - crate generic_params: Vec, +pub(crate) struct PolyTrait { + pub(crate) trait_: Path, + pub(crate) generic_params: Vec, } /// Rustdoc's representation of types, mostly based on the [`hir::Ty`]. #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum Type { +pub(crate) enum Type { /// A named type, which could be a trait. /// /// This is mostly Rustdoc's version of [`hir::Path`]. @@ -1580,7 +1580,7 @@ rustc_data_structures::static_assert_size!(Type, 80); impl Type { /// When comparing types for equality, it can help to ignore `&` wrapping. - crate fn without_borrowed_ref(&self) -> &Type { + pub(crate) fn without_borrowed_ref(&self) -> &Type { let mut result = self; while let Type::BorrowedRef { type_, .. } = result { result = &*type_; @@ -1591,7 +1591,7 @@ impl Type { /// Check if two types are "potentially the same". /// This is different from `Eq`, because it knows that things like /// `Placeholder` are possible matches for everything. - crate fn is_same(&self, other: &Self, cache: &Cache) -> bool { + pub(crate) fn is_same(&self, other: &Self, cache: &Cache) -> bool { match (self, other) { // Recursive cases. (Type::Tuple(a), Type::Tuple(b)) => { @@ -1618,7 +1618,7 @@ impl Type { } } - crate fn primitive_type(&self) -> Option { + pub(crate) fn primitive_type(&self) -> Option { match *self { Primitive(p) | BorrowedRef { type_: box Primitive(p), .. } => Some(p), Slice(..) | BorrowedRef { type_: box Slice(..), .. } => Some(PrimitiveType::Slice), @@ -1637,36 +1637,36 @@ impl Type { } /// Checks if this is a `T::Name` path for an associated type. - crate fn is_assoc_ty(&self) -> bool { + pub(crate) fn is_assoc_ty(&self) -> bool { match self { Type::Path { path, .. } => path.is_assoc_ty(), _ => false, } } - crate fn is_self_type(&self) -> bool { + pub(crate) fn is_self_type(&self) -> bool { match *self { Generic(name) => name == kw::SelfUpper, _ => false, } } - crate fn generics(&self) -> Option> { + pub(crate) fn generics(&self) -> Option> { match self { Type::Path { path, .. } => path.generics(), _ => None, } } - crate fn is_full_generic(&self) -> bool { + pub(crate) fn is_full_generic(&self) -> bool { matches!(self, Type::Generic(_)) } - crate fn is_primitive(&self) -> bool { + pub(crate) fn is_primitive(&self) -> bool { self.primitive_type().is_some() } - crate fn projection(&self) -> Option<(&Type, DefId, PathSegment)> { + pub(crate) fn projection(&self) -> Option<(&Type, DefId, PathSegment)> { if let QPath { self_type, trait_, assoc, .. } = self { Some((&self_type, trait_.def_id(), *assoc.clone())) } else { @@ -1701,7 +1701,7 @@ impl Type { /// Use this method to get the [DefId] of a [clean] AST node, including [PrimitiveType]s. /// /// [clean]: crate::clean - crate fn def_id(&self, cache: &Cache) -> Option { + pub(crate) fn def_id(&self, cache: &Cache) -> Option { self.inner_def_id(Some(cache)) } } @@ -1713,7 +1713,7 @@ impl Type { /// N.B. This has to be different from [`hir::PrimTy`] because it also includes types that aren't /// paths, like [`Self::Unit`]. #[derive(Clone, PartialEq, Eq, Hash, Copy, Debug)] -crate enum PrimitiveType { +pub(crate) enum PrimitiveType { Isize, I8, I16, @@ -1743,7 +1743,7 @@ crate enum PrimitiveType { type SimplifiedTypes = FxHashMap>; impl PrimitiveType { - crate fn from_hir(prim: hir::PrimTy) -> PrimitiveType { + pub(crate) fn from_hir(prim: hir::PrimTy) -> PrimitiveType { use ast::{FloatTy, IntTy, UintTy}; match prim { hir::PrimTy::Int(IntTy::Isize) => PrimitiveType::Isize, @@ -1766,7 +1766,7 @@ impl PrimitiveType { } } - crate fn from_symbol(s: Symbol) -> Option { + pub(crate) fn from_symbol(s: Symbol) -> Option { match s { sym::isize => Some(PrimitiveType::Isize), sym::i8 => Some(PrimitiveType::I8), @@ -1797,7 +1797,7 @@ impl PrimitiveType { } } - crate fn simplified_types() -> &'static SimplifiedTypes { + pub(crate) fn simplified_types() -> &'static SimplifiedTypes { use ty::fast_reject::SimplifiedTypeGen::*; use ty::{FloatTy, IntTy, UintTy}; use PrimitiveType::*; @@ -1842,7 +1842,7 @@ impl PrimitiveType { }) } - crate fn impls<'tcx>(&self, tcx: TyCtxt<'tcx>) -> impl Iterator + 'tcx { + pub(crate) fn impls<'tcx>(&self, tcx: TyCtxt<'tcx>) -> impl Iterator + 'tcx { Self::simplified_types() .get(self) .into_iter() @@ -1851,7 +1851,7 @@ impl PrimitiveType { .copied() } - crate fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator + '_ { + pub(crate) fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator + '_ { Self::simplified_types() .values() .flatten() @@ -1859,7 +1859,7 @@ impl PrimitiveType { .copied() } - crate fn as_sym(&self) -> Symbol { + pub(crate) fn as_sym(&self) -> Symbol { use PrimitiveType::*; match self { Isize => sym::isize, @@ -1897,7 +1897,7 @@ impl PrimitiveType { /// but otherwise, if multiple crates define the same primitive, there is no guarantee of which will be picked. /// In particular, if a crate depends on both `std` and another crate that also defines `doc(primitive)`, then /// it's entirely random whether `std` or the other crate is picked. (no_std crates are usually fine unless multiple dependencies define a primitive.) - crate fn primitive_locations(tcx: TyCtxt<'_>) -> &FxHashMap { + pub(crate) fn primitive_locations(tcx: TyCtxt<'_>) -> &FxHashMap { static PRIMITIVE_LOCATIONS: OnceCell> = OnceCell::new(); PRIMITIVE_LOCATIONS.get_or_init(|| { let mut primitive_locations = FxHashMap::default(); @@ -2008,7 +2008,7 @@ impl From for PrimitiveType { } #[derive(Copy, Clone, Debug)] -crate enum Visibility { +pub(crate) enum Visibility { /// `pub` Public, /// Visibility inherited from parent. @@ -2020,45 +2020,45 @@ crate enum Visibility { } impl Visibility { - crate fn is_public(&self) -> bool { + pub(crate) fn is_public(&self) -> bool { matches!(self, Visibility::Public) } } #[derive(Clone, Debug)] -crate struct Struct { - crate struct_type: CtorKind, - crate generics: Generics, - crate fields: Vec, - crate fields_stripped: bool, +pub(crate) struct Struct { + pub(crate) struct_type: CtorKind, + pub(crate) generics: Generics, + pub(crate) fields: Vec, + pub(crate) fields_stripped: bool, } #[derive(Clone, Debug)] -crate struct Union { - crate generics: Generics, - crate fields: Vec, - crate fields_stripped: bool, +pub(crate) struct Union { + pub(crate) generics: Generics, + pub(crate) fields: Vec, + pub(crate) fields_stripped: bool, } /// This is a more limited form of the standard Struct, different in that /// it lacks the things most items have (name, id, parameterization). Found /// only as a variant in an enum. #[derive(Clone, Debug)] -crate struct VariantStruct { - crate struct_type: CtorKind, - crate fields: Vec, - crate fields_stripped: bool, +pub(crate) struct VariantStruct { + pub(crate) struct_type: CtorKind, + pub(crate) fields: Vec, + pub(crate) fields_stripped: bool, } #[derive(Clone, Debug)] -crate struct Enum { - crate variants: IndexVec, - crate generics: Generics, - crate variants_stripped: bool, +pub(crate) struct Enum { + pub(crate) variants: IndexVec, + pub(crate) generics: Generics, + pub(crate) variants_stripped: bool, } #[derive(Clone, Debug)] -crate enum Variant { +pub(crate) enum Variant { CLike, Tuple(Vec), Struct(VariantStruct), @@ -2067,63 +2067,63 @@ crate enum Variant { /// Small wrapper around [`rustc_span::Span`] that adds helper methods /// and enforces calling [`rustc_span::Span::source_callsite()`]. #[derive(Copy, Clone, Debug)] -crate struct Span(rustc_span::Span); +pub(crate) struct Span(rustc_span::Span); impl Span { /// Wraps a [`rustc_span::Span`]. In case this span is the result of a macro expansion, the /// span will be updated to point to the macro invocation instead of the macro definition. /// /// (See rust-lang/rust#39726) - crate fn new(sp: rustc_span::Span) -> Self { + pub(crate) fn new(sp: rustc_span::Span) -> Self { Self(sp.source_callsite()) } - crate fn inner(&self) -> rustc_span::Span { + pub(crate) fn inner(&self) -> rustc_span::Span { self.0 } - crate fn dummy() -> Self { + pub(crate) fn dummy() -> Self { Self(rustc_span::DUMMY_SP) } - crate fn is_dummy(&self) -> bool { + pub(crate) fn is_dummy(&self) -> bool { self.0.is_dummy() } - crate fn filename(&self, sess: &Session) -> FileName { + pub(crate) fn filename(&self, sess: &Session) -> FileName { sess.source_map().span_to_filename(self.0) } - crate fn lo(&self, sess: &Session) -> Loc { + pub(crate) fn lo(&self, sess: &Session) -> Loc { sess.source_map().lookup_char_pos(self.0.lo()) } - crate fn hi(&self, sess: &Session) -> Loc { + pub(crate) fn hi(&self, sess: &Session) -> Loc { sess.source_map().lookup_char_pos(self.0.hi()) } - crate fn cnum(&self, sess: &Session) -> CrateNum { + pub(crate) fn cnum(&self, sess: &Session) -> CrateNum { // FIXME: is there a time when the lo and hi crate would be different? self.lo(sess).file.cnum } } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct Path { - crate res: Res, - crate segments: Vec, +pub(crate) struct Path { + pub(crate) res: Res, + pub(crate) segments: Vec, } impl Path { - crate fn def_id(&self) -> DefId { + pub(crate) fn def_id(&self) -> DefId { self.res.def_id() } - crate fn last(&self) -> Symbol { + pub(crate) fn last(&self) -> Symbol { self.segments.last().expect("segments were empty").name } - crate fn whole_name(&self) -> String { + pub(crate) fn whole_name(&self) -> String { self.segments .iter() .map(|s| if s.name == kw::PathRoot { String::new() } else { s.name.to_string() }) @@ -2132,7 +2132,7 @@ impl Path { } /// Checks if this is a `T::Name` path for an associated type. - crate fn is_assoc_ty(&self) -> bool { + pub(crate) fn is_assoc_ty(&self) -> bool { match self.res { Res::SelfTy { .. } if self.segments.len() != 1 => true, Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true, @@ -2141,7 +2141,7 @@ impl Path { } } - crate fn generics(&self) -> Option> { + pub(crate) fn generics(&self) -> Option> { self.segments.last().and_then(|seg| { if let GenericArgs::AngleBracketed { ref args, .. } = seg.args { Some( @@ -2158,7 +2158,7 @@ impl Path { }) } - crate fn bindings(&self) -> Option<&[TypeBinding]> { + pub(crate) fn bindings(&self) -> Option<&[TypeBinding]> { self.segments.last().and_then(|seg| { if let GenericArgs::AngleBracketed { ref bindings, .. } = seg.args { Some(&**bindings) @@ -2170,7 +2170,7 @@ impl Path { } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum GenericArg { +pub(crate) enum GenericArg { Lifetime(Lifetime), Type(Type), Const(Box), @@ -2183,7 +2183,7 @@ crate enum GenericArg { rustc_data_structures::static_assert_size!(GenericArg, 88); #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum GenericArgs { +pub(crate) enum GenericArgs { AngleBracketed { args: Vec, bindings: ThinVec }, Parenthesized { inputs: Vec, output: Option> }, } @@ -2194,9 +2194,9 @@ crate enum GenericArgs { rustc_data_structures::static_assert_size!(GenericArgs, 40); #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct PathSegment { - crate name: Symbol, - crate args: GenericArgs, +pub(crate) struct PathSegment { + pub(crate) name: Symbol, + pub(crate) args: GenericArgs, } // `PathSegment` usually occurs multiple times in every `Path`, so its size can @@ -2205,53 +2205,53 @@ crate struct PathSegment { rustc_data_structures::static_assert_size!(PathSegment, 48); #[derive(Clone, Debug)] -crate struct Typedef { - crate type_: Type, - crate generics: Generics, +pub(crate) struct Typedef { + pub(crate) type_: Type, + pub(crate) generics: Generics, /// `type_` can come from either the HIR or from metadata. If it comes from HIR, it may be a type /// alias instead of the final type. This will always have the final type, regardless of whether /// `type_` came from HIR or from metadata. /// /// If `item_type.is_none()`, `type_` is guaranteed to come from metadata (and therefore hold the /// final type). - crate item_type: Option, + pub(crate) item_type: Option, } #[derive(Clone, Debug)] -crate struct OpaqueTy { - crate bounds: Vec, - crate generics: Generics, +pub(crate) struct OpaqueTy { + pub(crate) bounds: Vec, + pub(crate) generics: Generics, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct BareFunctionDecl { - crate unsafety: hir::Unsafety, - crate generic_params: Vec, - crate decl: FnDecl, - crate abi: Abi, +pub(crate) struct BareFunctionDecl { + pub(crate) unsafety: hir::Unsafety, + pub(crate) generic_params: Vec, + pub(crate) decl: FnDecl, + pub(crate) abi: Abi, } #[derive(Clone, Debug)] -crate struct Static { - crate type_: Type, - crate mutability: Mutability, - crate expr: Option, +pub(crate) struct Static { + pub(crate) type_: Type, + pub(crate) mutability: Mutability, + pub(crate) expr: Option, } #[derive(Clone, PartialEq, Eq, Hash, Debug)] -crate struct Constant { - crate type_: Type, - crate kind: ConstantKind, +pub(crate) struct Constant { + pub(crate) type_: Type, + pub(crate) kind: ConstantKind, } #[derive(Clone, PartialEq, Eq, Hash, Debug)] -crate enum Term { +pub(crate) enum Term { Type(Type), Constant(Constant), } impl Term { - crate fn ty(&self) -> Option<&Type> { + pub(crate) fn ty(&self) -> Option<&Type> { if let Term::Type(ty) = self { Some(ty) } else { None } } } @@ -2263,7 +2263,7 @@ impl From for Term { } #[derive(Clone, PartialEq, Eq, Hash, Debug)] -crate enum ConstantKind { +pub(crate) enum ConstantKind { /// This is the wrapper around `ty::Const` for a non-local constant. Because it doesn't have a /// `BodyId`, we need to handle it on its own. /// @@ -2281,21 +2281,21 @@ crate enum ConstantKind { } impl Constant { - crate fn expr(&self, tcx: TyCtxt<'_>) -> String { + pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String { self.kind.expr(tcx) } - crate fn value(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn value(&self, tcx: TyCtxt<'_>) -> Option { self.kind.value(tcx) } - crate fn is_literal(&self, tcx: TyCtxt<'_>) -> bool { + pub(crate) fn is_literal(&self, tcx: TyCtxt<'_>) -> bool { self.kind.is_literal(tcx) } } impl ConstantKind { - crate fn expr(&self, tcx: TyCtxt<'_>) -> String { + pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String { match *self { ConstantKind::TyConst { ref expr } => expr.clone(), ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id), @@ -2305,7 +2305,7 @@ impl ConstantKind { } } - crate fn value(&self, tcx: TyCtxt<'_>) -> Option { + pub(crate) fn value(&self, tcx: TyCtxt<'_>) -> Option { match *self { ConstantKind::TyConst { .. } | ConstantKind::Anonymous { .. } => None, ConstantKind::Extern { def_id } | ConstantKind::Local { def_id, .. } => { @@ -2314,7 +2314,7 @@ impl ConstantKind { } } - crate fn is_literal(&self, tcx: TyCtxt<'_>) -> bool { + pub(crate) fn is_literal(&self, tcx: TyCtxt<'_>) -> bool { match *self { ConstantKind::TyConst { .. } => false, ConstantKind::Extern { def_id } => def_id.as_local().map_or(false, |def_id| { @@ -2328,18 +2328,18 @@ impl ConstantKind { } #[derive(Clone, Debug)] -crate struct Impl { - crate unsafety: hir::Unsafety, - crate generics: Generics, - crate trait_: Option, - crate for_: Type, - crate items: Vec, - crate polarity: ty::ImplPolarity, - crate kind: ImplKind, +pub(crate) struct Impl { + pub(crate) unsafety: hir::Unsafety, + pub(crate) generics: Generics, + pub(crate) trait_: Option, + pub(crate) for_: Type, + pub(crate) items: Vec, + pub(crate) polarity: ty::ImplPolarity, + pub(crate) kind: ImplKind, } impl Impl { - crate fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet { + pub(crate) fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet { self.trait_ .as_ref() .map(|t| t.def_id()) @@ -2349,22 +2349,22 @@ impl Impl { } #[derive(Clone, Debug)] -crate enum ImplKind { +pub(crate) enum ImplKind { Normal, Auto, Blanket(Box), } impl ImplKind { - crate fn is_auto(&self) -> bool { + pub(crate) fn is_auto(&self) -> bool { matches!(self, ImplKind::Auto) } - crate fn is_blanket(&self) -> bool { + pub(crate) fn is_blanket(&self) -> bool { matches!(self, ImplKind::Blanket(_)) } - crate fn as_blanket_ty(&self) -> Option<&Type> { + pub(crate) fn as_blanket_ty(&self) -> Option<&Type> { match self { ImplKind::Blanket(ty) => Some(ty), _ => None, @@ -2373,24 +2373,28 @@ impl ImplKind { } #[derive(Clone, Debug)] -crate struct Import { - crate kind: ImportKind, - crate source: ImportSource, - crate should_be_displayed: bool, +pub(crate) struct Import { + pub(crate) kind: ImportKind, + pub(crate) source: ImportSource, + pub(crate) should_be_displayed: bool, } impl Import { - crate fn new_simple(name: Symbol, source: ImportSource, should_be_displayed: bool) -> Self { + pub(crate) fn new_simple( + name: Symbol, + source: ImportSource, + should_be_displayed: bool, + ) -> Self { Self { kind: ImportKind::Simple(name), source, should_be_displayed } } - crate fn new_glob(source: ImportSource, should_be_displayed: bool) -> Self { + pub(crate) fn new_glob(source: ImportSource, should_be_displayed: bool) -> Self { Self { kind: ImportKind::Glob, source, should_be_displayed } } } #[derive(Clone, Debug)] -crate enum ImportKind { +pub(crate) enum ImportKind { // use source as str; Simple(Symbol), // use source::*; @@ -2398,38 +2402,38 @@ crate enum ImportKind { } #[derive(Clone, Debug)] -crate struct ImportSource { - crate path: Path, - crate did: Option, +pub(crate) struct ImportSource { + pub(crate) path: Path, + pub(crate) did: Option, } #[derive(Clone, Debug)] -crate struct Macro { - crate source: String, +pub(crate) struct Macro { + pub(crate) source: String, } #[derive(Clone, Debug)] -crate struct ProcMacro { - crate kind: MacroKind, - crate helpers: Vec, +pub(crate) struct ProcMacro { + pub(crate) kind: MacroKind, + pub(crate) helpers: Vec, } /// An type binding on an associated type (e.g., `A = Bar` in `Foo` or /// `A: Send + Sync` in `Foo`). #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct TypeBinding { - crate assoc: PathSegment, - crate kind: TypeBindingKind, +pub(crate) struct TypeBinding { + pub(crate) assoc: PathSegment, + pub(crate) kind: TypeBindingKind, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate enum TypeBindingKind { +pub(crate) enum TypeBindingKind { Equality { term: Term }, Constraint { bounds: Vec }, } impl TypeBinding { - crate fn term(&self) -> &Term { + pub(crate) fn term(&self) -> &Term { match self.kind { TypeBindingKind::Equality { ref term } => term, _ => panic!("expected equality type binding for parenthesized generic args"), @@ -2450,18 +2454,18 @@ impl TypeBinding { /// /// `public_fn`'s docs will show it as returning `Vec`, since `PrivAlias` is private. /// [`SubstParam`] is used to record that `T` should be mapped to `i32`. -crate enum SubstParam { +pub(crate) enum SubstParam { Type(Type), Lifetime(Lifetime), Constant(Constant), } impl SubstParam { - crate fn as_ty(&self) -> Option<&Type> { + pub(crate) fn as_ty(&self) -> Option<&Type> { if let Self::Type(ty) = self { Some(ty) } else { None } } - crate fn as_lt(&self) -> Option<&Lifetime> { + pub(crate) fn as_lt(&self) -> Option<&Lifetime> { if let Self::Lifetime(lt) = self { Some(lt) } else { None } } } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index c67b92df643..7a12ea0d5c2 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -25,7 +25,7 @@ use std::mem; #[cfg(test)] mod tests; -crate fn krate(cx: &mut DocContext<'_>) -> Crate { +pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate { let module = crate::visit_ast::RustdocVisitor::new(cx).visit(); for &cnum in cx.tcx.crates(()) { @@ -75,7 +75,7 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate { Crate { module, primitives, external_traits: cx.external_traits.clone() } } -crate fn substs_to_args( +pub(crate) fn substs_to_args( cx: &mut DocContext<'_>, substs: &[ty::subst::GenericArg<'_>], mut skip_first: bool, @@ -146,7 +146,7 @@ pub(super) fn external_path( } /// Remove the generic arguments from a path. -crate fn strip_path_generics(mut path: Path) -> Path { +pub(crate) fn strip_path_generics(mut path: Path) -> Path { for ps in path.segments.iter_mut() { ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: ThinVec::new() } } @@ -154,7 +154,7 @@ crate fn strip_path_generics(mut path: Path) -> Path { path } -crate fn qpath_to_string(p: &hir::QPath<'_>) -> String { +pub(crate) fn qpath_to_string(p: &hir::QPath<'_>) -> String { let segments = match *p { hir::QPath::Resolved(_, path) => &path.segments, hir::QPath::TypeRelative(_, segment) => return segment.ident.to_string(), @@ -173,7 +173,11 @@ crate fn qpath_to_string(p: &hir::QPath<'_>) -> String { s } -crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret: &mut Vec) { +pub(crate) fn build_deref_target_impls( + cx: &mut DocContext<'_>, + items: &[Item], + ret: &mut Vec, +) { let tcx = cx.tcx; for item in items { @@ -196,7 +200,7 @@ crate fn build_deref_target_impls(cx: &mut DocContext<'_>, items: &[Item], ret: } } -crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { +pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { use rustc_hir::*; debug!("trying to get a name from pattern: {:?}", p); @@ -229,7 +233,7 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { }) } -crate fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { +pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { match n.val() { ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => { let mut s = if let Some(def) = def.as_local() { @@ -259,7 +263,7 @@ crate fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { } } -crate fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option { +pub(crate) fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option { tcx.const_eval_poly(def_id).ok().and_then(|val| { let ty = tcx.type_of(def_id); match (val, ty.kind()) { @@ -323,7 +327,7 @@ fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: ty::Const<'_>) -> S } } -crate fn is_literal_expr(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { +pub(crate) fn is_literal_expr(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { if let hir::Node::Expr(expr) = tcx.hir().get(hir_id) { if let hir::ExprKind::Lit(_) = &expr.kind { return true; @@ -339,7 +343,7 @@ crate fn is_literal_expr(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool { false } -crate fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String { +pub(crate) fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String { let hir = tcx.hir(); let value = &hir.body(body).value; @@ -353,7 +357,7 @@ crate fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String { } /// Given a type Path, resolve it to a Type using the TyCtxt -crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type { +pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type { debug!("resolve_type({:?})", path); match path.res { @@ -367,7 +371,7 @@ crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type { } } -crate fn get_auto_trait_and_blanket_impls( +pub(crate) fn get_auto_trait_and_blanket_impls( cx: &mut DocContext<'_>, item_def_id: DefId, ) -> impl Iterator { @@ -389,7 +393,7 @@ crate fn get_auto_trait_and_blanket_impls( /// This is later used by [`href()`] to determine the HTML link for the item. /// /// [`href()`]: crate::html::format::href -crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { +pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { use DefKind::*; debug!("register_res({:?})", res); @@ -428,14 +432,14 @@ crate fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { did } -crate fn resolve_use_source(cx: &mut DocContext<'_>, path: Path) -> ImportSource { +pub(crate) fn resolve_use_source(cx: &mut DocContext<'_>, path: Path) -> ImportSource { ImportSource { did: if path.res.opt_def_id().is_none() { None } else { Some(register_res(cx, path.res)) }, path, } } -crate fn enter_impl_trait(cx: &mut DocContext<'_>, f: F) -> R +pub(crate) fn enter_impl_trait(cx: &mut DocContext<'_>, f: F) -> R where F: FnOnce(&mut DocContext<'_>) -> R, { @@ -447,7 +451,7 @@ where } /// Find the nearest parent module of a [`DefId`]. -crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option { +pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option { if def_id.is_top_level_module() { // The crate root has no parent. Use it as the root instead. Some(def_id) @@ -474,7 +478,7 @@ crate fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option, did: DefId, flag: Symbol) -> bool { +pub(crate) fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool { tcx.get_attrs(did, sym::doc).any(|attr| { attr.meta_item_list().map_or(false, |l| rustc_attr::list_contains_name(&l, flag)) }) @@ -484,7 +488,7 @@ crate fn has_doc_flag(tcx: TyCtxt<'_>, did: DefId, flag: Symbol) -> bool { /// so that the channel is consistent. /// /// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable. -crate const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL"); +pub(crate) const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL"); /// Render a sequence of macro arms in a format suitable for displaying to the user /// as part of an item declaration. diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 1ff2c8191e5..b934a1a59d7 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -31,7 +31,7 @@ use crate::scrape_examples::{AllCallLocations, ScrapeExamplesOptions}; use crate::theme; #[derive(Clone, Copy, PartialEq, Eq, Debug)] -crate enum OutputFormat { +pub(crate) enum OutputFormat { Json, Html, } @@ -43,7 +43,7 @@ impl Default for OutputFormat { } impl OutputFormat { - crate fn is_json(&self) -> bool { + pub(crate) fn is_json(&self) -> bool { matches!(self, OutputFormat::Json) } } @@ -62,100 +62,100 @@ impl TryFrom<&str> for OutputFormat { /// Configuration options for rustdoc. #[derive(Clone)] -crate struct Options { +pub(crate) struct Options { // Basic options / Options passed directly to rustc /// The crate root or Markdown file to load. - crate input: PathBuf, + pub(crate) input: PathBuf, /// The name of the crate being documented. - crate crate_name: Option, + pub(crate) crate_name: Option, /// Whether or not this is a proc-macro crate - crate proc_macro_crate: bool, + pub(crate) proc_macro_crate: bool, /// How to format errors and warnings. - crate error_format: ErrorOutputType, + pub(crate) error_format: ErrorOutputType, /// Library search paths to hand to the compiler. - crate libs: Vec, + pub(crate) libs: Vec, /// Library search paths strings to hand to the compiler. - crate lib_strs: Vec, + pub(crate) lib_strs: Vec, /// The list of external crates to link against. - crate externs: Externs, + pub(crate) externs: Externs, /// The list of external crates strings to link against. - crate extern_strs: Vec, + pub(crate) extern_strs: Vec, /// List of `cfg` flags to hand to the compiler. Always includes `rustdoc`. - crate cfgs: Vec, + pub(crate) cfgs: Vec, /// List of check cfg flags to hand to the compiler. - crate check_cfgs: Vec, + pub(crate) check_cfgs: Vec, /// Codegen options to hand to the compiler. - crate codegen_options: CodegenOptions, + pub(crate) codegen_options: CodegenOptions, /// Codegen options strings to hand to the compiler. - crate codegen_options_strs: Vec, + pub(crate) codegen_options_strs: Vec, /// Debugging (`-Z`) options to pass to the compiler. - crate debugging_opts: DebuggingOptions, + pub(crate) debugging_opts: DebuggingOptions, /// Debugging (`-Z`) options strings to pass to the compiler. - crate debugging_opts_strs: Vec, + pub(crate) debugging_opts_strs: Vec, /// The target used to compile the crate against. - crate target: TargetTriple, + pub(crate) target: TargetTriple, /// Edition used when reading the crate. Defaults to "2015". Also used by default when /// compiling doctests from the crate. - crate edition: Edition, + pub(crate) edition: Edition, /// The path to the sysroot. Used during the compilation process. - crate maybe_sysroot: Option, + pub(crate) maybe_sysroot: Option, /// Lint information passed over the command-line. - crate lint_opts: Vec<(String, Level)>, + pub(crate) lint_opts: Vec<(String, Level)>, /// Whether to ask rustc to describe the lints it knows. - crate describe_lints: bool, + pub(crate) describe_lints: bool, /// What level to cap lints at. - crate lint_cap: Option, + pub(crate) lint_cap: Option, // Options specific to running doctests /// Whether we should run doctests instead of generating docs. - crate should_test: bool, + pub(crate) should_test: bool, /// List of arguments to pass to the test harness, if running tests. - crate test_args: Vec, + pub(crate) test_args: Vec, /// The working directory in which to run tests. - crate test_run_directory: Option, + pub(crate) test_run_directory: Option, /// Optional path to persist the doctest executables to, defaults to a /// temporary directory if not set. - crate persist_doctests: Option, + pub(crate) persist_doctests: Option, /// Runtool to run doctests with - crate runtool: Option, + pub(crate) runtool: Option, /// Arguments to pass to the runtool - crate runtool_args: Vec, + pub(crate) runtool_args: Vec, /// Whether to allow ignoring doctests on a per-target basis /// For example, using ignore-foo to ignore running the doctest on any target that /// contains "foo" as a substring - crate enable_per_target_ignores: bool, + pub(crate) enable_per_target_ignores: bool, /// Do not run doctests, compile them if should_test is active. - crate no_run: bool, + pub(crate) no_run: bool, /// The path to a rustc-like binary to build tests with. If not set, we /// default to loading from `$sysroot/bin/rustc`. - crate test_builder: Option, + pub(crate) test_builder: Option, // Options that affect the documentation process /// Whether to run the `calculate-doc-coverage` pass, which counts the number of public items /// with and without documentation. - crate show_coverage: bool, + pub(crate) show_coverage: bool, // Options that alter generated documentation pages /// Crate version to note on the sidebar of generated docs. - crate crate_version: Option, + pub(crate) crate_version: Option, /// Collected options specific to outputting final pages. - crate render_options: RenderOptions, + pub(crate) render_options: RenderOptions, /// The format that we output when rendering. /// /// Currently used only for the `--show-coverage` option. - crate output_format: OutputFormat, + pub(crate) output_format: OutputFormat, /// If this option is set to `true`, rustdoc will only run checks and not generate /// documentation. - crate run_check: bool, + pub(crate) run_check: bool, /// Whether doctests should emit unused externs - crate json_unused_externs: JsonUnusedExterns, + pub(crate) json_unused_externs: JsonUnusedExterns, /// Whether to skip capturing stdout and stderr of tests. - crate nocapture: bool, + pub(crate) nocapture: bool, /// Configuration for scraping examples from the current crate. If this option is Some(..) then /// the compiler will scrape examples and not generate documentation. - crate scrape_examples_options: Option, + pub(crate) scrape_examples_options: Option, } impl fmt::Debug for Options { @@ -205,83 +205,83 @@ impl fmt::Debug for Options { /// Configuration options for the HTML page-creation process. #[derive(Clone, Debug)] -crate struct RenderOptions { +pub(crate) struct RenderOptions { /// Output directory to generate docs into. Defaults to `doc`. - crate output: PathBuf, + pub(crate) output: PathBuf, /// External files to insert into generated pages. - crate external_html: ExternalHtml, + pub(crate) external_html: ExternalHtml, /// A pre-populated `IdMap` with the default headings and any headings added by Markdown files /// processed by `external_html`. - crate id_map: IdMap, + pub(crate) id_map: IdMap, /// If present, playground URL to use in the "Run" button added to code samples. /// /// Be aware: This option can come both from the CLI and from crate attributes! - crate playground_url: Option, + pub(crate) playground_url: Option, /// Whether to sort modules alphabetically on a module page instead of using declaration order. /// `true` by default. // // FIXME(misdreavus): the flag name is `--sort-modules-by-appearance` but the meaning is // inverted once read. - crate sort_modules_alphabetically: bool, + pub(crate) sort_modules_alphabetically: bool, /// List of themes to extend the docs with. Original argument name is included to assist in /// displaying errors if it fails a theme check. - crate themes: Vec, + pub(crate) themes: Vec, /// If present, CSS file that contains rules to add to the default CSS. - crate extension_css: Option, + pub(crate) extension_css: Option, /// A map of crate names to the URL to use instead of querying the crate's `html_root_url`. - crate extern_html_root_urls: BTreeMap, + pub(crate) extern_html_root_urls: BTreeMap, /// Whether to give precedence to `html_root_url` or `--exten-html-root-url`. - crate extern_html_root_takes_precedence: bool, + pub(crate) extern_html_root_takes_precedence: bool, /// A map of the default settings (values are as for DOM storage API). Keys should lack the /// `rustdoc-` prefix. - crate default_settings: FxHashMap, + pub(crate) default_settings: FxHashMap, /// If present, suffix added to CSS/JavaScript files when referencing them in generated pages. - crate resource_suffix: String, + pub(crate) resource_suffix: String, /// Whether to run the static CSS/JavaScript through a minifier when outputting them. `true` by /// default. // // FIXME(misdreavus): the flag name is `--disable-minification` but the meaning is inverted // once read. - crate enable_minification: bool, + pub(crate) enable_minification: bool, /// Whether to create an index page in the root of the output directory. If this is true but /// `enable_index_page` is None, generate a static listing of crates instead. - crate enable_index_page: bool, + pub(crate) enable_index_page: bool, /// A file to use as the index page at the root of the output directory. Overrides /// `enable_index_page` to be true if set. - crate index_page: Option, + pub(crate) index_page: Option, /// An optional path to use as the location of static files. If not set, uses combinations of /// `../` to reach the documentation root. - crate static_root_path: Option, + pub(crate) static_root_path: Option, // Options specific to reading standalone Markdown files /// Whether to generate a table of contents on the output file when reading a standalone /// Markdown file. - crate markdown_no_toc: bool, + pub(crate) markdown_no_toc: bool, /// Additional CSS files to link in pages generated from standalone Markdown files. - crate markdown_css: Vec, + pub(crate) markdown_css: Vec, /// If present, playground URL to use in the "Run" button added to code samples generated from /// standalone Markdown files. If not present, `playground_url` is used. - crate markdown_playground_url: Option, + pub(crate) markdown_playground_url: Option, /// Document items that have lower than `pub` visibility. - crate document_private: bool, + pub(crate) document_private: bool, /// Document items that have `doc(hidden)`. - crate document_hidden: bool, + pub(crate) document_hidden: bool, /// If `true`, generate a JSON file in the crate folder instead of HTML redirection files. - crate generate_redirect_map: bool, + pub(crate) generate_redirect_map: bool, /// Show the memory layout of types in the docs. - crate show_type_layout: bool, - crate unstable_features: rustc_feature::UnstableFeatures, - crate emit: Vec, + pub(crate) show_type_layout: bool, + pub(crate) unstable_features: rustc_feature::UnstableFeatures, + pub(crate) emit: Vec, /// If `true`, HTML source pages will generate links for items to their definition. - crate generate_link_to_definition: bool, + pub(crate) generate_link_to_definition: bool, /// Set of function-call locations to include as examples - crate call_locations: AllCallLocations, + pub(crate) call_locations: AllCallLocations, /// If `true`, Context::init will not emit shared files. - crate no_emit_shared: bool, + pub(crate) no_emit_shared: bool, } #[derive(Copy, Clone, Debug, PartialEq, Eq)] -crate enum EmitType { +pub(crate) enum EmitType { Unversioned, Toolchain, InvocationSpecific, @@ -302,7 +302,7 @@ impl FromStr for EmitType { } impl RenderOptions { - crate fn should_emit_crate(&self) -> bool { + pub(crate) fn should_emit_crate(&self) -> bool { self.emit.is_empty() || self.emit.contains(&EmitType::InvocationSpecific) } } @@ -310,7 +310,7 @@ impl RenderOptions { impl Options { /// Parses the given command-line for options. If an error message or other early-return has /// been printed, returns `Err` with the exit code. - crate fn from_matches(matches: &getopts::Matches) -> Result { + pub(crate) fn from_matches(matches: &getopts::Matches) -> Result { // Check for unstable options. nightly_options::check_nightly_options(matches, &opts()); @@ -745,7 +745,7 @@ impl Options { } /// Returns `true` if the file given as `self.input` is a Markdown file. - crate fn markdown_input(&self) -> bool { + pub(crate) fn markdown_input(&self) -> bool { self.input.extension().map_or(false, |e| e == "md" || e == "markdown") } } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 17644aeed85..53281bfde2e 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -32,70 +32,74 @@ use crate::formats::cache::Cache; use crate::passes::collect_intra_doc_links::PreprocessedMarkdownLink; use crate::passes::{self, Condition::*}; -crate use rustc_session::config::{DebuggingOptions, Input, Options}; +pub(crate) use rustc_session::config::{DebuggingOptions, Input, Options}; -crate struct ResolverCaches { - crate markdown_links: Option>>, - crate doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option>>, +pub(crate) struct ResolverCaches { + pub(crate) markdown_links: Option>>, + pub(crate) doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option>>, /// Traits in scope for a given module. /// See `collect_intra_doc_links::traits_implemented_by` for more details. - crate traits_in_scope: DefIdMap>, - crate all_traits: Option>, - crate all_trait_impls: Option>, - crate all_macro_rules: FxHashMap>, + pub(crate) traits_in_scope: DefIdMap>, + pub(crate) all_traits: Option>, + pub(crate) all_trait_impls: Option>, + pub(crate) all_macro_rules: FxHashMap>, } -crate struct DocContext<'tcx> { - crate tcx: TyCtxt<'tcx>, +pub(crate) struct DocContext<'tcx> { + pub(crate) tcx: TyCtxt<'tcx>, /// Name resolver. Used for intra-doc links. /// /// The `Rc>` wrapping is needed because that is what's returned by /// [`rustc_interface::Queries::expansion()`]. // FIXME: see if we can get rid of this RefCell somehow - crate resolver: Rc>, - crate resolver_caches: ResolverCaches, + pub(crate) resolver: Rc>, + pub(crate) resolver_caches: ResolverCaches, /// Used for normalization. /// /// Most of this logic is copied from rustc_lint::late. - crate param_env: ParamEnv<'tcx>, + pub(crate) param_env: ParamEnv<'tcx>, /// Later on moved through `clean::Crate` into `cache` - crate external_traits: Rc>>, + pub(crate) external_traits: Rc>>, /// Used while populating `external_traits` to ensure we don't process the same trait twice at /// the same time. - crate active_extern_traits: FxHashSet, + pub(crate) active_extern_traits: FxHashSet, // The current set of parameter substitutions, // for expanding type aliases at the HIR level: /// Table `DefId` of type, lifetime, or const parameter -> substituted type, lifetime, or const - crate substs: FxHashMap, + pub(crate) substs: FxHashMap, /// Table synthetic type parameter for `impl Trait` in argument position -> bounds - crate impl_trait_bounds: FxHashMap>, + pub(crate) impl_trait_bounds: FxHashMap>, /// Auto-trait or blanket impls processed so far, as `(self_ty, trait_def_id)`. // FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set. - crate generated_synthetics: FxHashSet<(Ty<'tcx>, DefId)>, - crate auto_traits: Vec, + pub(crate) generated_synthetics: FxHashSet<(Ty<'tcx>, DefId)>, + pub(crate) auto_traits: Vec, /// The options given to rustdoc that could be relevant to a pass. - crate render_options: RenderOptions, + pub(crate) render_options: RenderOptions, /// This same cache is used throughout rustdoc, including in [`crate::html::render`]. - crate cache: Cache, + pub(crate) cache: Cache, /// Used by [`clean::inline`] to tell if an item has already been inlined. - crate inlined: FxHashSet, + pub(crate) inlined: FxHashSet, /// Used by `calculate_doc_coverage`. - crate output_format: OutputFormat, + pub(crate) output_format: OutputFormat, } impl<'tcx> DocContext<'tcx> { - crate fn sess(&self) -> &'tcx Session { + pub(crate) fn sess(&self) -> &'tcx Session { self.tcx.sess } - crate fn with_param_env T>(&mut self, def_id: DefId, f: F) -> T { + pub(crate) fn with_param_env T>( + &mut self, + def_id: DefId, + f: F, + ) -> T { let old_param_env = mem::replace(&mut self.param_env, self.tcx.param_env(def_id)); let ret = f(self); self.param_env = old_param_env; ret } - crate fn enter_resolver(&self, f: F) -> R + pub(crate) fn enter_resolver(&self, f: F) -> R where F: FnOnce(&mut resolve::Resolver<'_>) -> R, { @@ -104,7 +108,11 @@ impl<'tcx> DocContext<'tcx> { /// Call the closure with the given parameters set as /// the substitutions for a type alias' RHS. - crate fn enter_alias(&mut self, substs: FxHashMap, f: F) -> R + pub(crate) fn enter_alias( + &mut self, + substs: FxHashMap, + f: F, + ) -> R where F: FnOnce(&mut Self) -> R, { @@ -116,7 +124,7 @@ impl<'tcx> DocContext<'tcx> { /// Like `hir().local_def_id_to_hir_id()`, but skips calling it on fake DefIds. /// (This avoids a slice-index-out-of-bounds panic.) - crate fn as_local_hir_id(tcx: TyCtxt<'_>, item_id: ItemId) -> Option { + pub(crate) fn as_local_hir_id(tcx: TyCtxt<'_>, item_id: ItemId) -> Option { match item_id { ItemId::DefId(real_id) => { real_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) @@ -126,13 +134,13 @@ impl<'tcx> DocContext<'tcx> { } } - crate fn with_all_traits(&mut self, f: impl FnOnce(&mut Self, &[DefId])) { + pub(crate) fn with_all_traits(&mut self, f: impl FnOnce(&mut Self, &[DefId])) { let all_traits = self.resolver_caches.all_traits.take(); f(self, all_traits.as_ref().expect("`all_traits` are already borrowed")); self.resolver_caches.all_traits = all_traits; } - crate fn with_all_trait_impls(&mut self, f: impl FnOnce(&mut Self, &[DefId])) { + pub(crate) fn with_all_trait_impls(&mut self, f: impl FnOnce(&mut Self, &[DefId])) { let all_trait_impls = self.resolver_caches.all_trait_impls.take(); f(self, all_trait_impls.as_ref().expect("`all_trait_impls` are already borrowed")); self.resolver_caches.all_trait_impls = all_trait_impls; @@ -143,7 +151,7 @@ impl<'tcx> DocContext<'tcx> { /// /// If the given `error_format` is `ErrorOutputType::Json` and no `SourceMap` is given, a new one /// will be created for the handler. -crate fn new_handler( +pub(crate) fn new_handler( error_format: ErrorOutputType, source_map: Option>, debugging_opts: &DebuggingOptions, @@ -194,7 +202,7 @@ crate fn new_handler( } /// Parse, resolve, and typecheck the given crate. -crate fn create_config( +pub(crate) fn create_config( RustdocOptions { input, crate_name, @@ -311,7 +319,7 @@ crate fn create_config( } } -crate fn run_global_ctxt( +pub(crate) fn run_global_ctxt( tcx: TyCtxt<'_>, resolver: Rc>, resolver_caches: ResolverCaches, @@ -535,7 +543,7 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> { /// `DefId` or parameter index (`ty::ParamTy.index`) of a synthetic type parameter /// for `impl Trait` in argument position. #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -crate enum ImplTraitParam { +pub(crate) enum ImplTraitParam { DefId(DefId), ParamIndex(u32), } diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index 8dd8eb23df2..be066bdafa1 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -15,38 +15,38 @@ use std::path::{Path, PathBuf}; use std::string::ToString; use std::sync::mpsc::Sender; -crate trait PathError { +pub(crate) trait PathError { fn new>(e: S, path: P) -> Self where S: ToString + Sized; } -crate struct DocFS { +pub(crate) struct DocFS { sync_only: bool, errors: Option>, } impl DocFS { - crate fn new(errors: Sender) -> DocFS { + pub(crate) fn new(errors: Sender) -> DocFS { DocFS { sync_only: false, errors: Some(errors) } } - crate fn set_sync_only(&mut self, sync_only: bool) { + pub(crate) fn set_sync_only(&mut self, sync_only: bool) { self.sync_only = sync_only; } - crate fn close(&mut self) { + pub(crate) fn close(&mut self) { self.errors = None; } - crate fn create_dir_all>(&self, path: P) -> io::Result<()> { + pub(crate) fn create_dir_all>(&self, path: P) -> io::Result<()> { // For now, dir creation isn't a huge time consideration, do it // synchronously, which avoids needing ordering between write() actions // and directory creation. fs::create_dir_all(path) } - crate fn write( + pub(crate) fn write( &self, path: PathBuf, contents: impl 'static + Send + AsRef<[u8]>, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 93ccf60a1de..3005bd9e4a4 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -40,14 +40,14 @@ use crate::passes::span_of_attrs; /// Options that apply to all doctests in a crate or Markdown file (for `rustdoc foo.md`). #[derive(Clone, Default)] -crate struct GlobalTestOptions { +pub(crate) struct GlobalTestOptions { /// Whether to disable the default `extern crate my_crate;` when creating doctests. - crate no_crate_inject: bool, + pub(crate) no_crate_inject: bool, /// Additional crate-level attributes to add to doctests. - crate attrs: Vec, + pub(crate) attrs: Vec, } -crate fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { +pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { let input = config::Input::File(options.input.clone()); let invalid_codeblock_attributes_name = crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name; @@ -207,7 +207,11 @@ crate fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { Ok(()) } -crate fn run_tests(mut test_args: Vec, nocapture: bool, tests: Vec) { +pub(crate) fn run_tests( + mut test_args: Vec, + nocapture: bool, + tests: Vec, +) { test_args.insert(0, "rustdoctest".to_string()); if nocapture { test_args.push("--nocapture".to_string()); @@ -488,7 +492,7 @@ fn run_test( /// Transforms a test into code that can be compiled into a Rust binary, and returns the number of /// lines before the test code begins as well as if the output stream supports colors or not. -crate fn make_test( +pub(crate) fn make_test( s: &str, crate_name: Option<&str>, dont_insert_main: bool, @@ -840,7 +844,7 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) { (before, after, crates) } -crate trait Tester { +pub(crate) trait Tester { fn add_test(&mut self, test: String, config: LangString, line: usize); fn get_line(&self) -> usize { 0 @@ -848,8 +852,8 @@ crate trait Tester { fn register_header(&mut self, _name: &str, _level: u32) {} } -crate struct Collector { - crate tests: Vec, +pub(crate) struct Collector { + pub(crate) tests: Vec, // The name of the test displayed to the user, separated by `::`. // @@ -887,7 +891,7 @@ crate struct Collector { } impl Collector { - crate fn new( + pub(crate) fn new( crate_name: Symbol, rustdoc_options: RustdocOptions, use_headers: bool, @@ -922,7 +926,7 @@ impl Collector { format!("{} - {}(line {})", filename.prefer_local(), item_path, line) } - crate fn set_position(&mut self, position: Span) { + pub(crate) fn set_position(&mut self, position: Span) { self.position = position; } diff --git a/src/librustdoc/error.rs b/src/librustdoc/error.rs index 8eadbf63f33..6ed7eab1aba 100644 --- a/src/librustdoc/error.rs +++ b/src/librustdoc/error.rs @@ -5,9 +5,9 @@ use std::path::{Path, PathBuf}; use crate::docfs::PathError; #[derive(Debug)] -crate struct Error { - crate file: PathBuf, - crate error: String, +pub(crate) struct Error { + pub(crate) file: PathBuf, + pub(crate) error: String, } impl error::Error for Error {} diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 4df48cef593..37fd909c933 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -7,20 +7,20 @@ use std::str; use serde::Serialize; #[derive(Clone, Debug, Serialize)] -crate struct ExternalHtml { +pub(crate) struct ExternalHtml { /// Content that will be included inline in the `` section of a /// rendered Markdown file or generated documentation - crate in_header: String, + pub(crate) in_header: String, /// Content that will be included inline between `` and the content of /// a rendered Markdown file or generated documentation - crate before_content: String, + pub(crate) before_content: String, /// Content that will be included inline between the content and `` of /// a rendered Markdown file or generated documentation - crate after_content: String, + pub(crate) after_content: String, } impl ExternalHtml { - crate fn load( + pub(crate) fn load( in_header: &[String], before_content: &[String], after_content: &[String], @@ -70,12 +70,12 @@ impl ExternalHtml { } } -crate enum LoadStringError { +pub(crate) enum LoadStringError { ReadFail, BadUtf8, } -crate fn load_string>( +pub(crate) fn load_string>( file_path: P, diag: &rustc_errors::Handler, ) -> Result { diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index 95adc4426b5..f3e075bc12a 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -1,13 +1,13 @@ use crate::clean::*; -crate fn strip_item(mut item: Item) -> Item { +pub(crate) fn strip_item(mut item: Item) -> Item { if !matches!(*item.kind, StrippedItem(..)) { item.kind = box StrippedItem(item.kind); } item } -crate trait DocFolder: Sized { +pub(crate) trait DocFolder: Sized { fn fold_item(&mut self, item: Item) -> Option { Some(self.fold_item_recur(item)) } diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 28648e25d90..f5c0b5e6762 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -26,25 +26,25 @@ use crate::html::render::IndexItem; /// to `Send` so it may be stored in an `Arc` instance and shared among the various /// rendering threads. #[derive(Default)] -crate struct Cache { +pub(crate) struct Cache { /// Maps a type ID to all known implementations for that type. This is only /// recognized for intra-crate [`clean::Type::Path`]s, and is used to print /// out extra documentation on the page of an enum/struct. /// /// The values of the map are a list of implementations and documentation /// found on that implementation. - crate impls: FxHashMap>, + pub(crate) impls: FxHashMap>, /// Maintains a mapping of local crate `DefId`s to the fully qualified name /// and "short type description" of that node. This is used when generating /// URLs when a type is being linked to. External paths are not located in /// this map because the `External` type itself has all the information /// necessary. - crate paths: FxHashMap, ItemType)>, + pub(crate) paths: FxHashMap, ItemType)>, /// Similar to `paths`, but only holds external paths. This is only used for /// generating explicit hyperlinks to other crates. - crate external_paths: FxHashMap, ItemType)>, + pub(crate) external_paths: FxHashMap, ItemType)>, /// Maps local `DefId`s of exported types to fully qualified paths. /// Unlike 'paths', this mapping ignores any renames that occur @@ -56,41 +56,41 @@ crate struct Cache { /// to the path used if the corresponding type is inlined. By /// doing this, we can detect duplicate impls on a trait page, and only display /// the impl for the inlined type. - crate exact_paths: FxHashMap>, + pub(crate) exact_paths: FxHashMap>, /// This map contains information about all known traits of this crate. /// Implementations of a crate should inherit the documentation of the /// parent trait if no extra documentation is specified, and default methods /// should show up in documentation about trait implementations. - crate traits: FxHashMap, + pub(crate) traits: FxHashMap, /// When rendering traits, it's often useful to be able to list all /// implementors of the trait, and this mapping is exactly, that: a mapping /// of trait ids to the list of known implementors of the trait - crate implementors: FxHashMap>, + pub(crate) implementors: FxHashMap>, /// Cache of where external crate documentation can be found. - crate extern_locations: FxHashMap, + pub(crate) extern_locations: FxHashMap, /// Cache of where documentation for primitives can be found. - crate primitive_locations: FxHashMap, + pub(crate) primitive_locations: FxHashMap, // Note that external items for which `doc(hidden)` applies to are shown as // non-reachable while local items aren't. This is because we're reusing // the access levels from the privacy check pass. - crate access_levels: AccessLevels, + pub(crate) access_levels: AccessLevels, /// The version of the crate being documented, if given from the `--crate-version` flag. - crate crate_version: Option, + pub(crate) crate_version: Option, /// Whether to document private items. /// This is stored in `Cache` so it doesn't need to be passed through all rustdoc functions. - crate document_private: bool, + pub(crate) document_private: bool, /// Crates marked with [`#[doc(masked)]`][doc_masked]. /// /// [doc_masked]: https://doc.rust-lang.org/nightly/unstable-book/language-features/doc-masked.html - crate masked_crates: FxHashSet, + pub(crate) masked_crates: FxHashSet, // Private fields only used when initially crawling a crate to build a cache stack: Vec, @@ -98,14 +98,14 @@ crate struct Cache { parent_is_trait_impl: bool, stripped_mod: bool, - crate search_index: Vec, + pub(crate) search_index: Vec, // In rare case where a structure is defined in one module but implemented // in another, if the implementing module is parsed before defining module, // then the fully qualified name of the structure isn't presented in `paths` // yet when its implementation methods are being indexed. Caches such methods // and their parent id here and indexes them at the end of crate parsing. - crate orphan_impl_items: Vec<(DefId, clean::Item)>, + pub(crate) orphan_impl_items: Vec<(DefId, clean::Item)>, // Similarly to `orphan_impl_items`, sometimes trait impls are picked up // even though the trait itself is not exported. This can happen if a trait @@ -119,9 +119,9 @@ crate struct Cache { /// All intra-doc links resolved so far. /// /// Links are indexed by the DefId of the item they document. - crate intra_doc_links: FxHashMap>, + pub(crate) intra_doc_links: FxHashMap>, /// Cfg that have been hidden via #![doc(cfg_hide(...))] - crate hidden_cfg: FxHashSet, + pub(crate) hidden_cfg: FxHashSet, } /// This struct is used to wrap the `cache` and `tcx` in order to run `DocFolder`. @@ -133,13 +133,13 @@ struct CacheBuilder<'a, 'tcx> { } impl Cache { - crate fn new(access_levels: AccessLevels, document_private: bool) -> Self { + pub(crate) fn new(access_levels: AccessLevels, document_private: bool) -> Self { Cache { access_levels, document_private, ..Cache::default() } } /// Populates the `Cache` with more data. The returned `Crate` will be missing some data that was /// in `krate` due to the data being moved into the `Cache`. - crate fn populate(cx: &mut DocContext<'_>, mut krate: clean::Crate) -> clean::Crate { + pub(crate) fn populate(cx: &mut DocContext<'_>, mut krate: clean::Crate) -> clean::Crate { let tcx = cx.tcx; // Crawl the crate to build various caches used for the output diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index fb4afb769ad..eca5501cd33 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -21,7 +21,7 @@ use crate::clean; /// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an /// ordering based on a helper function inside `item_module`, in the same file. #[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)] -crate enum ItemType { +pub(crate) enum ItemType { Module = 0, ExternCrate = 1, Import = 2, @@ -147,7 +147,7 @@ impl From for ItemType { } impl ItemType { - crate fn as_str(&self) -> &'static str { + pub(crate) fn as_str(&self) -> &'static str { match *self { ItemType::Module => "mod", ItemType::ExternCrate => "externcrate", diff --git a/src/librustdoc/formats/mod.rs b/src/librustdoc/formats/mod.rs index 3e36318eb71..2367bde0167 100644 --- a/src/librustdoc/formats/mod.rs +++ b/src/librustdoc/formats/mod.rs @@ -1,16 +1,16 @@ -crate mod cache; -crate mod item_type; -crate mod renderer; +pub(crate) mod cache; +pub(crate) mod item_type; +pub(crate) mod renderer; use rustc_hir::def_id::DefId; -crate use renderer::{run_format, FormatRenderer}; +pub(crate) use renderer::{run_format, FormatRenderer}; use crate::clean::{self, ItemId}; /// Specifies whether rendering directly implemented trait items or ones from a certain Deref /// impl. -crate enum AssocItemRender<'a> { +pub(crate) enum AssocItemRender<'a> { All, DerefFor { trait_: &'a clean::Path, type_: &'a clean::Type, deref_mut_: bool }, } @@ -18,26 +18,26 @@ crate enum AssocItemRender<'a> { /// For different handling of associated items from the Deref target of a type rather than the type /// itself. #[derive(Copy, Clone, PartialEq)] -crate enum RenderMode { +pub(crate) enum RenderMode { Normal, ForDeref { mut_: bool }, } /// Metadata about implementations for a type or trait. #[derive(Clone, Debug)] -crate struct Impl { - crate impl_item: clean::Item, +pub(crate) struct Impl { + pub(crate) impl_item: clean::Item, } impl Impl { - crate fn inner_impl(&self) -> &clean::Impl { + pub(crate) fn inner_impl(&self) -> &clean::Impl { match *self.impl_item.kind { clean::ImplItem(ref impl_) => impl_, _ => panic!("non-impl item found in impl"), } } - crate fn trait_did(&self) -> Option { + pub(crate) fn trait_did(&self) -> Option { self.inner_impl().trait_.as_ref().map(|t| t.def_id()) } @@ -47,7 +47,7 @@ impl Impl { /// with blanket impls). /// /// It panics if `self` is a `ItemId::Primitive`. - crate fn def_id(&self) -> DefId { + pub(crate) fn def_id(&self) -> DefId { match self.impl_item.item_id { ItemId::Blanket { impl_id, .. } => impl_id, ItemId::Auto { trait_, .. } => trait_, diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index 2403ff4ebaa..62ba984acc9 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -9,7 +9,7 @@ use crate::formats::cache::Cache; /// Allows for different backends to rustdoc to be used with the `run_format()` function. Each /// backend renderer has hooks for initialization, documenting an item, entering and exiting a /// module, and cleanup/finalizing output. -crate trait FormatRenderer<'tcx>: Sized { +pub(crate) trait FormatRenderer<'tcx>: Sized { /// Gives a description of the renderer. Used for performance profiling. fn descr() -> &'static str; @@ -48,7 +48,7 @@ crate trait FormatRenderer<'tcx>: Sized { } /// Main method for rendering a crate. -crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( +pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>( krate: clean::Crate, options: RenderOptions, cache: Cache, diff --git a/src/librustdoc/html/escape.rs b/src/librustdoc/html/escape.rs index ce44722a532..4a19d0a44c3 100644 --- a/src/librustdoc/html/escape.rs +++ b/src/librustdoc/html/escape.rs @@ -7,7 +7,7 @@ use std::fmt; /// Wrapper struct which will emit the HTML-escaped version of the contained /// string when passed to a format string. -crate struct Escape<'a>(pub &'a str); +pub(crate) struct Escape<'a>(pub &'a str); impl<'a> fmt::Display for Escape<'a> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 528eb6410cb..3c492f51786 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -33,7 +33,7 @@ use crate::html::render::Context; use super::url_parts_builder::estimate_item_path_byte_length; use super::url_parts_builder::UrlPartsBuilder; -crate trait Print { +pub(crate) trait Print { fn print(self, buffer: &mut Buffer); } @@ -59,7 +59,7 @@ impl Print for &'_ str { } #[derive(Debug, Clone)] -crate struct Buffer { +pub(crate) struct Buffer { for_html: bool, buffer: String, } @@ -82,63 +82,63 @@ impl core::fmt::Write for Buffer { } impl Buffer { - crate fn empty_from(v: &Buffer) -> Buffer { + pub(crate) fn empty_from(v: &Buffer) -> Buffer { Buffer { for_html: v.for_html, buffer: String::new() } } - crate fn html() -> Buffer { + pub(crate) fn html() -> Buffer { Buffer { for_html: true, buffer: String::new() } } - crate fn new() -> Buffer { + pub(crate) fn new() -> Buffer { Buffer { for_html: false, buffer: String::new() } } - crate fn is_empty(&self) -> bool { + pub(crate) fn is_empty(&self) -> bool { self.buffer.is_empty() } - crate fn into_inner(self) -> String { + pub(crate) fn into_inner(self) -> String { self.buffer } - crate fn insert_str(&mut self, idx: usize, s: &str) { + pub(crate) fn insert_str(&mut self, idx: usize, s: &str) { self.buffer.insert_str(idx, s); } - crate fn push_str(&mut self, s: &str) { + pub(crate) fn push_str(&mut self, s: &str) { self.buffer.push_str(s); } - crate fn push_buffer(&mut self, other: Buffer) { + pub(crate) fn push_buffer(&mut self, other: Buffer) { self.buffer.push_str(&other.buffer); } // Intended for consumption by write! and writeln! (std::fmt) but without // the fmt::Result return type imposed by fmt::Write (and avoiding the trait // import). - crate fn write_str(&mut self, s: &str) { + pub(crate) fn write_str(&mut self, s: &str) { self.buffer.push_str(s); } // Intended for consumption by write! and writeln! (std::fmt) but without // the fmt::Result return type imposed by fmt::Write (and avoiding the trait // import). - crate fn write_fmt(&mut self, v: fmt::Arguments<'_>) { + pub(crate) fn write_fmt(&mut self, v: fmt::Arguments<'_>) { use fmt::Write; self.buffer.write_fmt(v).unwrap(); } - crate fn to_display(mut self, t: T) -> String { + pub(crate) fn to_display(mut self, t: T) -> String { t.print(&mut self); self.into_inner() } - crate fn is_for_html(&self) -> bool { + pub(crate) fn is_for_html(&self) -> bool { self.for_html } - crate fn reserve(&mut self, additional: usize) { + pub(crate) fn reserve(&mut self, additional: usize) { self.buffer.reserve(additional) } } @@ -158,7 +158,7 @@ fn comma_sep( }) } -crate fn print_generic_bounds<'a, 'tcx: 'a>( +pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>( bounds: &'a [clean::GenericBound], cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -176,7 +176,7 @@ crate fn print_generic_bounds<'a, 'tcx: 'a>( } impl clean::GenericParamDef { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -239,7 +239,7 @@ impl clean::GenericParamDef { } impl clean::Generics { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -262,7 +262,7 @@ impl clean::Generics { /// * The Generics from which to emit a where-clause. /// * The number of spaces to indent each line with. /// * Whether the where-clause needs to add a comma and newline after the last bound. -crate fn print_where_clause<'a, 'tcx: 'a>( +pub(crate) fn print_where_clause<'a, 'tcx: 'a>( gens: &'a clean::Generics, cx: &'a Context<'tcx>, indent: usize, @@ -372,13 +372,13 @@ crate fn print_where_clause<'a, 'tcx: 'a>( } impl clean::Lifetime { - crate fn print(&self) -> impl fmt::Display + '_ { + pub(crate) fn print(&self) -> impl fmt::Display + '_ { self.0.as_str() } } impl clean::Constant { - crate fn print(&self, tcx: TyCtxt<'_>) -> impl fmt::Display + '_ { + pub(crate) fn print(&self, tcx: TyCtxt<'_>) -> impl fmt::Display + '_ { let expr = self.expr(tcx); display_fn( move |f| { @@ -419,7 +419,7 @@ impl clean::PolyTrait { } impl clean::GenericBound { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -516,7 +516,7 @@ impl clean::GenericArgs { } // Possible errors when computing href link source for a `DefId` -crate enum HrefError { +pub(crate) enum HrefError { /// This item is known to rustdoc, but from a crate that does not have documentation generated. /// /// This can only happen for non-local items. @@ -543,7 +543,7 @@ crate enum HrefError { } // Panics if `syms` is empty. -crate fn join_with_double_colon(syms: &[Symbol]) -> String { +pub(crate) fn join_with_double_colon(syms: &[Symbol]) -> String { let mut s = String::with_capacity(estimate_item_path_byte_length(syms.len())); s.push_str(&syms[0].as_str()); for sym in &syms[1..] { @@ -553,7 +553,7 @@ crate fn join_with_double_colon(syms: &[Symbol]) -> String { s } -crate fn href_with_root_path( +pub(crate) fn href_with_root_path( did: DefId, cx: &Context<'_>, root_path: Option<&str>, @@ -633,14 +633,17 @@ crate fn href_with_root_path( Ok((url_parts.finish(), shortty, fqp.to_vec())) } -crate fn href(did: DefId, cx: &Context<'_>) -> Result<(String, ItemType, Vec), HrefError> { +pub(crate) fn href( + did: DefId, + cx: &Context<'_>, +) -> Result<(String, ItemType, Vec), HrefError> { href_with_root_path(did, cx, None) } /// Both paths should only be modules. /// This is because modules get their own directories; that is, `std::vec` and `std::vec::Vec` will /// both need `../iter/trait.Iterator.html` to get at the iterator trait. -crate fn href_relative_parts<'fqp>( +pub(crate) fn href_relative_parts<'fqp>( fqp: &'fqp [Symbol], relative_to_fqp: &[Symbol], ) -> Box + 'fqp> { @@ -787,7 +790,7 @@ fn tybounds<'a, 'tcx: 'a>( }) } -crate fn anchor<'a, 'cx: 'a>( +pub(crate) fn anchor<'a, 'cx: 'a>( did: DefId, text: Symbol, cx: &'cx Context<'_>, @@ -1031,7 +1034,7 @@ fn fmt_type<'cx>( } impl clean::Type { - crate fn print<'b, 'a: 'b, 'tcx: 'a>( + pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'b + Captures<'tcx> { @@ -1040,7 +1043,7 @@ impl clean::Type { } impl clean::Path { - crate fn print<'b, 'a: 'b, 'tcx: 'a>( + pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'b + Captures<'tcx> { @@ -1049,7 +1052,7 @@ impl clean::Path { } impl clean::Impl { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, use_absolute: bool, cx: &'a Context<'tcx>, @@ -1083,7 +1086,7 @@ impl clean::Impl { } impl clean::Arguments { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1107,7 +1110,7 @@ impl clean::Arguments { } impl clean::FnRetTy { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1142,7 +1145,7 @@ impl clean::BareFunctionDecl { } impl clean::FnDecl { - crate fn print<'b, 'a: 'b, 'tcx: 'a>( + pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'b + Captures<'tcx> { @@ -1174,7 +1177,7 @@ impl clean::FnDecl { /// * `indent`: The number of spaces to indent each successive line with, if line-wrapping is /// necessary. /// * `asyncness`: Whether the function is async or not. - crate fn full_print<'a, 'tcx: 'a>( + pub(crate) fn full_print<'a, 'tcx: 'a>( &'a self, header_len: usize, indent: usize, @@ -1291,7 +1294,7 @@ impl clean::FnDecl { } impl clean::Visibility { - crate fn print_with_space<'a, 'tcx: 'a>( + pub(crate) fn print_with_space<'a, 'tcx: 'a>( self, item_did: ItemId, cx: &'a Context<'tcx>, @@ -1339,7 +1342,7 @@ impl clean::Visibility { /// This function is the same as print_with_space, except that it renders no links. /// It's used for macros' rendered source view, which is syntax highlighted and cannot have /// any HTML in it. - crate fn to_src_with_space<'a, 'tcx: 'a>( + pub(crate) fn to_src_with_space<'a, 'tcx: 'a>( self, tcx: TyCtxt<'tcx>, item_did: DefId, @@ -1374,7 +1377,7 @@ impl clean::Visibility { } } -crate trait PrintWithSpace { +pub(crate) trait PrintWithSpace { fn print_with_space(&self) -> &str; } @@ -1405,7 +1408,10 @@ impl PrintWithSpace for hir::Mutability { } } -crate fn print_constness_with_space(c: &hir::Constness, s: Option) -> &'static str { +pub(crate) fn print_constness_with_space( + c: &hir::Constness, + s: Option, +) -> &'static str { match (c, s) { // const stable or when feature(staged_api) is not set ( @@ -1419,7 +1425,7 @@ crate fn print_constness_with_space(c: &hir::Constness, s: Option( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1443,7 +1449,7 @@ impl clean::Import { } impl clean::ImportSource { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1466,7 +1472,7 @@ impl clean::ImportSource { } impl clean::TypeBinding { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1500,7 +1506,7 @@ impl clean::TypeBinding { } } -crate fn print_abi_with_space(abi: Abi) -> impl fmt::Display { +pub(crate) fn print_abi_with_space(abi: Abi) -> impl fmt::Display { display_fn(move |f| { let quot = if f.alternate() { "\"" } else { """ }; match abi { @@ -1510,12 +1516,12 @@ crate fn print_abi_with_space(abi: Abi) -> impl fmt::Display { }) } -crate fn print_default_space<'a>(v: bool) -> &'a str { +pub(crate) fn print_default_space<'a>(v: bool) -> &'a str { if v { "default " } else { "" } } impl clean::GenericArg { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1529,7 +1535,7 @@ impl clean::GenericArg { } impl clean::types::Term { - crate fn print<'a, 'tcx: 'a>( + pub(crate) fn print<'a, 'tcx: 'a>( &'a self, cx: &'a Context<'tcx>, ) -> impl fmt::Display + 'a + Captures<'tcx> { @@ -1540,7 +1546,9 @@ impl clean::types::Term { } } -crate fn display_fn(f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Display { +pub(crate) fn display_fn( + f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result, +) -> impl fmt::Display { struct WithFormatter(Cell>); impl fmt::Display for WithFormatter diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index a0187bd77f8..480728b1797 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -22,21 +22,21 @@ use super::format::{self, Buffer}; use super::render::LinkFromSrc; /// This type is needed in case we want to render links on items to allow to go to their definition. -crate struct ContextInfo<'a, 'b, 'c> { - crate context: &'a Context<'b>, +pub(crate) struct ContextInfo<'a, 'b, 'c> { + pub(crate) context: &'a Context<'b>, /// This span contains the current file we're going through. - crate file_span: Span, + pub(crate) file_span: Span, /// This field is used to know "how far" from the top of the directory we are to link to either /// documentation pages or other source pages. - crate root_path: &'c str, + pub(crate) root_path: &'c str, } /// Decorations are represented as a map from CSS class to vector of character ranges. /// Each range will be wrapped in a span with that class. -crate struct DecorationInfo(crate FxHashMap<&'static str, Vec<(u32, u32)>>); +pub(crate) struct DecorationInfo(pub(crate) FxHashMap<&'static str, Vec<(u32, u32)>>); /// Highlights `src`, returning the HTML output. -crate fn render_with_highlighting( +pub(crate) fn render_with_highlighting( src: &str, out: &mut Buffer, class: Option<&str>, diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 4ca71ea8684..de54347a0f7 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -10,33 +10,33 @@ use crate::html::render::{ensure_trailing_slash, StylePath}; use askama::Template; #[derive(Clone)] -crate struct Layout { - crate logo: String, - crate favicon: String, - crate external_html: ExternalHtml, - crate default_settings: FxHashMap, - crate krate: String, +pub(crate) struct Layout { + pub(crate) logo: String, + pub(crate) favicon: String, + pub(crate) external_html: ExternalHtml, + pub(crate) default_settings: FxHashMap, + pub(crate) krate: String, /// The given user css file which allow to customize the generated /// documentation theme. - crate css_file_extension: Option, + pub(crate) css_file_extension: Option, /// If true, then scrape-examples.js will be included in the output HTML file - crate scrape_examples_extension: bool, + pub(crate) scrape_examples_extension: bool, } -crate struct Page<'a> { - crate title: &'a str, - crate css_class: &'a str, - crate root_path: &'a str, - crate static_root_path: Option<&'a str>, - crate description: &'a str, - crate keywords: &'a str, - crate resource_suffix: &'a str, - crate extra_scripts: &'a [&'a str], - crate static_extra_scripts: &'a [&'a str], +pub(crate) struct Page<'a> { + pub(crate) title: &'a str, + pub(crate) css_class: &'a str, + pub(crate) root_path: &'a str, + pub(crate) static_root_path: Option<&'a str>, + pub(crate) description: &'a str, + pub(crate) keywords: &'a str, + pub(crate) resource_suffix: &'a str, + pub(crate) extra_scripts: &'a [&'a str], + pub(crate) static_extra_scripts: &'a [&'a str], } impl<'a> Page<'a> { - crate fn get_static_root_path(&self) -> &str { + pub(crate) fn get_static_root_path(&self) -> &str { self.static_root_path.unwrap_or(self.root_path) } } @@ -51,10 +51,10 @@ struct PageLayout<'a> { sidebar: String, content: String, krate_with_trailing_slash: String, - crate rustdoc_version: &'a str, + pub(crate) rustdoc_version: &'a str, } -crate fn render( +pub(crate) fn render( layout: &Layout, page: &Page<'_>, sidebar: S, @@ -86,7 +86,7 @@ crate fn render( .unwrap() } -crate fn redirect(url: &str) -> String { +pub(crate) fn redirect(url: &str) -> String { //