Skip to content

Commit

Permalink
Delete unused code in rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jul 30, 2018
1 parent 54628c8 commit 620c4fd
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 121 deletions.
22 changes: 0 additions & 22 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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()
}
Expand Down
6 changes: 0 additions & 6 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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>,
Expand Down
18 changes: 6 additions & 12 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 0 additions & 14 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
43 changes: 22 additions & 21 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#![feature(vec_remove_item)]
#![feature(entry_and_modify)]
#![feature(ptr_offset_from)]
#![feature(crate_visibility_modifier)]

#![recursion_limit="256"]

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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")),
Expand Down Expand Up @@ -334,15 +335,15 @@ 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);
}
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);
Expand Down
110 changes: 66 additions & 44 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
fn(clean::Crate) -> clean::Crate, // fn
&'static str); // description
type Pass = (
&'static str, // name
fn(clean::Crate) -> clean::Crate, // fn
&'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,
"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"),
(
"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",
),
];

pub const DEFAULT_PASSES: &'static [&'static str] = &[
Expand All @@ -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 => &[],
}
}

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
};
Expand All @@ -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> {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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),
}
}
}
4 changes: 2 additions & 2 deletions src/librustdoc/passes/strip_hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]`
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 620c4fd

Please sign in to comment.