rustdoc: Make a bunch of fields private

Also create issue for removing shared mutable state.
This commit is contained in:
Camelid 2021-02-21 14:35:15 -08:00
parent c4bb66c284
commit b3d2a371bb
2 changed files with 18 additions and 12 deletions

View File

@ -44,15 +44,20 @@ use crate::html::{layout, sources};
crate struct Context<'tcx> {
/// Current hierarchy of components leading down to what's currently being
/// rendered
crate current: Vec<String>,
pub(super) current: Vec<String>,
/// 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(super) 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.
crate render_redirect_pages: bool,
crate shared: Rc<SharedContext<'tcx>>,
pub(super) render_redirect_pages: bool,
/// Shared mutable state.
///
/// Issue for improving the situation: [#82381][]
///
/// [#82381]: https://github.com/rust-lang/rust/issues/82381
pub(super) shared: Rc<SharedContext<'tcx>>,
/// The [`Cache`] used during rendering.
///
/// Ideally the cache would be in [`SharedContext`], but it's mutated
@ -62,7 +67,7 @@ crate struct Context<'tcx> {
/// It's immutable once in `Context`, so it's not as bad that it's not in
/// `SharedContext`.
// FIXME: move `cache` to `SharedContext`
crate cache: Rc<Cache>,
pub(super) cache: Rc<Cache>,
}
impl<'tcx> Context<'tcx> {

View File

@ -81,6 +81,7 @@ crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
})
}
/// Shared mutable state used in [`Context`] and elsewhere.
crate struct SharedContext<'tcx> {
crate tcx: TyCtxt<'tcx>,
/// The path to the crate root source minus the file name.
@ -96,16 +97,16 @@ crate struct SharedContext<'tcx> {
/// The local file sources we've emitted and their respective url-paths.
crate local_sources: FxHashMap<PathBuf, String>,
/// Whether the collapsed pass ran
crate collapsed: bool,
collapsed: bool,
/// The base-URL of the issue tracker for when an item has been tagged with
/// an issue number.
crate issue_tracker_base_url: Option<String>,
issue_tracker_base_url: Option<String>,
/// The directories that have already been created in this doc run. Used to reduce the number
/// of spurious `create_dir_all` calls.
crate created_dirs: RefCell<FxHashSet<PathBuf>>,
created_dirs: RefCell<FxHashSet<PathBuf>>,
/// This flag indicates whether listings of modules (in the side bar and documentation itself)
/// should be ordered alphabetically or in order of appearance (in the source code).
crate sort_modules_alphabetically: bool,
sort_modules_alphabetically: bool,
/// Additional CSS files to be added to the generated docs.
crate style_files: Vec<StylePath>,
/// Suffix to be added on resource files (if suffix is "-v2" then "light.css" becomes
@ -118,7 +119,7 @@ crate struct SharedContext<'tcx> {
crate fs: DocFS,
/// The default edition used to parse doctests.
crate edition: Edition,
crate codes: ErrorCodes,
codes: ErrorCodes,
playground: Option<markdown::Playground>,
/// The map used to ensure all generated 'id=' attributes are unique.
id_map: RefCell<IdMap>,
@ -128,11 +129,11 @@ crate struct SharedContext<'tcx> {
all: RefCell<AllTypes>,
/// Storage for the errors produced while generating documentation so they
/// can be printed together at the end.
crate errors: Receiver<String>,
errors: Receiver<String>,
/// `None` by default, depends on the `generate-redirect-map` option flag. If this field is set
/// to `Some(...)`, it'll store redirections and then generate a JSON file at the top level of
/// the crate.
crate redirections: Option<RefCell<FxHashMap<String, String>>>,
redirections: Option<RefCell<FxHashMap<String, String>>>,
}
impl SharedContext<'_> {