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