diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2022-05-20 21:06:44 -0400 |
|---|---|---|
| committer | Jacob Pratt <jacob@jhpratt.dev> | 2022-05-21 00:32:47 -0400 |
| commit | 69702468865d582f512df31a52ac2608afe5df0d (patch) | |
| tree | 12c11456a618b7ca4dffd47967802e7f46cb2ed4 | |
| parent | 49c82f31a85f04a709810de4ccfb8ba765c1377b (diff) | |
| download | rust-69702468865d582f512df31a52ac2608afe5df0d.tar.gz rust-69702468865d582f512df31a52ac2608afe5df0d.zip | |
Remove `crate` visibility modifier in libs, tests
85 files changed, 1037 insertions, 1252 deletions
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<RegionTarget<'tcx>>, } -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<Item> { + pub(crate) fn get_auto_trait_impls(&mut self, item_def_id: DefId) -> Vec<Item> { 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<Item> { + pub(crate) fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> { 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<Cfg>, ) -> Result<Option<Cfg>, 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<Cfg, InvalidCfgError> { + pub(crate) fn parse(cfg: &MetaItem) -> Result<Cfg, InvalidCfgError> { 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<DefId>, @@ -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<DefId>, @@ -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<DefId>, 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<DefId>, 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<T> { +pub(crate) trait Clean<T> { 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<WP>) -> Vec<WP> { +pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> { // 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<WP>) -> Vec<WP> { clauses } -crate fn merge_bounds( +pub(crate) fn merge_bounds( cx: &clean::DocContext<'_>, bounds: &mut Vec<clean::GenericBound>, 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<ItemId>; +pub(crate) type ItemIdSet = FxHashSet<ItemId>; #[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<DefId> { + pub(crate) fn as_def_id(self) -> Option<DefId> { 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<DefId> 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<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>, + pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>, } // `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<Symbol>, - crate attrs: Box<Attributes>, - crate visibility: Visibility, + pub(crate) name: Option<Symbol>, + pub(crate) attrs: Box<Attributes>, + 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<ItemKind>, - crate item_id: ItemId, + pub(crate) kind: Box<ItemKind>, + pub(crate) item_id: ItemId, - crate cfg: Option<Arc<Cfg>>, + pub(crate) cfg: Option<Arc<Cfg>>, } /// 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<Stability> { + pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> { self.item_id.as_def_id().and_then(|did| tcx.lookup_stability(did)) } - crate fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> { + pub(crate) fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> { self.item_id.as_def_id().and_then(|did| tcx.lookup_const_stability(did)) } - crate fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> { + pub(crate) fn deprecation(&self, tcx: TyCtxt<'_>) -> Option<Deprecation> { 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<String> { + pub(crate) fn doc_value(&self) -> Option<String> { 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<Symbol>, 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<Symbol>, 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<Symbol>, 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<String> { + pub(crate) fn collapsed_doc_value(&self) -> Option<String> { self.attrs.collapsed_doc_value() } - crate fn links(&self, cx: &Context<'_>) -> Vec<RenderedLink> { + pub(crate) fn links(&self, cx: &Context<'_>) -> Vec<RenderedLink> { 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<RenderedLink> { + pub(crate) fn link_names(&self, cache: &Cache) -> Vec<RenderedLink> { 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<bool> { + pub(crate) fn has_stripped_fields(&self) -> Option<bool> { 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<String> { + pub(crate) fn stability_class(&self, tcx: TyCtxt<'_>) -> Option<String> { 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<Symbol> { + pub(crate) fn stable_since(&self, tcx: TyCtxt<'_>) -> Option<Symbol> { match self.stability(tcx)?.level { StabilityLevel::Stable { since, .. } => Some(since), StabilityLevel::Unstable { .. } => None, } } - crate fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option<Symbol> { + pub(crate) fn const_stable_since(&self, tcx: TyCtxt<'_>) -> Option<Symbol> { 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<hir::FnHeader> { + pub(crate) fn fn_header(&self, tcx: TyCtxt<'_>) -> Option<hir::FnHeader> { 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<Symbol>, @@ -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<Item = &Item> { + pub(crate) fn inner_items(&self) -> impl Iterator<Item = &Item> { 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<Item>, - crate span: Span, +pub(crate) struct Module { + pub(crate) items: Vec<Item>, + pub(crate) span: Span, } -crate trait AttributesExt { +pub(crate) trait AttributesExt { type AttributeIterator<'a>: Iterator<Item = ast::NestedMetaItem> 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<I: Iterator<Item = ast::NestedMetaItem>> 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<DefId>, - crate doc: Symbol, - crate kind: DocFragmentKind, - crate indent: usize, + pub(crate) parent_module: Option<DefId>, + 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<DocFragment>) { /// /// 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<UrlFragment>, + pub(crate) fragment: Option<UrlFragment>, } 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<DocFragment>, - crate other_attrs: Vec<ast::Attribute>, +pub(crate) struct Attributes { + pub(crate) doc_strings: Vec<DocFragment>, + pub(crate) other_attrs: Vec<ast::Attribute>, } impl Attributes { - crate fn lists(&self, name: Symbol) -> impl Iterator<Item = ast::NestedMetaItem> + '_ { + pub(crate) fn lists(&self, name: Symbol) -> impl Iterator<Item = ast::NestedMetaItem> + '_ { 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<Item = (&'a ast::Attribute, Option<DefId>)>, 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<String> { + pub(crate) fn doc_value(&self) -> Option<String> { 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<Option<DefId>, String> { + pub(crate) fn prepare_to_doc_link_resolution(&self) -> FxHashMap<Option<DefId>, 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<String> { + pub(crate) fn collapsed_doc_value(&self) -> Option<String> { 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<PolyTrait> { + pub(crate) fn get_poly_trait(&self) -> Option<PolyTrait> { if let GenericBound::TraitBound(ref p, _) = *self { return Some(p.clone()); } None } - crate fn get_trait_path(&self) -> Option<Path> { + pub(crate) fn get_trait_path(&self) -> Option<Path> { 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<GenericBound>, bound_params: Vec<Lifetime> }, RegionPredicate { lifetime: Lifetime, bounds: Vec<GenericBound> }, 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<Lifetime> }, Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool }, Const { did: DefId, ty: Box<Type>, default: Option<Box<String>> }, } 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<Generic>? #[derive(Clone, Debug, Default)] -crate struct Generics { - crate params: Vec<GenericParamDef>, - crate where_predicates: Vec<WherePredicate>, +pub(crate) struct Generics { + pub(crate) params: Vec<GenericParamDef>, + pub(crate) where_predicates: Vec<WherePredicate>, } #[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<SelfTy> { + pub(crate) fn self_type(&self) -> Option<SelfTy> { 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<Argument>, +pub(crate) struct Arguments { + pub(crate) values: Vec<Argument>, } #[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 <https://github.com/rust-lang/rust/issues/83167>. - crate is_const: bool, + pub(crate) is_const: bool, } #[derive(Clone, PartialEq, Debug)] -crate enum SelfTy { +pub(crate) enum SelfTy { SelfValue, SelfBorrowed(Option<Lifetime>, Mutability), SelfExplicit(Type), } impl Argument { - crate fn to_self(&self) -> Option<SelfTy> { + pub(crate) fn to_self(&self) -> Option<SelfTy> { 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<Item>, - crate generics: Generics, - crate bounds: Vec<GenericBound>, - crate is_auto: bool, +pub(crate) struct Trait { + pub(crate) unsafety: hir::Unsafety, + pub(crate) items: Vec<Item>, + pub(crate) generics: Generics, + pub(crate) bounds: Vec<GenericBound>, + pub(crate) is_auto: bool, } #[derive(Clone, Debug)] -crate struct TraitAlias { - crate generics: Generics, - crate bounds: Vec<GenericBound>, +pub(crate) struct TraitAlias { + pub(crate) generics: Generics, + pub(crate) bounds: Vec<GenericBound>, } /// 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<GenericParamDef>, +pub(crate) struct PolyTrait { + pub(crate) trait_: Path, + pub(crate) generic_params: Vec<GenericParamDef>, } /// 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<PrimitiveType> { + pub(crate) fn primitive_type(&self) -> Option<PrimitiveType> { 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<Vec<&Type>> { + pub(crate) fn generics(&self) -> Option<Vec<&Type>> { 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<DefId> { + pub(crate) fn def_id(&self, cache: &Cache) -> Option<DefId> { 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<PrimitiveType, ArrayVec<SimplifiedType, 2>>; 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<PrimitiveType> { + pub(crate) fn from_symbol(s: Symbol) -> Option<PrimitiveType> { 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<Item = DefId> + 'tcx { + pub(crate) fn impls<'tcx>(&self, tcx: TyCtxt<'tcx>) -> impl Iterator<Item = DefId> + 'tcx { Self::simplified_types() .get(self) .into_iter() @@ -1851,7 +1851,7 @@ impl PrimitiveType { .copied() } - crate fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> + '_ { + pub(crate) fn all_impls(tcx: TyCtxt<'_>) -> impl Iterator<Item = DefId> + '_ { 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<PrimitiveType, DefId> { + pub(crate) fn primitive_locations(tcx: TyCtxt<'_>) -> &FxHashMap<PrimitiveType, DefId> { static PRIMITIVE_LOCATIONS: OnceCell<FxHashMap<PrimitiveType, DefId>> = OnceCell::new(); PRIMITIVE_LOCATIONS.get_or_init(|| { let mut primitive_locations = FxHashMap::default(); @@ -2008,7 +2008,7 @@ impl From<hir::PrimTy> 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<Item>, - crate fields_stripped: bool, +pub(crate) struct Struct { + pub(crate) struct_type: CtorKind, + pub(crate) generics: Generics, + pub(crate) fields: Vec<Item>, + pub(crate) fields_stripped: bool, } #[derive(Clone, Debug)] -crate struct Union { - crate generics: Generics, - crate fields: Vec<Item>, - crate fields_stripped: bool, +pub(crate) struct Union { + pub(crate) generics: Generics, + pub(crate) fields: Vec<Item>, + 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<Item>, - crate fields_stripped: bool, +pub(crate) struct VariantStruct { + pub(crate) struct_type: CtorKind, + pub(crate) fields: Vec<Item>, + pub(crate) fields_stripped: bool, } #[derive(Clone, Debug)] -crate struct Enum { - crate variants: IndexVec<VariantIdx, Item>, - crate generics: Generics, - crate variants_stripped: bool, +pub(crate) struct Enum { + pub(crate) variants: IndexVec<VariantIdx, Item>, + pub(crate) generics: Generics, + pub(crate) variants_stripped: bool, } #[derive(Clone, Debug)] -crate enum Variant { +pub(crate) enum Variant { CLike, Tuple(Vec<Item>), 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<PathSegment>, +pub(crate) struct Path { + pub(crate) res: Res, + pub(crate) segments: Vec<PathSegment>, } 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<Vec<&Type>> { + pub(crate) fn generics(&self) -> Option<Vec<&Type>> { 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<Constant>), @@ -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<GenericArg>, bindings: ThinVec<TypeBinding> }, Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> }, } @@ -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<Type>, + pub(crate) item_type: Option<Type>, } #[derive(Clone, Debug)] -crate struct OpaqueTy { - crate bounds: Vec<GenericBound>, - crate generics: Generics, +pub(crate) struct OpaqueTy { + pub(crate) bounds: Vec<GenericBound>, + pub(crate) generics: Generics, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] -crate struct BareFunctionDecl { - crate unsafety: hir::Unsafety, - crate generic_params: Vec<GenericParamDef>, - crate decl: FnDecl, - crate abi: Abi, +pub(crate) struct BareFunctionDecl { + pub(crate) unsafety: hir::Unsafety, + pub(crate) generic_params: Vec<GenericParamDef>, + pub(crate) decl: FnDecl, + pub(crate) abi: Abi, } #[derive(Clone, Debug)] -crate struct Static { - crate type_: Type, - crate mutability: Mutability, - crate expr: Option<BodyId>, +pub(crate) struct Static { + pub(crate) type_: Type, + pub(crate) mutability: Mutability, + pub(crate) expr: Option<BodyId>, } #[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<Type> 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<String> { + pub(crate) fn value(&self, tcx: TyCtxt<'_>) -> Option<String> { 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<String> { + pub(crate) fn value(&self, tcx: TyCtxt<'_>) -> Option<String> { 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<Path>, - crate for_: Type, - crate items: Vec<Item>, - crate polarity: ty::ImplPolarity, - crate kind: ImplKind, +pub(crate) struct Impl { + pub(crate) unsafety: hir::Unsafety, + pub(crate) generics: Generics, + pub(crate) trait_: Option<Path>, + pub(crate) for_: Type, + pub(crate) items: Vec<Item>, + pub(crate) polarity: ty::ImplPolarity, + pub(crate) kind: ImplKind, } impl Impl { - crate fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> { + pub(crate) fn provided_trait_methods(&self, tcx: TyCtxt<'_>) -> FxHashSet<Symbol> { 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<Type>), } 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<DefId>, +pub(crate) struct ImportSource { + pub(crate) path: Path, + pub(crate) did: Option<DefId>, } #[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<Symbol>, +pub(crate) struct ProcMacro { + pub(crate) kind: MacroKind, + pub(crate) helpers: Vec<Symbol>, } /// An type binding on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or /// `A: Send + Sync` in `Foo<A: Send + Sync>`). #[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<GenericBound> }, } 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<i32>`, 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<Item>) { +pub(crate) fn build_deref_target_impls( + cx: &mut DocContext<'_>, + items: &[Item], + ret: &mut Vec<Item>, +) { 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<String> { +pub(crate) fn print_evaluated_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<String> { 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<Item = Item> { @@ -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<F, R>(cx: &mut DocContext<'_>, f: F) -> R +pub(crate) fn enter_impl_trait<F, R>(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<DefId> { +pub(crate) fn find_nearest_parent_module(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> { 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<De /// /// This function exists because it runs on `hir::Attributes` whereas the other is a /// `clean::Attributes` method. -crate fn has_doc_flag(tcx: TyCtxt<'_>, 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<String>, + pub(crate) crate_name: Option<String>, /// 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<SearchPath>, + pub(crate) libs: Vec<SearchPath>, /// Library search paths strings to hand to the compiler. - crate lib_strs: Vec<String>, + pub(crate) lib_strs: Vec<String>, /// 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<String>, + pub(crate) extern_strs: Vec<String>, /// List of `cfg` flags to hand to the compiler. Always includes `rustdoc`. - crate cfgs: Vec<String>, + pub(crate) cfgs: Vec<String>, /// List of check cfg flags to hand to the compiler. - crate check_cfgs: Vec<String>, + pub(crate) check_cfgs: Vec<String>, /// 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<String>, + pub(crate) codegen_options_strs: Vec<String>, /// 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<String>, + pub(crate) debugging_opts_strs: Vec<String>, /// 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<PathBuf>, + pub(crate) maybe_sysroot: Option<PathBuf>, /// 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<Level>, + pub(crate) lint_cap: Option<Level>, // 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<String>, + pub(crate) test_args: Vec<String>, /// The working directory in which to run tests. - crate test_run_directory: Option<PathBuf>, + pub(crate) test_run_directory: Option<PathBuf>, /// Optional path to persist the doctest executables to, defaults to a /// temporary directory if not set. - crate persist_doctests: Option<PathBuf>, + pub(crate) persist_doctests: Option<PathBuf>, /// Runtool to run doctests with - crate runtool: Option<String>, + pub(crate) runtool: Option<String>, /// Arguments to pass to the runtool - crate runtool_args: Vec<String>, + pub(crate) runtool_args: Vec<String>, /// 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<PathBuf>, + pub(crate) test_builder: Option<PathBuf>, // 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<String>, + pub(crate) crate_version: Option<String>, /// 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<ScrapeExamplesOptions>, + pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>, } 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<String>, + pub(crate) playground_url: Option<String>, /// 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<StylePath>, + pub(crate) themes: Vec<StylePath>, /// If present, CSS file that contains rules to add to the default CSS. - crate extension_css: Option<PathBuf>, + pub(crate) extension_css: Option<PathBuf>, /// 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<String, String>, + pub(crate) extern_html_root_urls: BTreeMap<String, String>, /// 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<String, String>, + pub(crate) default_settings: FxHashMap<String, String>, /// 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<PathBuf>, + pub(crate) index_page: Option<PathBuf>, /// 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<String>, + pub(crate) static_root_path: Option<String>, // 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<String>, + pub(crate) markdown_css: Vec<String>, /// 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<String>, + pub(crate) markdown_playground_url: Option<String>, /// 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<EmitType>, + pub(crate) show_type_layout: bool, + pub(crate) unstable_features: rustc_feature::UnstableFeatures, + pub(crate) emit: Vec<EmitType>, /// 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<Options, i32> { + pub(crate) fn from_matches(matches: &getopts::Matches) -> Result<Options, i32> { // 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<FxHashMap<String, Vec<PreprocessedMarkdownLink>>>, - crate doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option<Res<NodeId>>>, +pub(crate) struct ResolverCaches { + pub(crate) markdown_links: Option<FxHashMap<String, Vec<PreprocessedMarkdownLink>>>, + pub(crate) doc_link_resolutions: FxHashMap<(Symbol, Namespace, DefId), Option<Res<NodeId>>>, /// Traits in scope for a given module. /// See `collect_intra_doc_links::traits_implemented_by` for more details. - crate traits_in_scope: DefIdMap<Vec<TraitCandidate>>, - crate all_traits: Option<Vec<DefId>>, - crate all_trait_impls: Option<Vec<DefId>>, - crate all_macro_rules: FxHashMap<Symbol, Res<NodeId>>, + pub(crate) traits_in_scope: DefIdMap<Vec<TraitCandidate>>, + pub(crate) all_traits: Option<Vec<DefId>>, + pub(crate) all_trait_impls: Option<Vec<DefId>>, + pub(crate) all_macro_rules: FxHashMap<Symbol, Res<NodeId>>, } -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<RefCell<...>>` 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<RefCell<interface::BoxedResolver>>, - crate resolver_caches: ResolverCaches, + pub(crate) resolver: Rc<RefCell<interface::BoxedResolver>>, + 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<RefCell<FxHashMap<DefId, clean::TraitWithExtraInfo>>>, + pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, clean::TraitWithExtraInfo>>>, /// Used while populating `external_traits` to ensure we don't process the same trait twice at /// the same time. - crate active_extern_traits: FxHashSet<DefId>, + pub(crate) active_extern_traits: FxHashSet<DefId>, // 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<DefId, clean::SubstParam>, + pub(crate) substs: FxHashMap<DefId, clean::SubstParam>, /// Table synthetic type parameter for `impl Trait` in argument position -> bounds - crate impl_trait_bounds: FxHashMap<ImplTraitParam, Vec<clean::GenericBound>>, + pub(crate) impl_trait_bounds: FxHashMap<ImplTraitParam, Vec<clean::GenericBound>>, /// 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<DefId>, + pub(crate) generated_synthetics: FxHashSet<(Ty<'tcx>, DefId)>, + pub(crate) auto_traits: Vec<DefId>, /// 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<ItemId>, + pub(crate) inlined: FxHashSet<ItemId>, /// 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, F: FnOnce(&mut Self) -> T>(&mut self, def_id: DefId, f: F) -> T { + pub(crate) fn with_param_env<T, F: FnOnce(&mut Self) -> 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<F, R>(&self, f: F) -> R + pub(crate) fn enter_resolver<F, R>(&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<F, R>(&mut self, substs: FxHashMap<DefId, clean::SubstParam>, f: F) -> R + pub(crate) fn enter_alias<F, R>( + &mut self, + substs: FxHashMap<DefId, clean::SubstParam>, + 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<HirId> { + pub(crate) fn as_local_hir_id(tcx: TyCtxt<'_>, item_id: ItemId) -> Option<HirId> { 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<Lrc<source_map::SourceMap>>, 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<RefCell<interface::BoxedResolver>>, 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<S, P: AsRef<Path>>(e: S, path: P) -> Self where S: ToString + Sized; } -crate struct DocFS { +pub(crate) struct DocFS { sync_only: bool, errors: Option<Sender<String>>, } impl DocFS { - crate fn new(errors: Sender<String>) -> DocFS { + pub(crate) fn new(errors: Sender<String>) -> 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<P: AsRef<Path>>(&self, path: P) -> io::Result<()> { + pub(crate) fn create_dir_all<P: AsRef<Path>>(&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<E>( + pub(crate) fn write<E>( &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<String>, + pub(crate) attrs: Vec<String>, } -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<String>, nocapture: bool, tests: Vec<test::TestDescAndFn>) { +pub(crate) fn run_tests( + mut test_args: Vec<String>, + nocapture: bool, + tests: Vec<test::TestDescAndFn>, +) { 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<test::TestDescAndFn>, +pub(crate) struct Collector { + pub(crate) tests: Vec<test::TestDescAndFn>, // 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 `<head>` 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 `<body>` 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 `</body>` 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<P: AsRef<Path>>( +pub(crate) fn load_string<P: AsRef<Path>>( file_path: P, diag: &rustc_errors::Handler, ) -> Result<String, LoadStringError> { 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<Item> { 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<DefId, Vec<Impl>>, + pub(crate) impls: FxHashMap<DefId, Vec<Impl>>, /// 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<DefId, (Vec<Symbol>, ItemType)>, + pub(crate) paths: FxHashMap<DefId, (Vec<Symbol>, ItemType)>, /// Similar to `paths`, but only holds external paths. This is only used for /// generating explicit hyperlinks to other crates. - crate external_paths: FxHashMap<DefId, (Vec<Symbol>, ItemType)>, + pub(crate) external_paths: FxHashMap<DefId, (Vec<Symbol>, 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<DefId, Vec<Symbol>>, + pub(crate) exact_paths: FxHashMap<DefId, Vec<Symbol>>, /// 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<DefId, clean::TraitWithExtraInfo>, + pub(crate) traits: FxHashMap<DefId, clean::TraitWithExtraInfo>, /// 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<DefId, Vec<Impl>>, + pub(crate) implementors: FxHashMap<DefId, Vec<Impl>>, /// Cache of where external crate documentation can be found. - crate extern_locations: FxHashMap<CrateNum, ExternalLocation>, + pub(crate) extern_locations: FxHashMap<CrateNum, ExternalLocation>, /// Cache of where documentation for primitives can be found. - crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>, + pub(crate) primitive_locations: FxHashMap<clean::PrimitiveType, DefId>, // 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<DefId>, + pub(crate) access_levels: AccessLevels<DefId>, /// The version of the crate being documented, if given from the `--crate-version` flag. - crate crate_version: Option<String>, + pub(crate) crate_version: Option<String>, /// 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<CrateNum>, + pub(crate) masked_crates: FxHashSet<CrateNum>, // Private fields only used when initially crawling a crate to build a cache stack: Vec<Symbol>, @@ -98,14 +98,14 @@ crate struct Cache { parent_is_trait_impl: bool, stripped_mod: bool, - crate search_index: Vec<IndexItem>, + pub(crate) search_index: Vec<IndexItem>, // 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<ItemId, Vec<clean::ItemLink>>, + pub(crate) intra_doc_links: FxHashMap<ItemId, Vec<clean::ItemLink>>, /// Cfg that have been hidden via #![doc(cfg_hide(...))] - crate hidden_cfg: FxHashSet<clean::cfg::Cfg>, + pub(crate) hidden_cfg: FxHashSet<clean::cfg::Cfg>, } /// 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<DefId>, document_private: bool) -> Self { + pub(crate) fn new(access_levels: AccessLevels<DefId>, 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<DefKind> 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<DefId> { + pub(crate) fn trait_did(&self) -> Option<DefId> { 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<T: Print>(mut self, t: T) -> String { + pub(crate) fn to_display<T: Print>(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<T: fmt::Display>( }) } -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<Symbol>), HrefError> { +pub(crate) fn href( + did: DefId, + cx: &Context<'_>, +) -> Result<(String, ItemType, Vec<Symbol>), 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<dyn Iterator<Item = Symbol> + '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<ConstStability>) -> &'static str { +pub(crate) fn print_constness_with_space( + c: &hir::Constness, + s: Option<ConstStability>, +) -> &'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<ConstStability } impl clean::Import { - 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> { @@ -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<F>(Cell<Option<F>>); impl<F> fmt::Display for WithFormatter<F> 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<String, String>, - 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<String, String>, + pub(crate) krate: String, /// The given user css file which allow to customize the generated /// documentation theme. - crate css_file_extension: Option<PathBuf>, + pub(crate) css_file_extension: Option<PathBuf>, /// 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<T: Print, S: Print>( +pub(crate) fn render<T: Print, S: Print>( layout: &Layout, page: &Page<'_>, sidebar: S, @@ -86,7 +86,7 @@ crate fn render<T: Print, S: Print>( .unwrap() } -crate fn redirect(url: &str) -> String { +pub(crate) fn redirect(url: &str) -> String { // <script> triggers a redirect before refresh, so this is fine. format!( r##"<!DOCTYPE html> diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5ba3bdc12ed..8877f628332 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -104,23 +104,23 @@ pub struct Markdown<'a> { pub heading_offset: HeadingOffset, } /// A tuple struct like `Markdown` that renders the markdown with a table of contents. -crate struct MarkdownWithToc<'a>( - crate &'a str, - crate &'a mut IdMap, - crate ErrorCodes, - crate Edition, - crate &'a Option<Playground>, +pub(crate) struct MarkdownWithToc<'a>( + pub(crate) &'a str, + pub(crate) &'a mut IdMap, + pub(crate) ErrorCodes, + pub(crate) Edition, + pub(crate) &'a Option<Playground>, ); /// A tuple struct like `Markdown` that renders the markdown escaping HTML tags. -crate struct MarkdownHtml<'a>( - crate &'a str, - crate &'a mut IdMap, - crate ErrorCodes, - crate Edition, - crate &'a Option<Playground>, +pub(crate) struct MarkdownHtml<'a>( + pub(crate) &'a str, + pub(crate) &'a mut IdMap, + pub(crate) ErrorCodes, + pub(crate) Edition, + pub(crate) &'a Option<Playground>, ); /// A tuple struct like `Markdown` that renders only the first paragraph. -crate struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [RenderedLink]); +pub(crate) struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [RenderedLink]); #[derive(Copy, Clone, PartialEq, Debug)] pub enum ErrorCodes { @@ -129,14 +129,14 @@ pub enum ErrorCodes { } impl ErrorCodes { - crate fn from(b: bool) -> Self { + pub(crate) fn from(b: bool) -> Self { match b { true => ErrorCodes::Yes, false => ErrorCodes::No, } } - crate fn as_bool(self) -> bool { + pub(crate) fn as_bool(self) -> bool { match self { ErrorCodes::Yes => true, ErrorCodes::No => false, @@ -716,7 +716,7 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> { } } -crate fn find_testable_code<T: doctest::Tester>( +pub(crate) fn find_testable_code<T: doctest::Tester>( doc: &str, tests: &mut T, error_codes: ErrorCodes, @@ -788,7 +788,7 @@ crate fn find_testable_code<T: doctest::Tester>( } } -crate struct ExtraInfo<'tcx> { +pub(crate) struct ExtraInfo<'tcx> { id: ExtraInfoId, sp: Span, tcx: TyCtxt<'tcx>, @@ -800,11 +800,11 @@ enum ExtraInfoId { } impl<'tcx> ExtraInfo<'tcx> { - crate fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> { + pub(crate) fn new(tcx: TyCtxt<'tcx>, hir_id: HirId, sp: Span) -> ExtraInfo<'tcx> { ExtraInfo { id: ExtraInfoId::Hir(hir_id), sp, tcx } } - crate fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> { + pub(crate) fn new_did(tcx: TyCtxt<'tcx>, did: DefId, sp: Span) -> ExtraInfo<'tcx> { ExtraInfo { id: ExtraInfoId::Def(did), sp, tcx } } @@ -835,20 +835,20 @@ impl<'tcx> ExtraInfo<'tcx> { } #[derive(Eq, PartialEq, Clone, Debug)] -crate struct LangString { +pub(crate) struct LangString { original: String, - crate should_panic: bool, - crate no_run: bool, - crate ignore: Ignore, - crate rust: bool, - crate test_harness: bool, - crate compile_fail: bool, - crate error_codes: Vec<String>, - crate edition: Option<Edition>, + pub(crate) should_panic: bool, + pub(crate) no_run: bool, + pub(crate) ignore: Ignore, + pub(crate) rust: bool, + pub(crate) test_harness: bool, + pub(crate) compile_fail: bool, + pub(crate) error_codes: Vec<String>, + pub(crate) edition: Option<Edition>, } #[derive(Eq, PartialEq, Clone, Debug)] -crate enum Ignore { +pub(crate) enum Ignore { All, None, Some(Vec<String>), @@ -1058,7 +1058,7 @@ impl Markdown<'_> { } impl MarkdownWithToc<'_> { - crate fn into_string(self) -> String { + pub(crate) fn into_string(self) -> String { let MarkdownWithToc(md, mut ids, codes, edition, playground) = self; let p = Parser::new_ext(md, main_body_opts()).into_offset_iter(); @@ -1080,7 +1080,7 @@ impl MarkdownWithToc<'_> { } impl MarkdownHtml<'_> { - crate fn into_string(self) -> String { + pub(crate) fn into_string(self) -> String { let MarkdownHtml(md, mut ids, codes, edition, playground) = self; // This is actually common enough to special-case @@ -1108,7 +1108,7 @@ impl MarkdownHtml<'_> { } impl MarkdownSummaryLine<'_> { - crate fn into_string(self) -> String { + pub(crate) fn into_string(self) -> String { let MarkdownSummaryLine(md, links) = self; // This is actually common enough to special-case if md.is_empty() { @@ -1207,7 +1207,7 @@ fn markdown_summary_with_limit( /// Will shorten to 59 or 60 characters, including an ellipsis (…) if it was shortened. /// /// See [`markdown_summary_with_limit`] for details about what is rendered and what is not. -crate fn short_markdown_summary(markdown: &str, link_names: &[RenderedLink]) -> String { +pub(crate) fn short_markdown_summary(markdown: &str, link_names: &[RenderedLink]) -> String { let (mut s, was_shortened) = markdown_summary_with_limit(markdown, link_names, 59); if was_shortened { @@ -1223,7 +1223,7 @@ crate fn short_markdown_summary(markdown: &str, link_names: &[RenderedLink]) -> /// - Headings, links, and formatting are stripped. /// - Inline code is rendered as-is, surrounded by backticks. /// - HTML and code blocks are ignored. -crate fn plain_text_summary(md: &str) -> String { +pub(crate) fn plain_text_summary(md: &str) -> String { if md.is_empty() { return String::new(); } @@ -1250,13 +1250,16 @@ crate fn plain_text_summary(md: &str) -> String { } #[derive(Debug)] -crate struct MarkdownLink { +pub(crate) struct MarkdownLink { pub kind: LinkType, pub link: String, pub range: Range<usize>, } -crate fn markdown_links<R>(md: &str, filter_map: impl Fn(MarkdownLink) -> Option<R>) -> Vec<R> { +pub(crate) fn markdown_links<R>( + md: &str, + filter_map: impl Fn(MarkdownLink) -> Option<R>, +) -> Vec<R> { if md.is_empty() { return vec![]; } @@ -1337,19 +1340,19 @@ crate fn markdown_links<R>(md: &str, filter_map: impl Fn(MarkdownLink) -> Option } #[derive(Debug)] -crate struct RustCodeBlock { +pub(crate) struct RustCodeBlock { /// The range in the markdown that the code block occupies. Note that this includes the fences /// for fenced code blocks. - crate range: Range<usize>, + pub(crate) range: Range<usize>, /// The range in the markdown that the code within the code block occupies. - crate code: Range<usize>, - crate is_fenced: bool, - crate lang_string: LangString, + pub(crate) code: Range<usize>, + pub(crate) is_fenced: bool, + pub(crate) lang_string: LangString, } /// Returns a range of bytes for each code block in the markdown that is tagged as `rust` or /// untagged (and assumed to be rust). -crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeBlock> { +pub(crate) fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeBlock> { let mut code_blocks = vec![]; if md.is_empty() { @@ -1492,7 +1495,7 @@ impl IdMap { IdMap { map: DEFAULT_ID_MAP.clone() } } - crate fn derive<S: AsRef<str> + ToString>(&mut self, candidate: S) -> String { + pub(crate) fn derive<S: AsRef<str> + ToString>(&mut self, candidate: S) -> String { let id = match self.map.get_mut(candidate.as_ref()) { None => candidate.to_string(), Some(a) => { diff --git a/src/librustdoc/html/mod.rs b/src/librustdoc/html/mod.rs index e1bbc784fd1..481ed16c05f 100644 --- a/src/librustdoc/html/mod.rs +++ b/src/librustdoc/html/mod.rs @@ -1,14 +1,14 @@ -crate mod escape; -crate mod format; -crate mod highlight; -crate mod layout; +pub(crate) mod escape; +pub(crate) mod format; +pub(crate) mod highlight; +pub(crate) mod layout; mod length_limit; // used by the error-index generator, so it needs to be public pub mod markdown; -crate mod render; -crate mod sources; -crate mod static_files; -crate mod toc; +pub(crate) mod render; +pub(crate) mod sources; +pub(crate) mod static_files; +pub(crate) mod toc; mod url_parts_builder; #[cfg(test)] diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 81f961992b6..76377c438e8 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -42,13 +42,13 @@ use crate::try_err; /// It is intended that this context is a lightweight object which can be fairly /// easily cloned because it is cloned per work-job (about once per item in the /// rustdoc tree). -crate struct Context<'tcx> { +pub(crate) struct Context<'tcx> { /// Current hierarchy of components leading down to what's currently being /// rendered pub(crate) current: Vec<Symbol>, /// The current destination folder of where HTML artifacts should be placed. /// This changes as the context descends into the module hierarchy. - crate dst: PathBuf, + pub(crate) dst: PathBuf, /// A flag, which when `true`, will render pages which redirect to the /// real location of an item. This is used to allow external links to /// publicly reused items to redirect to the right location. @@ -63,11 +63,11 @@ crate struct Context<'tcx> { /// Issue for improving the situation: [#82381][] /// /// [#82381]: https://github.com/rust-lang/rust/issues/82381 - crate shared: Rc<SharedContext<'tcx>>, + pub(crate) shared: Rc<SharedContext<'tcx>>, /// This flag indicates whether source links should be generated or not. If /// the source files are present in the html rendering, then this will be /// `true`. - crate include_sources: bool, + pub(crate) include_sources: bool, } // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. @@ -75,16 +75,16 @@ crate struct Context<'tcx> { rustc_data_structures::static_assert_size!(Context<'_>, 144); /// Shared mutable state used in [`Context`] and elsewhere. -crate struct SharedContext<'tcx> { - crate tcx: TyCtxt<'tcx>, +pub(crate) struct SharedContext<'tcx> { + pub(crate) tcx: TyCtxt<'tcx>, /// The path to the crate root source minus the file name. /// Used for simplifying paths to the highlighted source code files. - crate src_root: PathBuf, + pub(crate) src_root: PathBuf, /// This describes the layout of each page, and is not modified after /// creation of the context (contains info like the favicon and added html). - crate layout: layout::Layout, + pub(crate) layout: layout::Layout, /// The local file sources we've emitted and their respective url-paths. - crate local_sources: FxHashMap<PathBuf, String>, + pub(crate) local_sources: FxHashMap<PathBuf, String>, /// Show the memory layout of types in the docs. pub(super) show_type_layout: bool, /// The base-URL of the issue tracker for when an item has been tagged with @@ -97,15 +97,15 @@ crate struct SharedContext<'tcx> { /// should be ordered alphabetically or in order of appearance (in the source code). pub(super) sort_modules_alphabetically: bool, /// Additional CSS files to be added to the generated docs. - crate style_files: Vec<StylePath>, + pub(crate) style_files: Vec<StylePath>, /// Suffix to be added on resource files (if suffix is "-v2" then "light.css" becomes /// "light-v2.css"). - crate resource_suffix: String, + pub(crate) resource_suffix: String, /// Optional path string to be used to load static files on output pages. If not set, uses /// combinations of `../` to reach the documentation root. - crate static_root_path: Option<String>, + pub(crate) static_root_path: Option<String>, /// The fs handle we are working with. - crate fs: DocFS, + pub(crate) fs: DocFS, pub(super) codes: ErrorCodes, pub(super) playground: Option<markdown::Playground>, all: RefCell<AllTypes>, @@ -119,15 +119,15 @@ crate struct SharedContext<'tcx> { /// Correspondance map used to link types used in the source code pages to allow to click on /// links to jump to the type's definition. - crate span_correspondance_map: FxHashMap<rustc_span::Span, LinkFromSrc>, + pub(crate) span_correspondance_map: FxHashMap<rustc_span::Span, LinkFromSrc>, /// The [`Cache`] used during rendering. - crate cache: Cache, + pub(crate) cache: Cache, - crate call_locations: AllCallLocations, + pub(crate) call_locations: AllCallLocations, } impl SharedContext<'_> { - crate fn ensure_dir(&self, dst: &Path) -> Result<(), Error> { + pub(crate) fn ensure_dir(&self, dst: &Path) -> Result<(), Error> { let mut dirs = self.created_dirs.borrow_mut(); if !dirs.contains(dst) { try_err!(self.fs.create_dir_all(dst), dst); @@ -137,7 +137,7 @@ impl SharedContext<'_> { Ok(()) } - crate fn edition(&self) -> Edition { + pub(crate) fn edition(&self) -> Edition { self.tcx.sess.edition() } } @@ -301,7 +301,7 @@ impl<'tcx> Context<'tcx> { self.href_from_span(item.span(self.tcx()), true) } - crate fn href_from_span(&self, span: clean::Span, with_lines: bool) -> Option<String> { + pub(crate) fn href_from_span(&self, span: clean::Span, with_lines: bool) -> Option<String> { if span.is_dummy() { return None; } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index c13ae1e431a..0de50c60fac 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -23,7 +23,7 @@ //! These threads are not parallelized (they haven't been a bottleneck yet), and //! both occur before the crate is rendered. -crate mod search_index; +pub(crate) mod search_index; #[cfg(test)] mod tests; @@ -33,8 +33,8 @@ mod print_item; mod span_map; mod write_shared; -crate use self::context::*; -crate use self::span_map::{collect_spans_and_sources, LinkFromSrc}; +pub(crate) use self::context::*; +pub(crate) use self::span_map::{collect_spans_and_sources, LinkFromSrc}; use std::collections::VecDeque; use std::default::Default; @@ -81,9 +81,9 @@ use crate::try_none; use crate::DOC_RUST_LANG_ORG_CHANNEL; /// A pair of name and its optional document. -crate type NameDoc = (String, Option<String>); +pub(crate) type NameDoc = (String, Option<String>); -crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ { +pub(crate) fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ { crate::html::format::display_fn(move |f| { if !v.ends_with('/') && !v.is_empty() { write!(f, "{}/", v) } else { f.write_str(v) } }) @@ -95,27 +95,27 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ { /// Struct representing one entry in the JS search index. These are all emitted /// by hand to a large JS file at the end of cache-creation. #[derive(Debug)] -crate struct IndexItem { - crate ty: ItemType, - crate name: String, - crate path: String, - crate desc: String, - crate parent: Option<DefId>, - crate parent_idx: Option<usize>, - crate search_type: Option<IndexItemFunctionType>, - crate aliases: Box<[Symbol]>, +pub(crate) struct IndexItem { + pub(crate) ty: ItemType, + pub(crate) name: String, + pub(crate) path: String, + pub(crate) desc: String, + pub(crate) parent: Option<DefId>, + pub(crate) parent_idx: Option<usize>, + pub(crate) search_type: Option<IndexItemFunctionType>, + pub(crate) aliases: Box<[Symbol]>, } /// A type used for the search index. #[derive(Debug)] -crate struct RenderType { +pub(crate) struct RenderType { name: Option<String>, generics: Option<Vec<TypeWithKind>>, } /// Full type of functions/methods in the search index. #[derive(Debug)] -crate struct IndexItemFunctionType { +pub(crate) struct IndexItemFunctionType { inputs: Vec<TypeWithKind>, output: Vec<TypeWithKind>, } @@ -143,7 +143,7 @@ impl Serialize for IndexItemFunctionType { } #[derive(Debug)] -crate struct TypeWithKind { +pub(crate) struct TypeWithKind { ty: RenderType, kind: ItemType, } @@ -170,13 +170,13 @@ impl Serialize for TypeWithKind { } #[derive(Debug, Clone)] -crate struct StylePath { +pub(crate) struct StylePath { /// The path to the theme - crate path: PathBuf, + pub(crate) path: PathBuf, } impl StylePath { - crate fn basename(&self) -> Result<String, Error> { + pub(crate) fn basename(&self) -> Result<String, Error> { Ok(try_none!(try_none!(self.path.file_stem(), &self.path).to_str(), &self.path).to_string()) } } @@ -203,7 +203,7 @@ impl ItemEntry { } impl ItemEntry { - crate fn print(&self) -> impl fmt::Display + '_ { + pub(crate) fn print(&self) -> impl fmt::Display + '_ { crate::html::format::display_fn(move |f| { write!(f, "<a href=\"{}\">{}</a>", self.url, Escape(&self.name)) }) @@ -2580,7 +2580,7 @@ fn sidebar_foreign_type(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item) { } } -crate const BASIC_KEYWORDS: &str = "rust, rustlang, rust-lang"; +pub(crate) const BASIC_KEYWORDS: &str = "rust, rustlang, rust-lang"; /// Returns a list of all paths used in the type. /// This is used to help deduplicate imported impls diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 4951cd83af2..12e6115e6fe 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -246,14 +246,14 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl // This call is to remove re-export duplicates in cases such as: // // ``` - // crate mod foo { - // crate mod bar { - // crate trait Double { fn foo(); } + // pub(crate) mod foo { + // pub(crate) mod bar { + // pub(crate) trait Double { fn foo(); } // } // } // - // crate use foo::bar::*; - // crate use foo::*; + // pub(crate) use foo::bar::*; + // pub(crate) use foo::*; // ``` // // `Double` will appear twice in the generated docs. @@ -1473,7 +1473,7 @@ fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { } /// Compare two strings treating multi-digit numbers as single units (i.e. natural sort order). -crate fn compare_names(mut lhs: &str, mut rhs: &str) -> Ordering { +pub(crate) fn compare_names(mut lhs: &str, mut rhs: &str) -> Ordering { /// Takes a non-numeric and a numeric part from the given &str. fn take_parts<'a>(s: &mut &'a str) -> (&'a str, &'a str) { let i = s.find(|c: char| c.is_ascii_digit()); diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index e1309c03b5c..4e53ba4dc0c 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -15,7 +15,11 @@ use crate::html::markdown::short_markdown_summary; use crate::html::render::{IndexItem, IndexItemFunctionType, RenderType, TypeWithKind}; /// Builds the search index from the collected metadata -crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<'tcx>) -> String { +pub(crate) fn build_index<'tcx>( + krate: &clean::Crate, + cache: &mut Cache, + tcx: TyCtxt<'tcx>, +) -> String { let mut defid_to_pathid = FxHashMap::default(); let mut crate_paths = vec![]; @@ -185,7 +189,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt< ) } -crate fn get_function_type_for_search<'tcx>( +pub(crate) fn get_function_type_for_search<'tcx>( item: &clean::Item, tcx: TyCtxt<'tcx>, cache: &Cache, diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index 1ae888d059d..287ce9611d7 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -20,7 +20,7 @@ use std::path::{Path, PathBuf}; /// Otherwise, we store the definition `DefId` and will generate a link to the documentation page /// instead of the source code directly. #[derive(Debug)] -crate enum LinkFromSrc { +pub(crate) enum LinkFromSrc { Local(clean::Span), External(DefId), Primitive(PrimitiveType), @@ -36,7 +36,7 @@ crate enum LinkFromSrc { /// Note about the `span` correspondance map: the keys are actually `(lo, hi)` of `span`s. We don't /// need the `span` context later on, only their position, so instead of keep a whole `Span`, we /// only keep the `lo` and `hi`. -crate fn collect_spans_and_sources( +pub(crate) fn collect_spans_and_sources( tcx: TyCtxt<'_>, krate: &clean::Crate, src_root: &Path, @@ -57,8 +57,8 @@ crate fn collect_spans_and_sources( } struct SpanMapVisitor<'tcx> { - crate tcx: TyCtxt<'tcx>, - crate matches: FxHashMap<Span, LinkFromSrc>, + pub(crate) tcx: TyCtxt<'tcx>, + pub(crate) matches: FxHashMap<Span, LinkFromSrc>, } impl<'tcx> SpanMapVisitor<'tcx> { diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 9fba6e91162..0bbdc37ea89 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -16,7 +16,7 @@ use std::ffi::OsStr; use std::fs; use std::path::{Component, Path, PathBuf}; -crate fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), Error> { +pub(crate) fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), Error> { info!("emitting source files"); let dst = cx.dst.join("src").join(krate.name(cx.tcx()).as_str()); @@ -27,7 +27,7 @@ crate fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), Error> Ok(()) } -crate fn collect_local_sources<'tcx>( +pub(crate) fn collect_local_sources<'tcx>( tcx: TyCtxt<'tcx>, src_root: &Path, krate: &clean::Crate, @@ -231,7 +231,7 @@ impl SourceCollector<'_, '_> { /// static HTML tree. Each component in the cleaned path will be passed as an /// argument to `f`. The very last component of the path (ie the file name) will /// be passed to `f` if `keep_filename` is true, and ignored otherwise. -crate fn clean_path<F>(src_root: &Path, p: &Path, keep_filename: bool, mut f: F) +pub(crate) fn clean_path<F>(src_root: &Path, p: &Path, keep_filename: bool, mut f: F) where F: FnMut(&OsStr), { @@ -253,14 +253,14 @@ where } } -crate enum SourceContext { +pub(crate) enum SourceContext { Standalone, Embedded { offset: usize }, } /// Wrapper struct to render the source code of a file. This will do things like /// adding line numbers to the left-hand side. -crate fn print_src( +pub(crate) fn print_src( buf: &mut Buffer, s: &str, edition: Edition, diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 85ca8431d90..75f2b7e3570 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -8,131 +8,134 @@ //! directly written to a `Write` handle. /// The file contents of the main `rustdoc.css` file, responsible for the core layout of the page. -crate static RUSTDOC_CSS: &str = include_str!("static/css/rustdoc.css"); +pub(crate) static RUSTDOC_CSS: &str = include_str!("static/css/rustdoc.css"); /// The file contents of `settings.css`, responsible for the items on the settings page. -crate static SETTINGS_CSS: &str = include_str!("static/css/settings.css"); +pub(crate) static SETTINGS_CSS: &str = include_str!("static/css/settings.css"); /// The file contents of the `noscript.css` file, used in case JS isn't supported or is disabled. -crate static NOSCRIPT_CSS: &str = include_str!("static/css/noscript.css"); +pub(crate) static NOSCRIPT_CSS: &str = include_str!("static/css/noscript.css"); /// The file contents of `normalize.css`, included to even out standard elements between browser /// implementations. -crate static NORMALIZE_CSS: &str = include_str!("static/css/normalize.css"); +pub(crate) static NORMALIZE_CSS: &str = include_str!("static/css/normalize.css"); /// The file contents of `main.js`, which contains the core JavaScript used on documentation pages, /// including search behavior and docblock folding, among others. -crate static MAIN_JS: &str = include_str!("static/js/main.js"); +pub(crate) static MAIN_JS: &str = include_str!("static/js/main.js"); /// The file contents of `search.js`, which contains the search behavior. -crate static SEARCH_JS: &str = include_str!("static/js/search.js"); +pub(crate) static SEARCH_JS: &str = include_str!("static/js/search.js"); /// The file contents of `settings.js`, which contains the JavaScript used to handle the settings /// page. -crate static SETTINGS_JS: &str = include_str!("static/js/settings.js"); +pub(crate) static SETTINGS_JS: &str = include_str!("static/js/settings.js"); /// The file contents of `storage.js`, which contains functionality related to browser Local /// Storage, used to store documentation settings. -crate static STORAGE_JS: &str = include_str!("static/js/storage.js"); +pub(crate) static STORAGE_JS: &str = include_str!("static/js/storage.js"); /// The file contents of `scraped-examples.js`, which contains functionality related to the /// --scrape-examples flag that inserts automatically-found examples of usages of items. -crate static SCRAPE_EXAMPLES_JS: &str = include_str!("static/js/scrape-examples.js"); +pub(crate) static SCRAPE_EXAMPLES_JS: &str = include_str!("static/js/scrape-examples.js"); -crate static SCRAPE_EXAMPLES_HELP_MD: &str = include_str!("static/scrape-examples-help.md"); +pub(crate) static SCRAPE_EXAMPLES_HELP_MD: &str = include_str!("static/scrape-examples-help.md"); /// The file contents of `wheel.svg`, the icon used for the settings button. -crate static WHEEL_SVG: &[u8] = include_bytes!("static/images/wheel.svg"); +pub(crate) static WHEEL_SVG: &[u8] = include_bytes!("static/images/wheel.svg"); /// The file contents of `clipboard.svg`, the icon used for the "copy path" button. -crate static CLIPBOARD_SVG: &[u8] = include_bytes!("static/images/clipboard.svg"); +pub(crate) static CLIPBOARD_SVG: &[u8] = include_bytes!("static/images/clipboard.svg"); /// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox. -crate static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/images/down-arrow.svg"); +pub(crate) static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/images/down-arrow.svg"); /// The file contents of `toggle-minus.svg`, the icon used for opened toggles. -crate static TOGGLE_MINUS_PNG: &[u8] = include_bytes!("static/images/toggle-minus.svg"); +pub(crate) static TOGGLE_MINUS_PNG: &[u8] = include_bytes!("static/images/toggle-minus.svg"); /// The file contents of `toggle-plus.svg`, the icon used for closed toggles. -crate static TOGGLE_PLUS_PNG: &[u8] = include_bytes!("static/images/toggle-plus.svg"); +pub(crate) static TOGGLE_PLUS_PNG: &[u8] = include_bytes!("static/images/toggle-plus.svg"); /// The contents of `COPYRIGHT.txt`, the license listing for files distributed with documentation /// output. -crate static COPYRIGHT: &[u8] = include_bytes!("static/COPYRIGHT.txt"); +pub(crate) static COPYRIGHT: &[u8] = include_bytes!("static/COPYRIGHT.txt"); /// The contents of `LICENSE-APACHE.txt`, the text of the Apache License, version 2.0. -crate static LICENSE_APACHE: &[u8] = include_bytes!("static/LICENSE-APACHE.txt"); +pub(crate) static LICENSE_APACHE: &[u8] = include_bytes!("static/LICENSE-APACHE.txt"); /// The contents of `LICENSE-MIT.txt`, the text of the MIT License. -crate static LICENSE_MIT: &[u8] = include_bytes!("static/LICENSE-MIT.txt"); +pub(crate) static LICENSE_MIT: &[u8] = include_bytes!("static/LICENSE-MIT.txt"); /// The contents of `rust-logo.svg`, the default icon of the documentation. -crate static RUST_LOGO_SVG: &[u8] = include_bytes!("static/images/rust-logo.svg"); +pub(crate) static RUST_LOGO_SVG: &[u8] = include_bytes!("static/images/rust-logo.svg"); /// The default documentation favicons (SVG and PNG fallbacks) -crate static RUST_FAVICON_SVG: &[u8] = include_bytes!("static/images/favicon.svg"); -crate static RUST_FAVICON_PNG_16: &[u8] = include_bytes!("static/images/favicon-16x16.png"); -crate static RUST_FAVICON_PNG_32: &[u8] = include_bytes!("static/images/favicon-32x32.png"); +pub(crate) static RUST_FAVICON_SVG: &[u8] = include_bytes!("static/images/favicon.svg"); +pub(crate) static RUST_FAVICON_PNG_16: &[u8] = include_bytes!("static/images/favicon-16x16.png"); +pub(crate) static RUST_FAVICON_PNG_32: &[u8] = include_bytes!("static/images/favicon-32x32.png"); /// The built-in themes given to every documentation site. -crate mod themes { +pub(crate) mod themes { /// The "light" theme, selected by default when no setting is available. Used as the basis for /// the `--check-theme` functionality. - crate static LIGHT: &str = include_str!("static/css/themes/light.css"); + pub(crate) static LIGHT: &str = include_str!("static/css/themes/light.css"); /// The "dark" theme. - crate static DARK: &str = include_str!("static/css/themes/dark.css"); + pub(crate) static DARK: &str = include_str!("static/css/themes/dark.css"); /// The "ayu" theme. - crate static AYU: &str = include_str!("static/css/themes/ayu.css"); + pub(crate) static AYU: &str = include_str!("static/css/themes/ayu.css"); } /// Files related to the Fira Sans font. -crate mod fira_sans { +pub(crate) mod fira_sans { /// The file `FiraSans-Regular.woff2`, the Regular variant of the Fira Sans font in woff2. - crate static REGULAR: &[u8] = include_bytes!("static/fonts/FiraSans-Regular.woff2"); + pub(crate) static REGULAR: &[u8] = include_bytes!("static/fonts/FiraSans-Regular.woff2"); /// The file `FiraSans-Medium.woff2`, the Medium variant of the Fira Sans font in woff2. - crate static MEDIUM: &[u8] = include_bytes!("static/fonts/FiraSans-Medium.woff2"); + pub(crate) static MEDIUM: &[u8] = include_bytes!("static/fonts/FiraSans-Medium.woff2"); /// The file `FiraSans-LICENSE.txt`, the license text for the Fira Sans font. - crate static LICENSE: &[u8] = include_bytes!("static/fonts/FiraSans-LICENSE.txt"); + pub(crate) static LICENSE: &[u8] = include_bytes!("static/fonts/FiraSans-LICENSE.txt"); } /// Files related to the Source Serif 4 font. -crate mod source_serif_4 { +pub(crate) mod source_serif_4 { /// The file `SourceSerif4-Regular.ttf.woff2`, the Regular variant of the Source Serif 4 font in /// woff2. - crate static REGULAR: &[u8] = include_bytes!("static/fonts/SourceSerif4-Regular.ttf.woff2"); + pub(crate) static REGULAR: &[u8] = + include_bytes!("static/fonts/SourceSerif4-Regular.ttf.woff2"); /// The file `SourceSerif4-Bold.ttf.woff2`, the Bold variant of the Source Serif 4 font in /// woff2. - crate static BOLD: &[u8] = include_bytes!("static/fonts/SourceSerif4-Bold.ttf.woff2"); + pub(crate) static BOLD: &[u8] = include_bytes!("static/fonts/SourceSerif4-Bold.ttf.woff2"); /// The file `SourceSerif4-It.ttf.woff2`, the Italic variant of the Source Serif 4 font in /// woff2. - crate static ITALIC: &[u8] = include_bytes!("static/fonts/SourceSerif4-It.ttf.woff2"); + pub(crate) static ITALIC: &[u8] = include_bytes!("static/fonts/SourceSerif4-It.ttf.woff2"); /// The file `SourceSerif4-LICENSE.txt`, the license text for the Source Serif 4 font. - crate static LICENSE: &[u8] = include_bytes!("static/fonts/SourceSerif4-LICENSE.md"); + pub(crate) static LICENSE: &[u8] = include_bytes!("static/fonts/SourceSerif4-LICENSE.md"); } /// Files related to the Source Code Pro font. -crate mod source_code_pro { +pub(crate) mod source_code_pro { /// The file `SourceCodePro-Regular.ttf.woff2`, the Regular variant of the Source Code Pro font /// in woff2. - crate static REGULAR: &[u8] = include_bytes!("static/fonts/SourceCodePro-Regular.ttf.woff2"); + pub(crate) static REGULAR: &[u8] = + include_bytes!("static/fonts/SourceCodePro-Regular.ttf.woff2"); /// The file `SourceCodePro-Semibold.ttf.woff2`, the Semibold variant of the Source Code Pro /// font in woff2. - crate static SEMIBOLD: &[u8] = include_bytes!("static/fonts/SourceCodePro-Semibold.ttf.woff2"); + pub(crate) static SEMIBOLD: &[u8] = + include_bytes!("static/fonts/SourceCodePro-Semibold.ttf.woff2"); /// The file `SourceCodePro-It.ttf.woff2`, the Italic variant of the Source Code Pro font in /// woff2. - crate static ITALIC: &[u8] = include_bytes!("static/fonts/SourceCodePro-It.ttf.woff2"); + pub(crate) static ITALIC: &[u8] = include_bytes!("static/fonts/SourceCodePro-It.ttf.woff2"); /// The file `SourceCodePro-LICENSE.txt`, the license text of the Source Code Pro font. - crate static LICENSE: &[u8] = include_bytes!("static/fonts/SourceCodePro-LICENSE.txt"); + pub(crate) static LICENSE: &[u8] = include_bytes!("static/fonts/SourceCodePro-LICENSE.txt"); } /// Files related to the Nanum Barun Gothic font. @@ -150,16 +153,16 @@ crate mod source_code_pro { /// --unicodes=U+AC00-D7AF,U+1100-11FF,U+3130-318F,U+A960-A97F,U+D7B0-D7FF \ /// --output-file=NanumBarunGothic.ttf.woff2 --flavor=woff2 /// ``` -crate mod nanum_barun_gothic { +pub(crate) mod nanum_barun_gothic { /// The file `NanumBarunGothic.ttf.woff2`, the Regular variant of the Nanum Barun Gothic font. - crate static REGULAR: &[u8] = include_bytes!("static/fonts/NanumBarunGothic.ttf.woff2"); + pub(crate) static REGULAR: &[u8] = include_bytes!("static/fonts/NanumBarunGothic.ttf.woff2"); /// The file `NanumBarunGothic-LICENSE.txt`, the license text of the Nanum Barun Gothic font. - crate static LICENSE: &[u8] = include_bytes!("static/fonts/NanumBarunGothic-LICENSE.txt"); + pub(crate) static LICENSE: &[u8] = include_bytes!("static/fonts/NanumBarunGothic-LICENSE.txt"); } /// Files related to the sidebar in rustdoc sources. -crate mod sidebar { +pub(crate) mod sidebar { /// File script to handle sidebar. - crate static SOURCE_SCRIPT: &str = include_str!("static/js/source-script.js"); + pub(crate) static SOURCE_SCRIPT: &str = include_str!("static/js/source-script.js"); } diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs index c55f2459a9c..07e33052aa7 100644 --- a/src/librustdoc/html/toc.rs +++ b/src/librustdoc/html/toc.rs @@ -2,7 +2,7 @@ /// A (recursive) table of contents #[derive(Debug, PartialEq)] -crate struct Toc { +pub(crate) struct Toc { /// The levels are strictly decreasing, i.e. /// /// `entries[0].level >= entries[1].level >= ...` @@ -26,7 +26,7 @@ impl Toc { } #[derive(Debug, PartialEq)] -crate struct TocEntry { +pub(crate) struct TocEntry { level: u32, sec_number: String, name: String, @@ -36,7 +36,7 @@ crate struct TocEntry { /// Progressive construction of a table of contents. #[derive(PartialEq)] -crate struct TocBuilder { +pub(crate) struct TocBuilder { top_level: Toc, /// The current hierarchy of parent headings, the levels are /// strictly increasing (i.e., `chain[0].level < chain[1].level < @@ -50,12 +50,12 @@ crate struct TocBuilder { } impl TocBuilder { - crate fn new() -> TocBuilder { + pub(crate) fn new() -> TocBuilder { TocBuilder { top_level: Toc { entries: Vec::new() }, chain: Vec::new() } } /// Converts into a true `Toc` struct. - crate fn into_toc(mut self) -> Toc { + pub(crate) fn into_toc(mut self) -> Toc { // we know all levels are >= 1. self.fold_until(0); self.top_level @@ -115,7 +115,7 @@ impl TocBuilder { /// Push a level `level` heading into the appropriate place in the /// hierarchy, returning a string containing the section number in /// `<num>.<num>.<num>` format. - crate fn push(&mut self, level: u32, name: String, id: String) -> &str { + pub(crate) fn push(&mut self, level: u32, name: String, id: String) -> &str { assert!(level >= 1); // collapse all previous sections into their parents until we @@ -177,7 +177,7 @@ impl Toc { } v.push_str("</ul>"); } - crate fn print(&self) -> String { + pub(crate) fn print(&self) -> String { let mut v = String::new(); self.print_inner(&mut v); v diff --git a/src/librustdoc/html/url_parts_builder.rs b/src/librustdoc/html/url_parts_builder.rs index 2bb78aa7dc9..1e6af6af63c 100644 --- a/src/librustdoc/html/url_parts_builder.rs +++ b/src/librustdoc/html/url_parts_builder.rs @@ -8,14 +8,14 @@ use rustc_span::Symbol; /// This type is a wrapper around the final `String` buffer, /// but its API is like that of a `Vec` of URL components. #[derive(Debug)] -crate struct UrlPartsBuilder { +pub(crate) struct UrlPartsBuilder { buf: String, } impl UrlPartsBuilder { /// Create an empty buffer. #[allow(dead_code)] - crate fn new() -> Self { + pub(crate) fn new() -> Self { Self { buf: String::new() } } @@ -43,7 +43,7 @@ impl UrlPartsBuilder { /// builder.push_front("nightly"); /// assert_eq!(builder.finish(), "nightly/core/str"); /// ``` - crate fn singleton(part: &str) -> Self { + pub(crate) fn singleton(part: &str) -> Self { Self { buf: part.to_owned() } } @@ -60,7 +60,7 @@ impl UrlPartsBuilder { /// builder.push("struct.Bytes.html"); /// assert_eq!(builder.finish(), "core/str/struct.Bytes.html"); /// ``` - crate fn push(&mut self, part: &str) { + pub(crate) fn push(&mut self, part: &str) { if !self.buf.is_empty() { self.buf.push('/'); } @@ -80,7 +80,7 @@ impl UrlPartsBuilder { /// builder.push_fmt(format_args!("{}.{}.html", "struct", "Bytes")); /// assert_eq!(builder.finish(), "core/str/struct.Bytes.html"); /// ``` - crate fn push_fmt(&mut self, args: fmt::Arguments<'_>) { + pub(crate) fn push_fmt(&mut self, args: fmt::Arguments<'_>) { if !self.buf.is_empty() { self.buf.push('/'); } @@ -101,7 +101,7 @@ impl UrlPartsBuilder { /// builder.push("struct.Bytes.html"); /// assert_eq!(builder.finish(), "nightly/core/str/struct.Bytes.html"); /// ``` - crate fn push_front(&mut self, part: &str) { + pub(crate) fn push_front(&mut self, part: &str) { let is_empty = self.buf.is_empty(); self.buf.reserve(part.len() + if !is_empty { 1 } else { 0 }); self.buf.insert_str(0, part); @@ -111,7 +111,7 @@ impl UrlPartsBuilder { } /// Get the final `String` buffer. - crate fn finish(self) -> String { + pub(crate) fn finish(self) -> String { self.buf } } @@ -134,7 +134,7 @@ const AVG_PART_LENGTH: usize = 8; /// /// **Note:** This is only to be used with, e.g., [`String::with_capacity()`]; /// the return value is just a rough estimate. -crate const fn estimate_item_path_byte_length(segment_count: usize) -> usize { +pub(crate) const fn estimate_item_path_byte_length(segment_count: usize) -> usize { AVG_PART_LENGTH * segment_count } diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 412387313dc..6f6f7e375a4 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -91,11 +91,11 @@ impl JsonRenderer<'_> { } } -crate trait FromWithTcx<T> { +pub(crate) trait FromWithTcx<T> { fn from_tcx(f: T, tcx: TyCtxt<'_>) -> Self; } -crate trait IntoWithTcx<T> { +pub(crate) trait IntoWithTcx<T> { fn into_tcx(self, tcx: TyCtxt<'_>) -> T; } @@ -108,7 +108,7 @@ where } } -crate fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation { +pub(crate) fn from_deprecation(deprecation: rustc_attr::Deprecation) -> Deprecation { #[rustfmt::skip] let rustc_attr::Deprecation { since, note, is_since_rustc_version: _, suggestion: _ } = deprecation; Deprecation { since: since.map(|s| s.to_string()), note: note.map(|s| s.to_string()) } @@ -173,7 +173,7 @@ impl FromWithTcx<clean::TypeBindingKind> for TypeBindingKind { } } -crate fn from_item_id(item_id: ItemId) -> Id { +pub(crate) fn from_item_id(item_id: ItemId) -> Id { struct DisplayDefId(DefId); impl fmt::Display for DisplayDefId { @@ -272,7 +272,7 @@ impl FromWithTcx<clean::Union> for Union { } } -crate fn from_ctor_kind(struct_type: CtorKind) -> StructType { +pub(crate) fn from_ctor_kind(struct_type: CtorKind) -> StructType { match struct_type { CtorKind::Fictive => StructType::Plain, CtorKind::Fn => StructType::Tuple, @@ -280,7 +280,7 @@ crate fn from_ctor_kind(struct_type: CtorKind) -> StructType { } } -crate fn from_fn_header(header: &rustc_hir::FnHeader) -> Header { +pub(crate) fn from_fn_header(header: &rustc_hir::FnHeader) -> Header { Header { async_: header.is_async(), const_: header.is_const(), @@ -390,7 +390,9 @@ impl FromWithTcx<clean::GenericBound> for GenericBound { } } -crate fn from_trait_bound_modifier(modifier: rustc_hir::TraitBoundModifier) -> TraitBoundModifier { +pub(crate) fn from_trait_bound_modifier( + modifier: rustc_hir::TraitBoundModifier, +) -> TraitBoundModifier { use rustc_hir::TraitBoundModifier::*; match modifier { None => TraitBoundModifier::None, @@ -554,7 +556,7 @@ impl FromWithTcx<clean::Impl> for Impl { } } -crate fn from_function( +pub(crate) fn from_function( function: clean::Function, header: rustc_hir::FnHeader, tcx: TyCtxt<'_>, @@ -567,7 +569,7 @@ crate fn from_function( } } -crate fn from_function_method( +pub(crate) fn from_function_method( function: clean::Function, has_body: bool, header: rustc_hir::FnHeader, @@ -658,7 +660,7 @@ impl FromWithTcx<clean::ProcMacro> for ProcMacro { } } -crate fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind { +pub(crate) fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind { use rustc_span::hygiene::MacroKind::*; match kind { Bang => MacroKind::Bang, diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index e6e5bba7f00..08f61056d85 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -29,7 +29,7 @@ use crate::json::conversions::{from_item_id, IntoWithTcx}; use crate::{clean, try_err}; #[derive(Clone)] -crate struct JsonRenderer<'tcx> { +pub(crate) struct JsonRenderer<'tcx> { tcx: TyCtxt<'tcx>, /// A mapping of IDs that contains all local items for this crate which gets output as a top /// level field of the JSON blob. diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index dfc70237821..61acf2de90d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -13,7 +13,6 @@ #![feature(let_else)] #![feature(nll)] #![feature(test)] -#![feature(crate_visibility_modifier)] #![feature(never_type)] #![feature(once_cell)] #![feature(type_ascription)] @@ -121,7 +120,7 @@ mod formats; // used by the error-index generator, so it needs to be public pub mod html; mod json; -crate mod lint; +pub(crate) mod lint; mod markdown; mod passes; mod scrape_examples; diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 49d8d7fb7fb..08a1a868521 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -169,7 +169,7 @@ declare_rustdoc_lint! { "codeblock could not be parsed as valid Rust or is empty" } -crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| { +pub(crate) static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| { vec![ BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS, @@ -183,7 +183,7 @@ crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| { ] }); -crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { +pub(crate) fn register_lints(_sess: &Session, lint_store: &mut LintStore) { lint_store.register_lints(&**RUSTDOC_LINTS); lint_store.register_group( true, diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 62e42b783e9..0b557ef244e 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -36,7 +36,7 @@ fn extract_leading_metadata(s: &str) -> (Vec<&str>, &str) { /// Render `input` (e.g., "foo.md") into an HTML file in `output` /// (e.g., output = "bar" => "bar/foo.html"). -crate fn render<P: AsRef<Path>>( +pub(crate) fn render<P: AsRef<Path>>( input: P, options: RenderOptions, edition: Edition, @@ -127,7 +127,7 @@ crate fn render<P: AsRef<Path>>( } /// Runs any tests/code examples in the markdown file `input`. -crate fn test(options: Options) -> Result<(), String> { +pub(crate) fn test(options: Options) -> Result<(), String> { let input_str = read_to_string(&options.input) .map_err(|err| format!("{}: {}", options.input.display(), err))?; let mut opts = GlobalTestOptions::default(); diff --git a/src/librustdoc/passes/bare_urls.rs b/src/librustdoc/passes/bare_urls.rs index 1839a35a8b1..e9e810658ef 100644 --- a/src/librustdoc/passes/bare_urls.rs +++ b/src/librustdoc/passes/bare_urls.rs @@ -12,7 +12,7 @@ use rustc_errors::Applicability; use std::lazy::SyncLazy; use std::mem; -crate const CHECK_BARE_URLS: Pass = Pass { +pub(crate) const CHECK_BARE_URLS: Pass = Pass { name: "check-bare-urls", run: check_bare_urls, description: "detects URLs that are not hyperlinks", @@ -54,7 +54,7 @@ impl<'a, 'tcx> BareUrlsLinter<'a, 'tcx> { } } -crate fn check_bare_urls(krate: Crate, cx: &mut DocContext<'_>) -> Crate { +pub(crate) fn check_bare_urls(krate: Crate, cx: &mut DocContext<'_>) -> Crate { BareUrlsLinter { cx }.visit_crate(&krate); krate } diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs index 0d40ef4c600..3981d49a8a9 100644 --- a/src/librustdoc/passes/calculate_doc_coverage.rs +++ b/src/librustdoc/passes/calculate_doc_coverage.rs @@ -16,7 +16,7 @@ use serde::Serialize; use std::collections::BTreeMap; use std::ops; -crate const CALCULATE_DOC_COVERAGE: Pass = Pass { +pub(crate) const CALCULATE_DOC_COVERAGE: Pass = Pass { name: "calculate-doc-coverage", run: calculate_doc_coverage, description: "counts the number of items with and without documentation", diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs index 23d947c4d72..8a50938f82b 100644 --- a/src/librustdoc/passes/check_code_block_syntax.rs +++ b/src/librustdoc/passes/check_code_block_syntax.rs @@ -14,13 +14,16 @@ use crate::html::markdown::{self, RustCodeBlock}; use crate::passes::Pass; use crate::visit::DocVisitor; -crate const CHECK_CODE_BLOCK_SYNTAX: Pass = Pass { +pub(crate) const CHECK_CODE_BLOCK_SYNTAX: Pass = Pass { name: "check-code-block-syntax", run: check_code_block_syntax, description: "validates syntax inside Rust code blocks", }; -crate fn check_code_block_syntax(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate { +pub(crate) fn check_code_block_syntax( + krate: clean::Crate, + cx: &mut DocContext<'_>, +) -> clean::Crate { SyntaxChecker { cx }.visit_crate(&krate); krate } diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs index 80a2683fde7..0fb0c7dbdd7 100644 --- a/src/librustdoc/passes/check_doc_test_visibility.rs +++ b/src/librustdoc/passes/check_doc_test_visibility.rs @@ -17,7 +17,7 @@ use rustc_middle::lint::LintLevelSource; use rustc_session::lint; use rustc_span::symbol::sym; -crate const CHECK_DOC_TEST_VISIBILITY: Pass = Pass { +pub(crate) const CHECK_DOC_TEST_VISIBILITY: Pass = Pass { name: "check_doc_test_visibility", run: check_doc_test_visibility, description: "run various visibility-related lints on doctests", @@ -27,7 +27,7 @@ struct DocTestVisibilityLinter<'a, 'tcx> { cx: &'a mut DocContext<'tcx>, } -crate fn check_doc_test_visibility(krate: Crate, cx: &mut DocContext<'_>) -> Crate { +pub(crate) fn check_doc_test_visibility(krate: Crate, cx: &mut DocContext<'_>) -> Crate { let mut coll = DocTestVisibilityLinter { cx }; coll.visit_crate(&krate); krate @@ -55,7 +55,7 @@ impl crate::doctest::Tester for Tests { } } -crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool { +pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool { if !cx.cache.access_levels.is_public(item.item_id.expect_def_id()) || matches!( *item.kind, @@ -106,7 +106,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo level != lint::Level::Allow || matches!(source, LintLevelSource::Default) } -crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { +pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { let Some(hir_id) = DocContext::as_local_hir_id(cx.tcx, item.item_id) else { // If non-local, no need to check anything. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 95ba4ce5b06..ea0f5102539 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -33,9 +33,9 @@ use crate::passes::Pass; use crate::visit::DocVisitor; mod early; -crate use early::early_resolve_intra_doc_links; +pub(crate) use early::early_resolve_intra_doc_links; -crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass { +pub(crate) const COLLECT_INTRA_DOC_LINKS: Pass = Pass { name: "collect-intra-doc-links", run: collect_intra_doc_links, description: "resolves intra-doc links", @@ -219,14 +219,14 @@ enum MalformedGenerics { } #[derive(Clone, Debug, Hash, PartialEq, Eq)] -crate enum UrlFragment { +pub(crate) enum UrlFragment { Item(ItemFragment), UserWritten(String), } impl UrlFragment { /// Render the fragment, including the leading `#`. - crate fn render(&self, s: &mut String, tcx: TyCtxt<'_>) -> std::fmt::Result { + pub(crate) fn render(&self, s: &mut String, tcx: TyCtxt<'_>) -> std::fmt::Result { match self { UrlFragment::Item(frag) => frag.render(s, tcx), UrlFragment::UserWritten(raw) => write!(s, "#{}", raw), @@ -235,10 +235,10 @@ impl UrlFragment { } #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] -crate struct ItemFragment(FragmentKind, DefId); +pub(crate) struct ItemFragment(FragmentKind, DefId); #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] -crate enum FragmentKind { +pub(crate) enum FragmentKind { Method, TyMethod, AssociatedConstant, @@ -276,7 +276,7 @@ impl FragmentKind { impl ItemFragment { /// Render the fragment, including the leading `#`. - crate fn render(&self, s: &mut String, tcx: TyCtxt<'_>) -> std::fmt::Result { + pub(crate) fn render(&self, s: &mut String, tcx: TyCtxt<'_>) -> std::fmt::Result { write!(s, "#")?; match *self { ItemFragment(kind, def_id) => { @@ -954,7 +954,10 @@ struct PreprocessingInfo { } // Not a typedef to avoid leaking several private structures from this module. -crate struct PreprocessedMarkdownLink(Result<PreprocessingInfo, PreprocessingError>, MarkdownLink); +pub(crate) struct PreprocessedMarkdownLink( + Result<PreprocessingInfo, PreprocessingError>, + MarkdownLink, +); /// Returns: /// - `None` if the link should be ignored. diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs index 6f9912e71c5..a38c44bc888 100644 --- a/src/librustdoc/passes/collect_intra_doc_links/early.rs +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -21,7 +21,7 @@ use rustc_span::{Symbol, SyntaxContext}; use std::collections::hash_map::Entry; use std::mem; -crate fn early_resolve_intra_doc_links( +pub(crate) fn early_resolve_intra_doc_links( resolver: &mut Resolver<'_>, sess: &Session, krate: &ast::Crate, diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 3b7ca7dc3c5..aa7028247be 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -12,13 +12,13 @@ use rustc_hir::def_id::DefId; use rustc_middle::ty::DefIdTree; use rustc_span::symbol::sym; -crate const COLLECT_TRAIT_IMPLS: Pass = Pass { +pub(crate) const COLLECT_TRAIT_IMPLS: Pass = Pass { name: "collect-trait-impls", run: collect_trait_impls, description: "retrieves trait impls for items in the crate", }; -crate fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate { +pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> Crate { let synth_impls = cx.sess().time("collect_synthetic_impls", || { let mut synth = SyntheticImplCollector { cx, impls: Vec::new() }; synth.visit_crate(&krate); diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index 044f224e788..3012db0cad6 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -11,7 +11,7 @@ use std::iter::Peekable; use std::ops::Range; use std::str::CharIndices; -crate const CHECK_INVALID_HTML_TAGS: Pass = Pass { +pub(crate) const CHECK_INVALID_HTML_TAGS: Pass = Pass { name: "check-invalid-html-tags", run: check_invalid_html_tags, description: "detects invalid HTML tags in doc comments", @@ -21,7 +21,7 @@ struct InvalidHtmlTagsLinter<'a, 'tcx> { cx: &'a mut DocContext<'tcx>, } -crate fn check_invalid_html_tags(krate: Crate, cx: &mut DocContext<'_>) -> Crate { +pub(crate) fn check_invalid_html_tags(krate: Crate, cx: &mut DocContext<'_>) -> Crate { if cx.tcx.sess.is_nightly_build() { let mut coll = InvalidHtmlTagsLinter { cx }; coll.visit_crate(&krate); diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 97a436c7500..f81b38ea395 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -10,61 +10,61 @@ use crate::clean::{self, DocFragmentKind}; use crate::core::DocContext; mod stripper; -crate use stripper::*; +pub(crate) use stripper::*; mod bare_urls; -crate use self::bare_urls::CHECK_BARE_URLS; +pub(crate) use self::bare_urls::CHECK_BARE_URLS; mod strip_hidden; -crate use self::strip_hidden::STRIP_HIDDEN; +pub(crate) use self::strip_hidden::STRIP_HIDDEN; mod strip_private; -crate use self::strip_private::STRIP_PRIVATE; +pub(crate) use self::strip_private::STRIP_PRIVATE; mod strip_priv_imports; -crate use self::strip_priv_imports::STRIP_PRIV_IMPORTS; +pub(crate) use self::strip_priv_imports::STRIP_PRIV_IMPORTS; mod propagate_doc_cfg; -crate use self::propagate_doc_cfg::PROPAGATE_DOC_CFG; +pub(crate) use self::propagate_doc_cfg::PROPAGATE_DOC_CFG; -crate mod collect_intra_doc_links; -crate use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS; +pub(crate) mod collect_intra_doc_links; +pub(crate) use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS; mod check_doc_test_visibility; -crate use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY; +pub(crate) use self::check_doc_test_visibility::CHECK_DOC_TEST_VISIBILITY; mod collect_trait_impls; -crate use self::collect_trait_impls::COLLECT_TRAIT_IMPLS; +pub(crate) use self::collect_trait_impls::COLLECT_TRAIT_IMPLS; mod check_code_block_syntax; -crate use self::check_code_block_syntax::CHECK_CODE_BLOCK_SYNTAX; +pub(crate) use self::check_code_block_syntax::CHECK_CODE_BLOCK_SYNTAX; mod calculate_doc_coverage; -crate use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE; +pub(crate) use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE; mod html_tags; -crate use self::html_tags::CHECK_INVALID_HTML_TAGS; +pub(crate) use self::html_tags::CHECK_INVALID_HTML_TAGS; /// A single pass over the cleaned documentation. /// /// Runs in the compiler context, so it has access to types and traits and the like. #[derive(Copy, Clone)] -crate struct Pass { - crate name: &'static str, - crate run: fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate, - crate description: &'static str, +pub(crate) struct Pass { + pub(crate) name: &'static str, + pub(crate) run: fn(clean::Crate, &mut DocContext<'_>) -> clean::Crate, + pub(crate) description: &'static str, } /// In a list of passes, a pass that may or may not need to be run depending on options. #[derive(Copy, Clone)] -crate struct ConditionalPass { - crate pass: Pass, - crate condition: Condition, +pub(crate) struct ConditionalPass { + pub(crate) pass: Pass, + pub(crate) condition: Condition, } /// How to decide whether to run a conditional pass. #[derive(Copy, Clone)] -crate enum Condition { +pub(crate) enum Condition { Always, /// When `--document-private-items` is passed. WhenDocumentPrivate, @@ -75,7 +75,7 @@ crate enum Condition { } /// The full list of passes. -crate const PASSES: &[Pass] = &[ +pub(crate) const PASSES: &[Pass] = &[ CHECK_DOC_TEST_VISIBILITY, STRIP_HIDDEN, STRIP_PRIVATE, @@ -90,7 +90,7 @@ crate const PASSES: &[Pass] = &[ ]; /// The list of passes run by default. -crate const DEFAULT_PASSES: &[ConditionalPass] = &[ +pub(crate) const DEFAULT_PASSES: &[ConditionalPass] = &[ ConditionalPass::always(COLLECT_TRAIT_IMPLS), ConditionalPass::always(CHECK_DOC_TEST_VISIBILITY), ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden), @@ -104,29 +104,29 @@ crate const DEFAULT_PASSES: &[ConditionalPass] = &[ ]; /// The list of default passes run when `--doc-coverage` is passed to rustdoc. -crate const COVERAGE_PASSES: &[ConditionalPass] = &[ +pub(crate) const COVERAGE_PASSES: &[ConditionalPass] = &[ ConditionalPass::new(STRIP_HIDDEN, WhenNotDocumentHidden), ConditionalPass::new(STRIP_PRIVATE, WhenNotDocumentPrivate), ConditionalPass::always(CALCULATE_DOC_COVERAGE), ]; impl ConditionalPass { - crate const fn always(pass: Pass) -> Self { + pub(crate) const fn always(pass: Pass) -> Self { Self::new(pass, Always) } - crate const fn new(pass: Pass, condition: Condition) -> Self { + pub(crate) const fn new(pass: Pass, condition: Condition) -> Self { ConditionalPass { pass, condition } } } /// Returns the given default set of passes. -crate fn defaults(show_coverage: bool) -> &'static [ConditionalPass] { +pub(crate) fn defaults(show_coverage: bool) -> &'static [ConditionalPass] { if show_coverage { COVERAGE_PASSES } else { DEFAULT_PASSES } } /// Returns a span encompassing all the given attributes. -crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> { +pub(crate) fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> { if attrs.doc_strings.is_empty() { return None; } @@ -143,7 +143,7 @@ crate fn span_of_attrs(attrs: &clean::Attributes) -> Option<Span> { /// This method will return `None` if we cannot construct a span from the source map or if the /// attributes are not all sugared doc comments. It's difficult to calculate the correct span in /// that case due to escaping and other source features. -crate fn source_span_for_markdown_range( +pub(crate) fn source_span_for_markdown_range( tcx: TyCtxt<'_>, markdown: &str, md_range: &Range<usize>, diff --git a/src/librustdoc/passes/propagate_doc_cfg.rs b/src/librustdoc/passes/propagate_doc_cfg.rs index d3df2d2794b..0c5d8365518 100644 --- a/src/librustdoc/passes/propagate_doc_cfg.rs +++ b/src/librustdoc/passes/propagate_doc_cfg.rs @@ -7,13 +7,13 @@ use crate::core::DocContext; use crate::fold::DocFolder; use crate::passes::Pass; -crate const PROPAGATE_DOC_CFG: Pass = Pass { +pub(crate) const PROPAGATE_DOC_CFG: Pass = Pass { name: "propagate-doc-cfg", run: propagate_doc_cfg, description: "propagates `#[doc(cfg(...))]` to child items", }; -crate fn propagate_doc_cfg(cr: Crate, _: &mut DocContext<'_>) -> Crate { +pub(crate) fn propagate_doc_cfg(cr: Crate, _: &mut DocContext<'_>) -> Crate { CfgPropagator { parent_cfg: None }.fold_crate(cr) } diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index 6b052185bbd..ab5526e0612 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -8,14 +8,14 @@ use crate::core::DocContext; use crate::fold::{strip_item, DocFolder}; use crate::passes::{ImplStripper, Pass}; -crate const STRIP_HIDDEN: Pass = Pass { +pub(crate) const STRIP_HIDDEN: Pass = Pass { name: "strip-hidden", run: strip_hidden, description: "strips all `#[doc(hidden)]` items from the output", }; /// Strip items marked `#[doc(hidden)]` -crate fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate { +pub(crate) fn strip_hidden(krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate { let mut retained = ItemIdSet::default(); // strip all #[doc(hidden)] items diff --git a/src/librustdoc/passes/strip_priv_imports.rs b/src/librustdoc/passes/strip_priv_imports.rs index 21ce9ae7a28..85be8fa109a 100644 --- a/src/librustdoc/passes/strip_priv_imports.rs +++ b/src/librustdoc/passes/strip_priv_imports.rs @@ -5,12 +5,12 @@ use crate::core::DocContext; use crate::fold::DocFolder; use crate::passes::{ImportStripper, Pass}; -crate const STRIP_PRIV_IMPORTS: Pass = Pass { +pub(crate) const STRIP_PRIV_IMPORTS: Pass = Pass { name: "strip-priv-imports", run: strip_priv_imports, description: "strips all private import statements (`use`, `extern crate`) from a crate", }; -crate fn strip_priv_imports(krate: clean::Crate, _: &mut DocContext<'_>) -> clean::Crate { +pub(crate) fn strip_priv_imports(krate: clean::Crate, _: &mut DocContext<'_>) -> clean::Crate { ImportStripper.fold_crate(krate) } diff --git a/src/librustdoc/passes/strip_private.rs b/src/librustdoc/passes/strip_private.rs index ef7e768a511..6c94912bc53 100644 --- a/src/librustdoc/passes/strip_private.rs +++ b/src/librustdoc/passes/strip_private.rs @@ -5,7 +5,7 @@ use crate::core::DocContext; use crate::fold::DocFolder; use crate::passes::{ImplStripper, ImportStripper, Pass, Stripper}; -crate const STRIP_PRIVATE: Pass = Pass { +pub(crate) const STRIP_PRIVATE: Pass = Pass { name: "strip-private", run: strip_private, description: "strips all private items from a crate which cannot be seen externally, \ @@ -14,7 +14,7 @@ crate const STRIP_PRIVATE: Pass = Pass { /// Strip private items from the point of view of a crate or externally from a /// crate, specified by the `xcrate` flag. -crate fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate { +pub(crate) fn strip_private(mut krate: clean::Crate, cx: &mut DocContext<'_>) -> clean::Crate { // This stripper collects all *retained* nodes. let mut retained = ItemIdSet::default(); diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index 6a522bdacf9..d5db919dc4b 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -7,10 +7,10 @@ use crate::clean::{self, Item, ItemIdSet}; use crate::fold::{strip_item, DocFolder}; use crate::formats::cache::Cache; -crate struct Stripper<'a> { - crate retained: &'a mut ItemIdSet, - crate access_levels: &'a AccessLevels<DefId>, - crate update_retained: bool, +pub(crate) struct Stripper<'a> { + pub(crate) retained: &'a mut ItemIdSet, + pub(crate) access_levels: &'a AccessLevels<DefId>, + pub(crate) update_retained: bool, } impl<'a> DocFolder for Stripper<'a> { @@ -116,9 +116,9 @@ impl<'a> DocFolder for Stripper<'a> { } /// This stripper discards all impls which reference stripped items -crate struct ImplStripper<'a> { - crate retained: &'a ItemIdSet, - crate cache: &'a Cache, +pub(crate) struct ImplStripper<'a> { + pub(crate) retained: &'a ItemIdSet, + pub(crate) cache: &'a Cache, } impl<'a> DocFolder for ImplStripper<'a> { @@ -159,7 +159,7 @@ impl<'a> DocFolder for ImplStripper<'a> { } /// This stripper discards all private import statements (`use`, `extern crate`) -crate struct ImportStripper; +pub(crate) struct ImportStripper; impl DocFolder for ImportStripper { fn fold_item(&mut self, i: Item) -> Option<Item> { diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index e0aed1e1ed4..0fa492af1ad 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -31,14 +31,14 @@ use std::fs; use std::path::PathBuf; #[derive(Debug, Clone)] -crate struct ScrapeExamplesOptions { +pub(crate) struct ScrapeExamplesOptions { output_path: PathBuf, target_crates: Vec<String>, - crate scrape_tests: bool, + pub(crate) scrape_tests: bool, } impl ScrapeExamplesOptions { - crate fn new( + pub(crate) fn new( matches: &getopts::Matches, diag: &rustc_errors::Handler, ) -> Result<Option<Self>, i32> { @@ -65,9 +65,9 @@ impl ScrapeExamplesOptions { } #[derive(Encodable, Decodable, Debug, Clone)] -crate struct SyntaxRange { - crate byte_span: (u32, u32), - crate line_span: (usize, usize), +pub(crate) struct SyntaxRange { + pub(crate) byte_span: (u32, u32), + pub(crate) line_span: (usize, usize), } impl SyntaxRange { @@ -83,10 +83,10 @@ impl SyntaxRange { } #[derive(Encodable, Decodable, Debug, Clone)] -crate struct CallLocation { - crate call_expr: SyntaxRange, - crate call_ident: SyntaxRange, - crate enclosing_item: SyntaxRange, +pub(crate) struct CallLocation { + pub(crate) call_expr: SyntaxRange, + pub(crate) call_ident: SyntaxRange, + pub(crate) enclosing_item: SyntaxRange, } impl CallLocation { @@ -105,15 +105,15 @@ impl CallLocation { } #[derive(Encodable, Decodable, Debug, Clone)] -crate struct CallData { - crate locations: Vec<CallLocation>, - crate url: String, - crate display_name: String, - crate edition: Edition, +pub(crate) struct CallData { + pub(crate) locations: Vec<CallLocation>, + pub(crate) url: String, + pub(crate) display_name: String, + pub(crate) edition: Edition, } -crate type FnCallLocations = FxHashMap<PathBuf, CallData>; -crate type AllCallLocations = FxHashMap<DefPathHash, FnCallLocations>; +pub(crate) type FnCallLocations = FxHashMap<PathBuf, CallData>; +pub(crate) type AllCallLocations = FxHashMap<DefPathHash, FnCallLocations>; /// Visitor for traversing a crate and finding instances of function calls. struct FindCalls<'a, 'tcx> { @@ -270,7 +270,7 @@ where } } -crate fn run( +pub(crate) fn run( krate: clean::Crate, mut renderopts: config::RenderOptions, cache: formats::cache::Cache, @@ -328,7 +328,7 @@ crate fn run( } // Note: the Handler must be passed in explicitly because sess isn't available while parsing options -crate fn load_call_locations( +pub(crate) fn load_call_locations( with_examples: Vec<String>, diag: &rustc_errors::Handler, ) -> Result<AllCallLocations, i32> { diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 7c19865b6d7..20258c3b1dc 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -9,9 +9,9 @@ use rustc_errors::Handler; mod tests; #[derive(Debug, Clone, Eq)] -crate struct CssPath { - crate name: String, - crate children: FxHashSet<CssPath>, +pub(crate) struct CssPath { + pub(crate) name: String, + pub(crate) children: FxHashSet<CssPath>, } // This PartialEq implementation IS NOT COMMUTATIVE!!! @@ -214,7 +214,7 @@ fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> FxHashSet<CssPath> { paths.iter().cloned().collect() } -crate fn load_css_paths(v: &[u8]) -> CssPath { +pub(crate) fn load_css_paths(v: &[u8]) -> CssPath { let events = load_css_events(v); let mut pos = 0; @@ -223,7 +223,7 @@ crate fn load_css_paths(v: &[u8]) -> CssPath { parent } -crate fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>) { +pub(crate) fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>) { if against.name == other.name { for child in &against.children { let mut found = false; @@ -250,7 +250,7 @@ crate fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String> } } -crate fn test_theme_against<P: AsRef<Path>>( +pub(crate) fn test_theme_against<P: AsRef<Path>>( f: &P, against: &CssPath, diag: &Handler, diff --git a/src/librustdoc/visit.rs b/src/librustdoc/visit.rs index ef502926742..fa8be9a97c5 100644 --- a/src/librustdoc/visit.rs +++ b/src/librustdoc/visit.rs @@ -1,6 +1,6 @@ use crate::clean::*; -crate trait DocVisitor: Sized { +pub(crate) trait DocVisitor: Sized { fn visit_item(&mut self, item: &Item) { self.visit_item_recur(item) } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 75276d18fe5..519ace7b89a 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -21,22 +21,22 @@ use crate::core; /// This module is used to store stuff from Rust's AST in a more convenient /// manner (and with prettier names) before cleaning. #[derive(Debug)] -crate struct Module<'hir> { - crate name: Symbol, - crate where_inner: Span, - crate mods: Vec<Module<'hir>>, - crate id: hir::HirId, +pub(crate) struct Module<'hir> { + pub(crate) name: Symbol, + pub(crate) where_inner: Span, + pub(crate) mods: Vec<Module<'hir>>, + pub(crate) id: hir::HirId, // (item, renamed) - crate items: Vec<(&'hir hir::Item<'hir>, Option<Symbol>)>, - crate foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>)>, + pub(crate) items: Vec<(&'hir hir::Item<'hir>, Option<Symbol>)>, + pub(crate) foreigns: Vec<(&'hir hir::ForeignItem<'hir>, Option<Symbol>)>, } impl Module<'_> { - crate fn new(name: Symbol, id: hir::HirId, where_inner: Span) -> Self { + pub(crate) fn new(name: Symbol, id: hir::HirId, where_inner: Span) -> Self { Module { name, id, where_inner, mods: Vec::new(), items: Vec::new(), foreigns: Vec::new() } } - crate fn where_outer(&self, tcx: TyCtxt<'_>) -> Span { + pub(crate) fn where_outer(&self, tcx: TyCtxt<'_>) -> Span { tcx.hir().span(self.id) } } @@ -48,7 +48,7 @@ fn def_id_to_path(tcx: TyCtxt<'_>, did: DefId) -> Vec<Symbol> { std::iter::once(crate_name).chain(relative).collect() } -crate fn inherits_doc_hidden(tcx: TyCtxt<'_>, mut node: hir::HirId) -> bool { +pub(crate) fn inherits_doc_hidden(tcx: TyCtxt<'_>, mut node: hir::HirId) -> bool { while let Some(id) = tcx.hir().get_enclosing_scope(node) { node = id; if tcx.hir().attrs(node).lists(sym::doc).has_word(sym::hidden) { @@ -61,7 +61,7 @@ crate fn inherits_doc_hidden(tcx: TyCtxt<'_>, mut node: hir::HirId) -> bool { // Also, is there some reason that this doesn't use the 'visit' // framework from syntax?. -crate struct RustdocVisitor<'a, 'tcx> { +pub(crate) struct RustdocVisitor<'a, 'tcx> { cx: &'a mut core::DocContext<'tcx>, view_item_stack: FxHashSet<hir::HirId>, inlining: bool, @@ -71,7 +71,7 @@ crate struct RustdocVisitor<'a, 'tcx> { } impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { - crate fn new(cx: &'a mut core::DocContext<'tcx>) -> RustdocVisitor<'a, 'tcx> { + pub(crate) fn new(cx: &'a mut core::DocContext<'tcx>) -> RustdocVisitor<'a, 'tcx> { // If the root is re-exported, terminate all recursion. let mut stack = FxHashSet::default(); stack.insert(hir::CRATE_HIR_ID); @@ -89,7 +89,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { self.exact_paths.entry(did).or_insert_with(|| def_id_to_path(tcx, did)); } - crate fn visit(mut self) -> Module<'tcx> { + pub(crate) fn visit(mut self) -> Module<'tcx> { let mut top_level_module = self.visit_mod_contents( hir::CRATE_HIR_ID, self.cx.tcx.hir().root_module(), diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 9723cdbe334..f01ec38665c 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -8,7 +8,7 @@ use rustc_middle::ty::TyCtxt; /// Similar to `librustc_privacy::EmbargoVisitor`, but also takes /// specific rustdoc annotations into account (i.e., `doc(hidden)`) -crate struct LibEmbargoVisitor<'a, 'tcx> { +pub(crate) struct LibEmbargoVisitor<'a, 'tcx> { tcx: TyCtxt<'tcx>, // Accessibility levels for reachable nodes access_levels: &'a mut AccessLevels<DefId>, @@ -19,7 +19,7 @@ crate struct LibEmbargoVisitor<'a, 'tcx> { } impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> { - crate fn new(cx: &'a mut crate::core::DocContext<'tcx>) -> LibEmbargoVisitor<'a, 'tcx> { + pub(crate) fn new(cx: &'a mut crate::core::DocContext<'tcx>) -> LibEmbargoVisitor<'a, 'tcx> { LibEmbargoVisitor { tcx: cx.tcx, access_levels: &mut cx.cache.access_levels, @@ -28,7 +28,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> { } } - crate fn visit_lib(&mut self, cnum: CrateNum) { + pub(crate) fn visit_lib(&mut self, cnum: CrateNum) { let did = cnum.as_def_id(); self.update(did, Some(AccessLevel::Public)); self.visit_mod(did); @@ -48,7 +48,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> { } } - crate fn visit_mod(&mut self, def_id: DefId) { + pub(crate) fn visit_mod(&mut self, def_id: DefId) { if !self.visited_mods.insert(def_id) { return; } diff --git a/src/test/rustdoc/visibility.rs b/src/test/rustdoc/visibility.rs index c573e1b77f9..4099b54f081 100644 --- a/src/test/rustdoc/visibility.rs +++ b/src/test/rustdoc/visibility.rs @@ -1,7 +1,5 @@ // compile-flags: --document-private-items -#![feature(crate_visibility_modifier)] - #![crate_name = "foo"] // @!has 'foo/index.html' '//a[@href="struct.FooPublic.html"]/..' 'FooPublic 🔒' @@ -9,7 +7,7 @@ pub struct FooPublic; // @has 'foo/index.html' '//a[@href="struct.FooJustCrate.html"]/..' 'FooJustCrate 🔒' // @has 'foo/struct.FooJustCrate.html' '//pre' 'pub(crate) struct FooJustCrate' -crate struct FooJustCrate; +pub(crate) struct FooJustCrate; // @has 'foo/index.html' '//a[@href="struct.FooPubCrate.html"]/..' 'FooPubCrate 🔒' // @has 'foo/struct.FooPubCrate.html' '//pre' 'pub(crate) struct FooPubCrate' pub(crate) struct FooPubCrate; diff --git a/src/test/ui/lint/dead-code/issue-85255.rs b/src/test/ui/lint/dead-code/issue-85255.rs index 8c4aad66d47..871dde91a3e 100644 --- a/src/test/ui/lint/dead-code/issue-85255.rs +++ b/src/test/ui/lint/dead-code/issue-85255.rs @@ -2,7 +2,6 @@ // check-pass #![warn(dead_code)] -#![feature(crate_visibility_modifier)] struct Foo { a: i32, //~ WARNING: field is never read @@ -28,12 +27,12 @@ impl Bar1 { pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function is never used } -crate struct Foo2 { +pub(crate) struct Foo2 { a: i32, //~ WARNING: field is never read pub b: i32, //~ WARNING: field is never read } -crate struct Bar2; +pub(crate) struct Bar2; impl Bar2 { fn a(&self) -> i32 { 5 } //~ WARNING: associated function is never used diff --git a/src/test/ui/lint/dead-code/issue-85255.stderr b/src/test/ui/lint/dead-code/issue-85255.stderr index 736b1a20422..5f786d5a2a8 100644 --- a/src/test/ui/lint/dead-code/issue-85255.stderr +++ b/src/test/ui/lint/dead-code/issue-85255.stderr @@ -1,5 +1,5 @@ warning: field is never read: `a` - --> $DIR/issue-85255.rs:8:5 + --> $DIR/issue-85255.rs:7:5 | LL | a: i32, | ^^^^^^ @@ -11,67 +11,67 @@ LL | #![warn(dead_code)] | ^^^^^^^^^ warning: field is never read: `b` - --> $DIR/issue-85255.rs:9:5 + --> $DIR/issue-85255.rs:8:5 | LL | pub b: i32, | ^^^^^^^^^^ warning: associated function is never used: `a` - --> $DIR/issue-85255.rs:15:8 + --> $DIR/issue-85255.rs:14:8 | LL | fn a(&self) -> i32 { 5 } | ^ warning: associated function is never used: `b` - --> $DIR/issue-85255.rs:16:12 + --> $DIR/issue-85255.rs:15:12 | LL | pub fn b(&self) -> i32 { 6 } | ^ warning: field is never read: `a` - --> $DIR/issue-85255.rs:20:5 + --> $DIR/issue-85255.rs:19:5 | LL | a: i32, | ^^^^^^ warning: field is never read: `b` - --> $DIR/issue-85255.rs:21:5 + --> $DIR/issue-85255.rs:20:5 | LL | pub b: i32, | ^^^^^^^^^^ warning: associated function is never used: `a` - --> $DIR/issue-85255.rs:27:8 + --> $DIR/issue-85255.rs:26:8 | LL | fn a(&self) -> i32 { 5 } | ^ warning: associated function is never used: `b` - --> $DIR/issue-85255.rs:28:12 + --> $DIR/issue-85255.rs:27:12 | LL | pub fn b(&self) -> i32 { 6 } | ^ warning: field is never read: `a` - --> $DIR/issue-85255.rs:32:5 + --> $DIR/issue-85255.rs:31:5 | LL | a: i32, | ^^^^^^ warning: field is never read: `b` - --> $DIR/issue-85255.rs:33:5 + --> $DIR/issue-85255.rs:32:5 | LL | pub b: i32, | ^^^^^^^^^^ warning: associated function is never used: `a` - --> $DIR/issue-85255.rs:39:8 + --> $DIR/issue-85255.rs:38:8 | LL | fn a(&self) -> i32 { 5 } | ^ warning: associated function is never used: `b` - --> $DIR/issue-85255.rs:40:12 + --> $DIR/issue-85255.rs:39:12 | LL | pub fn b(&self) -> i32 { 6 } | ^ diff --git a/src/test/ui/lint/unnecessary-extern-crate.rs b/src/test/ui/lint/unnecessary-extern-crate.rs index 67eaaf4b6c2..af2bd84bd53 100644 --- a/src/test/ui/lint/unnecessary-extern-crate.rs +++ b/src/test/ui/lint/unnecessary-extern-crate.rs @@ -1,7 +1,7 @@ // edition:2018 #![deny(unused_extern_crates)] -#![feature(test, rustc_private, crate_visibility_modifier)] +#![feature(test, rustc_private)] extern crate libc; //~^ ERROR unused extern crate @@ -21,7 +21,7 @@ pub extern crate alloc; pub(crate) extern crate alloc as a; -crate extern crate alloc as b; +pub(crate) extern crate alloc as b; mod foo { pub(in crate::foo) extern crate alloc as c; diff --git a/src/test/ui/lint/unreachable_pub-pub_crate.rs b/src/test/ui/lint/unreachable_pub-pub_crate.rs deleted file mode 100644 index 4dc951985ae..00000000000 --- a/src/test/ui/lint/unreachable_pub-pub_crate.rs +++ /dev/null @@ -1,72 +0,0 @@ -// This is just like unreachable_pub.rs, but without the -// `crate_visibility_modifier` feature (so that we can test the suggestions to -// use `pub(crate)` that are given when that feature is off, as opposed to the -// suggestions to use `crate` given when it is on). When that feature becomes -// stable, this test can be deleted. - -// check-pass - - -#![warn(unreachable_pub)] - -mod private_mod { - // non-leaked `pub` items in private module should be linted - pub use std::fmt; //~ WARNING unreachable_pub - pub use std::env::{Args}; // braced-use has different item spans than unbraced - //~^ WARNING unreachable_pub - - pub struct Hydrogen { //~ WARNING unreachable_pub - // `pub` struct fields, too - pub neutrons: usize, //~ WARNING unreachable_pub - // (... but not more-restricted fields) - pub(crate) electrons: usize - } - impl Hydrogen { - // impls, too - pub fn count_neutrons(&self) -> usize { self.neutrons } //~ WARNING unreachable_pub - pub(crate) fn count_electrons(&self) -> usize { self.electrons } - } - impl Clone for Hydrogen { - fn clone(&self) -> Hydrogen { - Hydrogen { neutrons: self.neutrons, electrons: self.electrons } - } - } - - pub enum Helium {} //~ WARNING unreachable_pub - pub union Lithium { c1: usize, c2: u8 } //~ WARNING unreachable_pub - pub fn beryllium() {} //~ WARNING unreachable_pub - pub trait Boron {} //~ WARNING unreachable_pub - pub const CARBON: usize = 1; //~ WARNING unreachable_pub - pub static NITROGEN: usize = 2; //~ WARNING unreachable_pub - pub type Oxygen = bool; //~ WARNING unreachable_pub - - macro_rules! define_empty_struct_with_visibility { - ($visibility: vis, $name: ident) => { $visibility struct $name {} } - //~^ WARNING unreachable_pub - } - define_empty_struct_with_visibility!(pub, Fluorine); - - extern "C" { - pub fn catalyze() -> bool; //~ WARNING unreachable_pub - } - - // items leaked through signatures (see `get_neon` below) are OK - pub struct Neon {} - - // crate-visible items are OK - pub(crate) struct Sodium {} -} - -pub mod public_mod { - // module is public: these are OK, too - pub struct Magnesium {} - pub(crate) struct Aluminum {} -} - -pub fn get_neon() -> private_mod::Neon { - private_mod::Neon {} -} - -fn main() { - let _ = get_neon(); -} diff --git a/src/test/ui/lint/unreachable_pub-pub_crate.stderr b/src/test/ui/lint/unreachable_pub-pub_crate.stderr deleted file mode 100644 index 6c05a030138..00000000000 --- a/src/test/ui/lint/unreachable_pub-pub_crate.stderr +++ /dev/null @@ -1,148 +0,0 @@ -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:14:5 - | -LL | pub use std::fmt; - | ---^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | -note: the lint level is defined here - --> $DIR/unreachable_pub-pub_crate.rs:10:9 - | -LL | #![warn(unreachable_pub)] - | ^^^^^^^^^^^^^^^ - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:15:24 - | -LL | pub use std::env::{Args}; // braced-use has different item spans than unbraced - | --- ^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:18:5 - | -LL | pub struct Hydrogen { - | ---^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` field - --> $DIR/unreachable_pub-pub_crate.rs:20:9 - | -LL | pub neutrons: usize, - | ---^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:26:9 - | -LL | pub fn count_neutrons(&self) -> usize { self.neutrons } - | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:35:5 - | -LL | pub enum Helium {} - | ---^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:36:5 - | -LL | pub union Lithium { c1: usize, c2: u8 } - | ---^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:37:5 - | -LL | pub fn beryllium() {} - | ---^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:38:5 - | -LL | pub trait Boron {} - | ---^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:39:5 - | -LL | pub const CARBON: usize = 1; - | ---^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:40:5 - | -LL | pub static NITROGEN: usize = 2; - | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:41:5 - | -LL | pub type Oxygen = bool; - | ---^^^^^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:44:47 - | -LL | ($visibility: vis, $name: ident) => { $visibility struct $name {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | define_empty_struct_with_visibility!(pub, Fluorine); - | --------------------------------------------------- - | | | - | | help: consider restricting its visibility: `pub(crate)` - | in this macro invocation - | - = help: or consider exporting it for use by other crates - = note: this warning originates in the macro `define_empty_struct_with_visibility` (in Nightly builds, run with -Z macro-backtrace for more info) - -warning: unreachable `pub` item - --> $DIR/unreachable_pub-pub_crate.rs:50:9 - | -LL | pub fn catalyze() -> bool; - | ---^^^^^^^^^^^^^^^^^^^^^^^ - | | - | help: consider restricting its visibility: `pub(crate)` - | - = help: or consider exporting it for use by other crates - -warning: 14 warnings emitted - diff --git a/src/test/ui/lint/unreachable_pub.rs b/src/test/ui/lint/unreachable_pub.rs index 39e2b596156..a50467ce82d 100644 --- a/src/test/ui/lint/unreachable_pub.rs +++ b/src/test/ui/lint/unreachable_pub.rs @@ -1,7 +1,5 @@ // check-pass -#![feature(crate_visibility_modifier)] - #![allow(unused)] #![warn(unreachable_pub)] @@ -15,12 +13,12 @@ mod private_mod { // `pub` struct fields, too pub neutrons: usize, //~ WARNING unreachable_pub // (... but not more-restricted fields) - crate electrons: usize + pub(crate) electrons: usize } impl Hydrogen { // impls, too pub fn count_neutrons(&self) -> usize { self.neutrons } //~ WARNING unreachable_pub - crate fn count_electrons(&self) -> usize { self.electrons } + pub(crate) fn count_electrons(&self) -> usize { self.electrons } } impl Clone for Hydrogen { fn clone(&self) -> Hydrogen { @@ -50,13 +48,13 @@ mod private_mod { pub struct Neon {} // crate-visible items are OK - crate struct Sodium {} + pub(crate) struct Sodium {} } pub mod public_mod { // module is public: these are OK, too pub struct Magnesium {} - crate struct Aluminum {} + pub(crate) struct Aluminum {} } pub fn get_neon() -> private_mod::Neon { diff --git a/src/test/ui/lint/unreachable_pub.stderr b/src/test/ui/lint/unreachable_pub.stderr index e8e55be5a47..ce22eca1b8c 100644 --- a/src/test/ui/lint/unreachable_pub.stderr +++ b/src/test/ui/lint/unreachable_pub.stderr @@ -1,126 +1,126 @@ warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:10:5 + --> $DIR/unreachable_pub.rs:8:5 | LL | pub use std::fmt; | ---^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | note: the lint level is defined here - --> $DIR/unreachable_pub.rs:6:9 + --> $DIR/unreachable_pub.rs:4:9 | LL | #![warn(unreachable_pub)] | ^^^^^^^^^^^^^^^ = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:11:24 + --> $DIR/unreachable_pub.rs:9:24 | LL | pub use std::env::{Args}; // braced-use has different item spans than unbraced | --- ^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:14:5 + --> $DIR/unreachable_pub.rs:12:5 | LL | pub struct Hydrogen { | ---^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` field - --> $DIR/unreachable_pub.rs:16:9 + --> $DIR/unreachable_pub.rs:14:9 | LL | pub neutrons: usize, | ---^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:22:9 + --> $DIR/unreachable_pub.rs:20:9 | LL | pub fn count_neutrons(&self) -> usize { self.neutrons } | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:31:5 + --> $DIR/unreachable_pub.rs:29:5 | LL | pub enum Helium {} | ---^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:32:5 + --> $DIR/unreachable_pub.rs:30:5 | LL | pub union Lithium { c1: usize, c2: u8 } | ---^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:33:5 + --> $DIR/unreachable_pub.rs:31:5 | LL | pub fn beryllium() {} | ---^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:34:5 + --> $DIR/unreachable_pub.rs:32:5 | LL | pub trait Boron {} | ---^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:35:5 + --> $DIR/unreachable_pub.rs:33:5 | LL | pub const CARBON: usize = 1; | ---^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:36:5 + --> $DIR/unreachable_pub.rs:34:5 | LL | pub static NITROGEN: usize = 2; | ---^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:37:5 + --> $DIR/unreachable_pub.rs:35:5 | LL | pub type Oxygen = bool; | ---^^^^^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:40:47 + --> $DIR/unreachable_pub.rs:38:47 | LL | ($visibility: vis, $name: ident) => { $visibility struct $name {} } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -128,19 +128,19 @@ LL | ($visibility: vis, $name: ident) => { $visibility struct $name {} } LL | define_empty_struct_with_visibility!(pub, Fluorine); | --------------------------------------------------- | | | - | | help: consider restricting its visibility: `crate` + | | help: consider restricting its visibility: `pub(crate)` | in this macro invocation | = help: or consider exporting it for use by other crates = note: this warning originates in the macro `define_empty_struct_with_visibility` (in Nightly builds, run with -Z macro-backtrace for more info) warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:46:9 + --> $DIR/unreachable_pub.rs:44:9 | LL | pub fn catalyze() -> bool; | ---^^^^^^^^^^^^^^^^^^^^^^^ | | - | help: consider restricting its visibility: `crate` + | help: consider restricting its visibility: `pub(crate)` | = help: or consider exporting it for use by other crates diff --git a/src/test/ui/macros/macro-pub-matcher.rs b/src/test/ui/macros/macro-pub-matcher.rs index 174056d6cdf..7b02a70be09 100644 --- a/src/test/ui/macros/macro-pub-matcher.rs +++ b/src/test/ui/macros/macro-pub-matcher.rs @@ -1,6 +1,5 @@ // run-pass #![allow(dead_code, unused_imports, unused_macro_rules)] -#![feature(crate_visibility_modifier)] /** Ensure that `:vis` matches can be captured in existing positions, and passed @@ -56,15 +55,15 @@ mod with_pub_restricted { } mod with_crate { - vis_passthru! { crate const A: i32 = 0; } - vis_passthru! { crate enum B {} } - vis_passthru! { crate extern "C" fn c() {} } - vis_passthru! { crate mod d {} } - vis_passthru! { crate static E: i32 = 0; } - vis_passthru! { crate struct F; } - vis_passthru! { crate trait G {} } - vis_passthru! { crate type H = i32; } - vis_passthru! { crate use A as I; } + vis_passthru! { pub(crate) const A: i32 = 0; } + vis_passthru! { pub(crate) enum B {} } + vis_passthru! { pub(crate) extern "C" fn c() {} } + vis_passthru! { pub(crate) mod d {} } + vis_passthru! { pub(crate) static E: i32 = 0; } + vis_passthru! { pub(crate) struct F; } + vis_passthru! { pub(crate) trait G {} } + vis_passthru! { pub(crate) type H = i32; } + vis_passthru! { pub(crate) use A as I; } } mod garden { diff --git a/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.rs b/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.rs index 8f9dc4bc945..6f115e78e14 100644 --- a/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.rs +++ b/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.rs @@ -1,5 +1,3 @@ -#![feature(crate_visibility_modifier)] - #[deny(unused_imports)] mod rank { pub use self::Professor::*; @@ -31,7 +29,7 @@ mod rank { MasterChief } - crate enum Crewman { + pub(crate) enum Crewman { Recruit, Apprentice, Full diff --git a/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.stderr b/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.stderr index d4d9b31ed83..59b181fab40 100644 --- a/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.stderr +++ b/src/test/ui/privacy/issue-46209-private-enum-variant-reexport.stderr @@ -1,47 +1,47 @@ error[E0364]: `JuniorGrade` is private, and cannot be re-exported - --> $DIR/issue-46209-private-enum-variant-reexport.rs:7:32 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:32 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^^^^^^^^ | note: consider marking `JuniorGrade` as `pub` in the imported module - --> $DIR/issue-46209-private-enum-variant-reexport.rs:7:32 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:32 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^^^^^^^^ error[E0364]: `Full` is private, and cannot be re-exported - --> $DIR/issue-46209-private-enum-variant-reexport.rs:7:45 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:45 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^ | note: consider marking `Full` as `pub` in the imported module - --> $DIR/issue-46209-private-enum-variant-reexport.rs:7:45 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:45 | LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^ error: glob import doesn't reexport anything because no candidate is public enough - --> $DIR/issue-46209-private-enum-variant-reexport.rs:5:13 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:3:13 | LL | pub use self::Professor::*; | ^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/issue-46209-private-enum-variant-reexport.rs:3:8 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:1:8 | LL | #[deny(unused_imports)] | ^^^^^^^^^^^^^^ error: glob import doesn't reexport anything because no candidate is public enough - --> $DIR/issue-46209-private-enum-variant-reexport.rs:10:13 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:8:13 | LL | pub use self::PettyOfficer::*; | ^^^^^^^^^^^^^^^^^^^^^ error: glob import doesn't reexport anything because no candidate is public enough - --> $DIR/issue-46209-private-enum-variant-reexport.rs:12:13 + --> $DIR/issue-46209-private-enum-variant-reexport.rs:10:13 | LL | pub use self::Crewman::*; | ^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/privacy/restricted/auxiliary/pub_restricted.rs b/src/test/ui/privacy/restricted/auxiliary/pub_restricted.rs index 482d5cdc45d..a4013e6ac60 100644 --- a/src/test/ui/privacy/restricted/auxiliary/pub_restricted.rs +++ b/src/test/ui/privacy/restricted/auxiliary/pub_restricted.rs @@ -1,16 +1,14 @@ -#![feature(crate_visibility_modifier)] - pub(crate) struct Crate; #[derive(Default)] pub struct Universe { pub x: i32, pub(crate) y: i32, - crate z: i32, + pub(crate) z: i32, } impl Universe { pub fn f(&self) {} pub(crate) fn g(&self) {} - crate fn h(&self) {} + pub(crate) fn h(&self) {} } diff --git a/src/test/ui/privacy/restricted/private-in-public.rs b/src/test/ui/privacy/restricted/private-in-public.rs index 7cae28970d4..1e3dbdf73b9 100644 --- a/src/test/ui/privacy/restricted/private-in-public.rs +++ b/src/test/ui/privacy/restricted/private-in-public.rs @@ -1,12 +1,10 @@ -#![feature(crate_visibility_modifier)] - mod foo { struct Priv; mod bar { use foo::Priv; pub(super) fn f(_: Priv) {} pub(crate) fn g(_: Priv) {} //~ ERROR E0446 - crate fn h(_: Priv) {} //~ ERROR E0446 + pub(crate) fn h(_: Priv) {} //~ ERROR E0446 } } diff --git a/src/test/ui/privacy/restricted/private-in-public.stderr b/src/test/ui/privacy/restricted/private-in-public.stderr index c14382ce290..ee9c031ebff 100644 --- a/src/test/ui/privacy/restricted/private-in-public.stderr +++ b/src/test/ui/privacy/restricted/private-in-public.stderr @@ -1,5 +1,5 @@ error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public.rs:8:9 + --> $DIR/private-in-public.rs:6:9 | LL | struct Priv; | ------------ `Priv` declared as private @@ -8,13 +8,13 @@ LL | pub(crate) fn g(_: Priv) {} | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type error[E0446]: private type `Priv` in public interface - --> $DIR/private-in-public.rs:9:9 + --> $DIR/private-in-public.rs:7:9 | LL | struct Priv; | ------------ `Priv` declared as private ... -LL | crate fn h(_: Priv) {} - | ^^^^^^^^^^^^^^^^^^^ can't leak private type +LL | pub(crate) fn h(_: Priv) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type error: aborting due to 2 previous errors diff --git a/src/test/ui/privacy/restricted/test.stderr b/src/test/ui/privacy/restricted/test.stderr index 0f6003c4247..5a85aef2b17 100644 --- a/src/test/ui/privacy/restricted/test.stderr +++ b/src/test/ui/privacy/restricted/test.stderr @@ -29,7 +29,7 @@ LL | use pub_restricted::Crate; | ^^^^^ private struct | note: the struct `Crate` is defined here - --> $DIR/auxiliary/pub_restricted.rs:3:1 + --> $DIR/auxiliary/pub_restricted.rs:1:1 | LL | pub(crate) struct Crate; | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ error[E0624]: associated function `g` is private LL | u.g(); | ^ private associated function | - ::: $DIR/auxiliary/pub_restricted.rs:14:5 + ::: $DIR/auxiliary/pub_restricted.rs:12:5 | LL | pub(crate) fn g(&self) {} | ---------------------- private associated function defined here @@ -99,10 +99,10 @@ error[E0624]: associated function `h` is private LL | u.h(); | ^ private associated function | - ::: $DIR/auxiliary/pub_restricted.rs:15:5 + ::: $DIR/auxiliary/pub_restricted.rs:13:5 | -LL | crate fn h(&self) {} - | ----------------- private associated function defined here +LL | pub(crate) fn h(&self) {} + | ---------------------- private associated function defined here error: aborting due to 12 previous errors diff --git a/src/test/ui/resolve/crate-in-paths.rs b/src/test/ui/resolve/crate-in-paths.rs index 50ed50cbef0..7ebd259189d 100644 --- a/src/test/ui/resolve/crate-in-paths.rs +++ b/src/test/ui/resolve/crate-in-paths.rs @@ -1,9 +1,7 @@ // edition:2018 -#![feature(crate_visibility_modifier)] - mod bar { - crate struct Foo; + pub(crate) struct Foo; } fn main() { diff --git a/src/test/ui/resolve/crate-in-paths.stderr b/src/test/ui/resolve/crate-in-paths.stderr index c3aa135f77d..b7cf4950759 100644 --- a/src/test/ui/resolve/crate-in-paths.stderr +++ b/src/test/ui/resolve/crate-in-paths.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `Foo` in this scope - --> $DIR/crate-in-paths.rs:10:5 + --> $DIR/crate-in-paths.rs:8:5 | LL | Foo; | ^^^ not found in this scope diff --git a/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.fixed b/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.fixed index 37847a98ac7..85d106bc11f 100644 --- a/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.fixed +++ b/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.fixed @@ -1,14 +1,14 @@ // run-rustfix -#![feature(rust_2018_preview, crate_visibility_modifier)] +#![feature(rust_2018_preview)] #![deny(absolute_paths_not_starting_with_crate)] mod foo { - crate trait Foo { + pub(crate) trait Foo { type Bar; } - crate struct Baz {} + pub(crate) struct Baz {} impl Foo for Baz { type Bar = (); diff --git a/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs b/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs index 36efa14601d..9ff3c2e5fcf 100644 --- a/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs +++ b/src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs @@ -1,14 +1,14 @@ // run-rustfix -#![feature(rust_2018_preview, crate_visibility_modifier)] +#![feature(rust_2018_preview)] #![deny(absolute_paths_not_starting_with_crate)] mod foo { - crate trait Foo { + pub(crate) trait Foo { type Bar; } - crate struct Baz {} + pub(crate) struct Baz {} impl Foo for Baz { type Bar = (); diff --git a/src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed b/src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed index 5786ed7b1d5..f25d46ce30d 100644 --- a/src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed +++ b/src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed @@ -1,16 +1,16 @@ // run-rustfix -#![feature(rust_2018_preview, crate_visibility_modifier)] +#![feature(rust_2018_preview)] #![deny(absolute_paths_not_starting_with_crate)] #![allow(unused_imports)] #![allow(dead_code)] -crate mod foo { - crate mod bar { - crate mod baz { } - crate mod baz1 { } +pub(crate) mod foo { + pub(crate) mod bar { + pub(crate) mod baz { } + pub(crate) mod baz1 { } - crate struct XX; + pub(crate) struct XX; } } diff --git a/src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs b/src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs index b7c86088c75..9be1680c1ce 100644 --- a/src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs +++ b/src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs @@ -1,16 +1,16 @@ // run-rustfix -#![feature(rust_2018_preview, crate_visibility_modifier)] +#![feature(rust_2018_preview)] #![deny(absolute_paths_not_starting_with_crate)] #![allow(unused_imports)] #![allow(dead_code)] -crate mod foo { - crate mod bar { - crate mod baz { } - crate mod baz1 { } +pub(crate) mod foo { + pub(crate) mod bar { + pub(crate) mod baz { } + pub(crate) mod baz1 { } - crate struct XX; + pub(crate) struct XX; } } diff --git a/src/test/ui/rust-2018/edition-lint-nested-paths.fixed b/src/test/ui/rust-2018/edition-lint-nested-paths.fixed index c4546f8c821..a04937ae8ee 100644 --- a/src/test/ui/rust-2018/edition-lint-nested-paths.fixed +++ b/src/test/ui/rust-2018/edition-lint-nested-paths.fixed @@ -1,6 +1,6 @@ // run-rustfix -#![feature(rust_2018_preview, crate_visibility_modifier)] +#![feature(rust_2018_preview)] #![deny(absolute_paths_not_starting_with_crate)] use crate::foo::{a, b}; @@ -10,9 +10,9 @@ use crate::foo::{a, b}; //~| this is accepted in the current edition mod foo { - crate fn a() {} - crate fn b() {} - crate fn c() {} + pub(crate) fn a() {} + pub(crate) fn b() {} + pub(crate) fn c() {} } fn main() { diff --git a/src/test/ui/rust-2018/edition-lint-nested-paths.rs b/src/test/ui/rust-2018/edition-lint-nested-paths.rs index a7e34e407a3..e622a8e24be 100644 --- a/src/test/ui/rust-2018/edition-lint-nested-paths.rs +++ b/src/test/ui/rust-2018/edition-lint-nested-paths.rs @@ -1,6 +1,6 @@ // run-rustfix -#![feature(rust_2018_preview, crate_visibility_modifier)] +#![feature(rust_2018_preview)] #![deny(absolute_paths_not_starting_with_crate)] use foo::{a, b}; @@ -10,9 +10,9 @@ use foo::{a, b}; //~| this is accepted in the current edition mod foo { - crate fn a() {} - crate fn b() {} - crate fn c() {} + pub(crate) fn a() {} + pub(crate) fn b() {} + pub(crate) fn c() {} } fn main() { diff --git a/src/tools/rustfmt/tests/source/fn-simple.rs b/src/tools/rustfmt/tests/source/fn-simple.rs index 528b9a0292a..12a50c013a9 100644 --- a/src/tools/rustfmt/tests/source/fn-simple.rs +++ b/src/tools/rustfmt/tests/source/fn-simple.rs @@ -63,7 +63,7 @@ mod foo { // #2082 pub(crate) fn init() {} -crate fn init() {} +pub(crate) fn init() {} // #2630 fn make_map<T, F: (Fn(&T) -> String)>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {} diff --git a/src/tools/rustfmt/tests/source/pub-restricted.rs b/src/tools/rustfmt/tests/source/pub-restricted.rs index 30051fa72ee..5683acbf3aa 100644 --- a/src/tools/rustfmt/tests/source/pub-restricted.rs +++ b/src/tools/rustfmt/tests/source/pub-restricted.rs @@ -24,19 +24,6 @@ pub( crate ) enum WriteState<D> { WriteData(Writer<D>), } - crate enum WriteState<D> { - WriteId { - id: U64Writer, - size: U64Writer, - payload: Option<Writer<D>>, - }, - WriteSize { - size: U64Writer, - payload: Option<Writer<D>>, - }, - WriteData(Writer<D>), -} - pub(in ::global:: path :: to::some_mod ) enum WriteState<D> { WriteId { id: U64Writer, diff --git a/src/tools/rustfmt/tests/target/fn-simple.rs b/src/tools/rustfmt/tests/target/fn-simple.rs index 692739fa6a9..e725269360d 100644 --- a/src/tools/rustfmt/tests/target/fn-simple.rs +++ b/src/tools/rustfmt/tests/target/fn-simple.rs @@ -105,7 +105,7 @@ mod foo { // #2082 pub(crate) fn init() {} -crate fn init() {} +pub(crate) fn init() {} // #2630 fn make_map<T, F: (Fn(&T) -> String)>(records: &Vec<T>, key_fn: F) -> HashMap<String, usize> {} diff --git a/src/tools/rustfmt/tests/target/pub-restricted.rs b/src/tools/rustfmt/tests/target/pub-restricted.rs index 8cc2ade612a..0e178ef1013 100644 --- a/src/tools/rustfmt/tests/target/pub-restricted.rs +++ b/src/tools/rustfmt/tests/target/pub-restricted.rs @@ -24,19 +24,6 @@ pub(crate) enum WriteState<D> { WriteData(Writer<D>), } -crate enum WriteState<D> { - WriteId { - id: U64Writer, - size: U64Writer, - payload: Option<Writer<D>>, - }, - WriteSize { - size: U64Writer, - payload: Option<Writer<D>>, - }, - WriteData(Writer<D>), -} - pub(in global::path::to::some_mod) enum WriteState<D> { WriteId { id: U64Writer, |
