Auto merge of #52257 - steveklabnik:refactor-rustdoc, r=QuietMisdreavus

Refactor rustdoc

This is based on https://github.com/rust-lang/rust/pull/52194 and so shouldn't be merged until it gets merged.

Now that plugin functionality has been removed, let's kill PluginManager. Additionally, rustdoc now follows the standard cargo layout instead of dumping everything at the top level.

r? @rust-lang/rustdoc
This commit is contained in:
bors 2018-07-24 22:25:42 +00:00
commit 46804ef0ce
9 changed files with 16 additions and 72 deletions

View File

@ -90,7 +90,6 @@ pub mod html {
} }
pub mod markdown; pub mod markdown;
pub mod passes; pub mod passes;
pub mod plugins;
pub mod visit_ast; pub mod visit_ast;
pub mod visit_lib; pub mod visit_lib;
pub mod test; pub mod test;
@ -750,25 +749,22 @@ where R: 'static + Send,
eprintln!("WARNING: --plugin-path no longer functions; see CVE-2018-1000622"); eprintln!("WARNING: --plugin-path no longer functions; see CVE-2018-1000622");
} }
// Load all plugins/passes into a PluginManager info!("Executing passes");
let mut pm = plugins::PluginManager::new();
for pass in &passes { for pass in &passes {
let plugin = match passes::PASSES.iter() // determine if we know about this pass
.position(|&(p, ..)| { let pass = match passes::PASSES.iter().find(|(p, ..)| p == pass) {
p == *pass Some(pass) => pass.1,
}) {
Some(i) => passes::PASSES[i].1,
None => { None => {
error!("unknown pass {}, skipping", *pass); error!("unknown pass {}, skipping", *pass);
continue continue
}, },
}; };
pm.add_plugin(plugin);
}
// Run everything! // run it
info!("Executing passes/plugins"); krate = pass(krate);
let krate = pm.run_plugins(krate); }
tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap(); tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
})); }));

View File

@ -9,7 +9,6 @@
// except according to those terms. // except according to those terms.
use clean::{self, DocFragment, Item}; use clean::{self, DocFragment, Item};
use plugins;
use fold; use fold;
use fold::DocFolder; use fold::DocFolder;
use std::mem::replace; use std::mem::replace;
@ -31,7 +30,7 @@ impl DocFragment {
} }
} }
pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { pub fn collapse_docs(krate: clean::Crate) -> clean::Crate {
Collapser.fold_crate(krate) Collapser.fold_crate(krate)
} }

View File

@ -16,7 +16,6 @@ use std::mem;
use clean::{self, GetDefId, Item}; use clean::{self, GetDefId, Item};
use fold; use fold;
use fold::FoldItem::Strip; use fold::FoldItem::Strip;
use plugins;
mod collapse_docs; mod collapse_docs;
pub use self::collapse_docs::collapse_docs; pub use self::collapse_docs::collapse_docs;
@ -37,7 +36,7 @@ mod propagate_doc_cfg;
pub use self::propagate_doc_cfg::propagate_doc_cfg; pub use self::propagate_doc_cfg::propagate_doc_cfg;
type Pass = (&'static str, // name type Pass = (&'static str, // name
fn(clean::Crate) -> plugins::PluginResult, // fn fn(clean::Crate) -> clean::Crate, // fn
&'static str); // description &'static str); // description
pub const PASSES: &'static [Pass] = &[ pub const PASSES: &'static [Pass] = &[

View File

@ -13,9 +13,8 @@ use std::sync::Arc;
use clean::{Crate, Item}; use clean::{Crate, Item};
use clean::cfg::Cfg; use clean::cfg::Cfg;
use fold::DocFolder; use fold::DocFolder;
use plugins::PluginResult;
pub fn propagate_doc_cfg(cr: Crate) -> PluginResult { pub fn propagate_doc_cfg(cr: Crate) -> Crate {
CfgPropagator { parent_cfg: None }.fold_crate(cr) CfgPropagator { parent_cfg: None }.fold_crate(cr)
} }

View File

@ -13,14 +13,13 @@ use std::mem;
use clean::{self, AttributesExt, NestedAttributesExt}; use clean::{self, AttributesExt, NestedAttributesExt};
use clean::Item; use clean::Item;
use plugins;
use fold; use fold;
use fold::DocFolder; use fold::DocFolder;
use fold::FoldItem::Strip; use fold::FoldItem::Strip;
use passes::ImplStripper; use passes::ImplStripper;
/// Strip items marked `#[doc(hidden)]` /// Strip items marked `#[doc(hidden)]`
pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult { pub fn strip_hidden(krate: clean::Crate) -> clean::Crate {
let mut retained = DefIdSet(); let mut retained = DefIdSet();
// strip all #[doc(hidden)] items // strip all #[doc(hidden)] items

View File

@ -10,9 +10,8 @@
use clean; use clean;
use fold::DocFolder; use fold::DocFolder;
use plugins;
use passes::ImportStripper; use passes::ImportStripper;
pub fn strip_priv_imports(krate: clean::Crate) -> plugins::PluginResult { pub fn strip_priv_imports(krate: clean::Crate) -> clean::Crate {
ImportStripper.fold_crate(krate) ImportStripper.fold_crate(krate)
} }

View File

@ -11,13 +11,12 @@
use rustc::util::nodemap::DefIdSet; use rustc::util::nodemap::DefIdSet;
use clean; use clean;
use plugins;
use fold::DocFolder; use fold::DocFolder;
use passes::{ImplStripper, ImportStripper, Stripper}; use passes::{ImplStripper, ImportStripper, Stripper};
/// Strip private items from the point of view of a crate or externally from a /// Strip private items from the point of view of a crate or externally from a
/// crate, specified by the `xcrate` flag. /// crate, specified by the `xcrate` flag.
pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult { pub fn strip_private(mut krate: clean::Crate) -> clean::Crate {
// This stripper collects all *retained* nodes. // This stripper collects all *retained* nodes.
let mut retained = DefIdSet(); let mut retained = DefIdSet();
let access_levels = krate.access_levels.clone(); let access_levels = krate.access_levels.clone();

View File

@ -13,10 +13,9 @@ use std::string::String;
use std::usize; use std::usize;
use clean::{self, DocFragment, Item}; use clean::{self, DocFragment, Item};
use plugins;
use fold::{self, DocFolder}; use fold::{self, DocFolder};
pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult { pub fn unindent_comments(krate: clean::Crate) -> clean::Crate {
CommentCleaner.fold_crate(krate) CommentCleaner.fold_crate(krate)
} }

View File

@ -1,45 +0,0 @@
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(deprecated)]
use clean;
pub type PluginResult = clean::Crate;
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
/// Manages loading and running of plugins
pub struct PluginManager {
callbacks: Vec<PluginCallback> ,
}
impl PluginManager {
/// Create a new plugin manager
pub fn new() -> PluginManager {
PluginManager {
callbacks: Vec::new(),
}
}
/// Load a normal Rust function as a plugin.
///
/// This is to run passes over the cleaned crate. Plugins run this way
/// correspond to the A-aux tag on Github.
pub fn add_plugin(&mut self, plugin: PluginCallback) {
self.callbacks.push(plugin);
}
/// Run all the loaded plugins over the crate, returning their results
pub fn run_plugins(&self, mut krate: clean::Crate) -> clean::Crate {
for &callback in &self.callbacks {
krate = callback(krate);
}
krate
}
}