Delete unused code in rustdoc
This commit is contained in:
parent
54628c8ea8
commit
620c4fdf53
7 changed files with 96 additions and 121 deletions
|
@ -425,9 +425,6 @@ impl Item {
|
|||
pub fn is_enum(&self) -> bool {
|
||||
self.type_() == ItemType::Enum
|
||||
}
|
||||
pub fn is_fn(&self) -> bool {
|
||||
self.type_() == ItemType::Function
|
||||
}
|
||||
pub fn is_associated_type(&self) -> bool {
|
||||
self.type_() == ItemType::AssociatedType
|
||||
}
|
||||
|
@ -2188,10 +2185,6 @@ pub struct FnDecl {
|
|||
}
|
||||
|
||||
impl FnDecl {
|
||||
pub fn has_self(&self) -> bool {
|
||||
self.inputs.values.len() > 0 && self.inputs.values[0].name == "self"
|
||||
}
|
||||
|
||||
pub fn self_type(&self) -> Option<SelfTy> {
|
||||
self.inputs.values.get(0).and_then(|v| v.to_self())
|
||||
}
|
||||
|
@ -3547,21 +3540,6 @@ pub struct Path {
|
|||
}
|
||||
|
||||
impl Path {
|
||||
pub fn singleton(name: String) -> Path {
|
||||
Path {
|
||||
global: false,
|
||||
def: Def::Err,
|
||||
segments: vec![PathSegment {
|
||||
name,
|
||||
args: GenericArgs::AngleBracketed {
|
||||
lifetimes: Vec::new(),
|
||||
types: Vec::new(),
|
||||
bindings: Vec::new(),
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn last_name(&self) -> &str {
|
||||
self.segments.last().unwrap().name.as_str()
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
//! This module is used to store stuff from Rust's AST in a more convenient
|
||||
//! manner (and with prettier names) before cleaning.
|
||||
pub use self::StructType::*;
|
||||
pub use self::TypeBound::*;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Name, NodeId};
|
||||
|
@ -91,11 +90,6 @@ pub enum StructType {
|
|||
Unit,
|
||||
}
|
||||
|
||||
pub enum TypeBound {
|
||||
RegionBound,
|
||||
TraitBound(hir::TraitRef)
|
||||
}
|
||||
|
||||
pub struct Struct {
|
||||
pub vis: hir::Visibility,
|
||||
pub stab: Option<attr::Stability>,
|
||||
|
|
|
@ -12,19 +12,13 @@ use std::mem;
|
|||
|
||||
use clean::*;
|
||||
|
||||
pub enum FoldItem {
|
||||
Retain(Item),
|
||||
Strip(Item),
|
||||
Erase,
|
||||
}
|
||||
pub struct StripItem(pub Item);
|
||||
|
||||
impl FoldItem {
|
||||
pub fn fold(self) -> Option<Item> {
|
||||
match self {
|
||||
FoldItem::Erase => None,
|
||||
FoldItem::Retain(i) => Some(i),
|
||||
FoldItem::Strip(item@ Item { inner: StrippedItem(..), .. } ) => Some(item),
|
||||
FoldItem::Strip(mut i) => {
|
||||
impl StripItem {
|
||||
pub fn strip(self) -> Option<Item> {
|
||||
match self.0 {
|
||||
Item { inner: StrippedItem(..), .. } => Some(self.0),
|
||||
mut i => {
|
||||
i.inner = StrippedItem(box i.inner);
|
||||
Some(i)
|
||||
}
|
||||
|
|
|
@ -60,20 +60,6 @@ pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>
|
|||
String::from_utf8_lossy(&out[..]).into_owned()
|
||||
}
|
||||
|
||||
/// Highlights `src`, returning the HTML output. Returns only the inner html to
|
||||
/// be inserted into an element. C.f., `render_with_highlighting` which includes
|
||||
/// an enclosing `<pre>` block.
|
||||
pub fn render_inner_with_highlighting(src: &str) -> io::Result<String> {
|
||||
let sess = parse::ParseSess::new(FilePathMapping::empty());
|
||||
let fm = sess.codemap().new_filemap(FileName::Custom("stdin".to_string()), src.to_string());
|
||||
|
||||
let mut out = Vec::new();
|
||||
let mut classifier = Classifier::new(lexer::StringReader::new(&sess, fm, None), sess.codemap());
|
||||
classifier.write_source(&mut out)?;
|
||||
|
||||
Ok(String::from_utf8_lossy(&out).into_owned())
|
||||
}
|
||||
|
||||
/// Processes a program (nested in the internal `lexer`), classifying strings of
|
||||
/// text by highlighting category (`Class`). Calls out to a `Writer` to write
|
||||
/// each span of text in sequence.
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#![feature(vec_remove_item)]
|
||||
#![feature(entry_and_modify)]
|
||||
#![feature(ptr_offset_from)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
||||
|
@ -72,28 +73,28 @@ use rustc_target::spec::TargetTriple;
|
|||
use rustc::session::config::get_cmd_lint_options;
|
||||
|
||||
#[macro_use]
|
||||
pub mod externalfiles;
|
||||
mod externalfiles;
|
||||
|
||||
pub mod clean;
|
||||
pub mod core;
|
||||
pub mod doctree;
|
||||
pub mod fold;
|
||||
mod clean;
|
||||
mod core;
|
||||
mod doctree;
|
||||
mod fold;
|
||||
pub mod html {
|
||||
pub mod highlight;
|
||||
pub mod escape;
|
||||
pub mod item_type;
|
||||
pub mod format;
|
||||
pub mod layout;
|
||||
crate mod highlight;
|
||||
crate mod escape;
|
||||
crate mod item_type;
|
||||
crate mod format;
|
||||
crate mod layout;
|
||||
pub mod markdown;
|
||||
pub mod render;
|
||||
pub mod toc;
|
||||
crate mod render;
|
||||
crate mod toc;
|
||||
}
|
||||
pub mod markdown;
|
||||
pub mod passes;
|
||||
pub mod visit_ast;
|
||||
pub mod visit_lib;
|
||||
pub mod test;
|
||||
pub mod theme;
|
||||
mod markdown;
|
||||
mod passes;
|
||||
mod visit_ast;
|
||||
mod visit_lib;
|
||||
mod test;
|
||||
mod theme;
|
||||
|
||||
use clean::AttributesExt;
|
||||
|
||||
|
@ -140,7 +141,7 @@ fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
|
|||
RustcOptGroup::unstable(name, f)
|
||||
}
|
||||
|
||||
pub fn opts() -> Vec<RustcOptGroup> {
|
||||
fn opts() -> Vec<RustcOptGroup> {
|
||||
vec![
|
||||
stable("h", |o| o.optflag("h", "help", "show this help message")),
|
||||
stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
|
||||
|
@ -334,7 +335,7 @@ pub fn opts() -> Vec<RustcOptGroup> {
|
|||
]
|
||||
}
|
||||
|
||||
pub fn usage(argv0: &str) {
|
||||
fn usage(argv0: &str) {
|
||||
let mut options = getopts::Options::new();
|
||||
for option in opts() {
|
||||
(option.apply)(&mut options);
|
||||
|
@ -342,7 +343,7 @@ pub fn usage(argv0: &str) {
|
|||
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
|
||||
}
|
||||
|
||||
pub fn main_args(args: &[String]) -> isize {
|
||||
fn main_args(args: &[String]) -> isize {
|
||||
let mut options = getopts::Options::new();
|
||||
for option in opts() {
|
||||
(option.apply)(&mut options);
|
||||
|
|
|
@ -15,7 +15,7 @@ use std::mem;
|
|||
|
||||
use clean::{self, GetDefId, Item};
|
||||
use fold;
|
||||
use fold::FoldItem::Strip;
|
||||
use fold::StripItem;
|
||||
|
||||
mod collapse_docs;
|
||||
pub use self::collapse_docs::collapse_docs;
|
||||
|
@ -35,24 +35,44 @@ pub use self::unindent_comments::unindent_comments;
|
|||
mod 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) -> clean::Crate, // fn
|
||||
&'static str); // description
|
||||
&'static str,
|
||||
); // description
|
||||
|
||||
pub const PASSES: &'static [Pass] = &[
|
||||
("strip-hidden", strip_hidden,
|
||||
"strips all doc(hidden) items from the output"),
|
||||
("unindent-comments", unindent_comments,
|
||||
"removes excess indentation on comments in order for markdown to like it"),
|
||||
("collapse-docs", collapse_docs,
|
||||
"concatenates all document attributes into one document attribute"),
|
||||
("strip-private", strip_private,
|
||||
(
|
||||
"strip-hidden",
|
||||
strip_hidden,
|
||||
"strips all doc(hidden) items from the output",
|
||||
),
|
||||
(
|
||||
"unindent-comments",
|
||||
unindent_comments,
|
||||
"removes excess indentation on comments in order for markdown to like it",
|
||||
),
|
||||
(
|
||||
"collapse-docs",
|
||||
collapse_docs,
|
||||
"concatenates all document attributes into one document attribute",
|
||||
),
|
||||
(
|
||||
"strip-private",
|
||||
strip_private,
|
||||
"strips all private items from a crate which cannot be seen externally, \
|
||||
implies strip-priv-imports"),
|
||||
("strip-priv-imports", strip_priv_imports,
|
||||
"strips all private import statements (`use`, `extern crate`) from a crate"),
|
||||
("propagate-doc-cfg", propagate_doc_cfg,
|
||||
"propagates `#[doc(cfg(...))]` to child items"),
|
||||
implies strip-priv-imports",
|
||||
),
|
||||
(
|
||||
"strip-priv-imports",
|
||||
strip_priv_imports,
|
||||
"strips all private import statements (`use`, `extern crate`) from a crate",
|
||||
),
|
||||
(
|
||||
"propagate-doc-cfg",
|
||||
propagate_doc_cfg,
|
||||
"propagates `#[doc(cfg(...))]` to child items",
|
||||
),
|
||||
];
|
||||
|
||||
pub const DEFAULT_PASSES: &'static [&'static str] = &[
|
||||
|
@ -79,15 +99,9 @@ pub enum DefaultPassOption {
|
|||
|
||||
pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
|
||||
match default_set {
|
||||
DefaultPassOption::Default => {
|
||||
DEFAULT_PASSES
|
||||
},
|
||||
DefaultPassOption::Private => {
|
||||
DEFAULT_PRIVATE_PASSES
|
||||
},
|
||||
DefaultPassOption::None => {
|
||||
&[]
|
||||
},
|
||||
DefaultPassOption::Default => DEFAULT_PASSES,
|
||||
DefaultPassOption::Private => DEFAULT_PRIVATE_PASSES,
|
||||
DefaultPassOption::None => &[],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,14 +124,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
return ret;
|
||||
}
|
||||
// These items can all get re-exported
|
||||
clean::ExistentialItem(..) |
|
||||
clean::TypedefItem(..) | clean::StaticItem(..) |
|
||||
clean::StructItem(..) | clean::EnumItem(..) |
|
||||
clean::TraitItem(..) | clean::FunctionItem(..) |
|
||||
clean::VariantItem(..) | clean::MethodItem(..) |
|
||||
clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) |
|
||||
clean::ConstantItem(..) | clean::UnionItem(..) |
|
||||
clean::AssociatedConstItem(..) | clean::ForeignTypeItem => {
|
||||
clean::ExistentialItem(..)
|
||||
| clean::TypedefItem(..)
|
||||
| clean::StaticItem(..)
|
||||
| clean::StructItem(..)
|
||||
| clean::EnumItem(..)
|
||||
| clean::TraitItem(..)
|
||||
| clean::FunctionItem(..)
|
||||
| clean::VariantItem(..)
|
||||
| clean::MethodItem(..)
|
||||
| clean::ForeignFunctionItem(..)
|
||||
| clean::ForeignStaticItem(..)
|
||||
| clean::ConstantItem(..)
|
||||
| clean::UnionItem(..)
|
||||
| clean::AssociatedConstItem(..)
|
||||
| clean::ForeignTypeItem => {
|
||||
if i.def_id.is_local() {
|
||||
if !self.access_levels.is_exported(i.def_id) {
|
||||
return None;
|
||||
|
@ -127,14 +148,14 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
|
||||
clean::StructFieldItem(..) => {
|
||||
if i.visibility != Some(clean::Public) {
|
||||
return Strip(i).fold();
|
||||
return StripItem(i).strip();
|
||||
}
|
||||
}
|
||||
|
||||
clean::ModuleItem(..) => {
|
||||
if i.def_id.is_local() && i.visibility != Some(clean::Public) {
|
||||
let old = mem::replace(&mut self.update_retained, false);
|
||||
let ret = Strip(self.fold_item_recur(i).unwrap()).fold();
|
||||
let ret = StripItem(self.fold_item_recur(i).unwrap()).strip();
|
||||
self.update_retained = old;
|
||||
return ret;
|
||||
}
|
||||
|
@ -167,7 +188,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
clean::ImplItem(ref imp) if imp.trait_.is_some() => true,
|
||||
// Struct variant fields have inherited visibility
|
||||
clean::VariantItem(clean::Variant {
|
||||
kind: clean::VariantKind::Struct(..)
|
||||
kind: clean::VariantKind::Struct(..),
|
||||
}) => true,
|
||||
_ => false,
|
||||
};
|
||||
|
@ -192,7 +213,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
|
||||
// This stripper discards all impls which reference stripped items
|
||||
struct ImplStripper<'a> {
|
||||
retained: &'a DefIdSet
|
||||
retained: &'a DefIdSet,
|
||||
}
|
||||
|
||||
impl<'a> fold::DocFolder for ImplStripper<'a> {
|
||||
|
@ -203,9 +224,7 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
|
|||
return None;
|
||||
}
|
||||
if let Some(did) = imp.for_.def_id() {
|
||||
if did.is_local() && !imp.for_.is_generic() &&
|
||||
!self.retained.contains(&did)
|
||||
{
|
||||
if did.is_local() && !imp.for_.is_generic() && !self.retained.contains(&did) {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
@ -233,9 +252,12 @@ struct ImportStripper;
|
|||
impl fold::DocFolder for ImportStripper {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
match i.inner {
|
||||
clean::ExternCrateItem(..) |
|
||||
clean::ImportItem(..) if i.visibility != Some(clean::Public) => None,
|
||||
_ => self.fold_item_recur(i)
|
||||
clean::ExternCrateItem(..) | clean::ImportItem(..)
|
||||
if i.visibility != Some(clean::Public) =>
|
||||
{
|
||||
None
|
||||
}
|
||||
_ => self.fold_item_recur(i),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use clean::{self, AttributesExt, NestedAttributesExt};
|
|||
use clean::Item;
|
||||
use fold;
|
||||
use fold::DocFolder;
|
||||
use fold::FoldItem::Strip;
|
||||
use fold::StripItem;
|
||||
use passes::ImplStripper;
|
||||
|
||||
/// Strip items marked `#[doc(hidden)]`
|
||||
|
@ -49,7 +49,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
|
|||
// strip things like impl methods but when doing so
|
||||
// we must not add any items to the `retained` set.
|
||||
let old = mem::replace(&mut self.update_retained, false);
|
||||
let ret = Strip(self.fold_item_recur(i).unwrap()).fold();
|
||||
let ret = StripItem(self.fold_item_recur(i).unwrap()).strip();
|
||||
self.update_retained = old;
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue