diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f658d57426497..7454f79ed6bbb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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 { 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() } diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 591c660138aee..d6e8f3d938e93 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -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, diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index ddc5d56b474fc..6d96bc8e36038 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -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 { - 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 { + match self.0 { + Item { inner: StrippedItem(..), .. } => Some(self.0), + mut i => { i.inner = StrippedItem(box i.inner); Some(i) } diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 6cf9b143373a8..065778d8d0725 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -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 `
` block.
-pub fn render_inner_with_highlighting(src: &str) -> io::Result {
-    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.
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 613ca01ff82f8..041a233617083 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -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(name: &'static str, f: F) -> RustcOptGroup
     RustcOptGroup::unstable(name, f)
 }
 
-pub fn opts() -> Vec {
+fn opts() -> Vec {
     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 {
     ]
 }
 
-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] ", 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);
diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs
index 8de4fed5bf0c0..aa4acaf75bf31 100644
--- a/src/librustdoc/passes/mod.rs
+++ b/src/librustdoc/passes/mod.rs
@@ -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
-             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] = &[
@@ -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 {
         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),
         }
     }
 }
diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs
index b1545233f8a2b..279c9603703cd 100644
--- a/src/librustdoc/passes/strip_hidden.rs
+++ b/src/librustdoc/passes/strip_hidden.rs
@@ -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;
                 }