Skip to content

Commit d2652f6

Browse files
committed
Auto merge of #52630 - Mark-Simulacrum:rustdoc-cleanup-2, r=QuietMisdreavus
Delete unused code in rustdoc Also hid the unused crate exports of rustdoc. This is technically a breaking change but we don't even ship librustdoc in the sysroot so I don't expect breakage.
2 parents 4fbd4a5 + 620c4fd commit d2652f6

File tree

7 files changed

+96
-121
lines changed

7 files changed

+96
-121
lines changed

src/librustdoc/clean/mod.rs

-22
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,6 @@ impl Item {
425425
pub fn is_enum(&self) -> bool {
426426
self.type_() == ItemType::Enum
427427
}
428-
pub fn is_fn(&self) -> bool {
429-
self.type_() == ItemType::Function
430-
}
431428
pub fn is_associated_type(&self) -> bool {
432429
self.type_() == ItemType::AssociatedType
433430
}
@@ -2188,10 +2185,6 @@ pub struct FnDecl {
21882185
}
21892186

21902187
impl FnDecl {
2191-
pub fn has_self(&self) -> bool {
2192-
self.inputs.values.len() > 0 && self.inputs.values[0].name == "self"
2193-
}
2194-
21952188
pub fn self_type(&self) -> Option<SelfTy> {
21962189
self.inputs.values.get(0).and_then(|v| v.to_self())
21972190
}
@@ -3547,21 +3540,6 @@ pub struct Path {
35473540
}
35483541

35493542
impl Path {
3550-
pub fn singleton(name: String) -> Path {
3551-
Path {
3552-
global: false,
3553-
def: Def::Err,
3554-
segments: vec![PathSegment {
3555-
name,
3556-
args: GenericArgs::AngleBracketed {
3557-
lifetimes: Vec::new(),
3558-
types: Vec::new(),
3559-
bindings: Vec::new(),
3560-
}
3561-
}]
3562-
}
3563-
}
3564-
35653543
pub fn last_name(&self) -> &str {
35663544
self.segments.last().unwrap().name.as_str()
35673545
}

src/librustdoc/doctree.rs

-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//! This module is used to store stuff from Rust's AST in a more convenient
1212
//! manner (and with prettier names) before cleaning.
1313
pub use self::StructType::*;
14-
pub use self::TypeBound::*;
1514

1615
use syntax::ast;
1716
use syntax::ast::{Name, NodeId};
@@ -91,11 +90,6 @@ pub enum StructType {
9190
Unit,
9291
}
9392

94-
pub enum TypeBound {
95-
RegionBound,
96-
TraitBound(hir::TraitRef)
97-
}
98-
9993
pub struct Struct {
10094
pub vis: hir::Visibility,
10195
pub stab: Option<attr::Stability>,

src/librustdoc/fold.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ use std::mem;
1212

1313
use clean::*;
1414

15-
pub enum FoldItem {
16-
Retain(Item),
17-
Strip(Item),
18-
Erase,
19-
}
15+
pub struct StripItem(pub Item);
2016

21-
impl FoldItem {
22-
pub fn fold(self) -> Option<Item> {
23-
match self {
24-
FoldItem::Erase => None,
25-
FoldItem::Retain(i) => Some(i),
26-
FoldItem::Strip(item@ Item { inner: StrippedItem(..), .. } ) => Some(item),
27-
FoldItem::Strip(mut i) => {
17+
impl StripItem {
18+
pub fn strip(self) -> Option<Item> {
19+
match self.0 {
20+
Item { inner: StrippedItem(..), .. } => Some(self.0),
21+
mut i => {
2822
i.inner = StrippedItem(box i.inner);
2923
Some(i)
3024
}

src/librustdoc/html/highlight.rs

-14
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,6 @@ pub fn render_with_highlighting(src: &str, class: Option<&str>, id: Option<&str>
6060
String::from_utf8_lossy(&out[..]).into_owned()
6161
}
6262

63-
/// Highlights `src`, returning the HTML output. Returns only the inner html to
64-
/// be inserted into an element. C.f., `render_with_highlighting` which includes
65-
/// an enclosing `<pre>` block.
66-
pub fn render_inner_with_highlighting(src: &str) -> io::Result<String> {
67-
let sess = parse::ParseSess::new(FilePathMapping::empty());
68-
let fm = sess.codemap().new_filemap(FileName::Custom("stdin".to_string()), src.to_string());
69-
70-
let mut out = Vec::new();
71-
let mut classifier = Classifier::new(lexer::StringReader::new(&sess, fm, None), sess.codemap());
72-
classifier.write_source(&mut out)?;
73-
74-
Ok(String::from_utf8_lossy(&out).into_owned())
75-
}
76-
7763
/// Processes a program (nested in the internal `lexer`), classifying strings of
7864
/// text by highlighting category (`Class`). Calls out to a `Writer` to write
7965
/// each span of text in sequence.

src/librustdoc/lib.rs

+22-21
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(vec_remove_item)]
2626
#![feature(entry_and_modify)]
2727
#![feature(ptr_offset_from)]
28+
#![feature(crate_visibility_modifier)]
2829

2930
#![recursion_limit="256"]
3031

@@ -72,28 +73,28 @@ use rustc_target::spec::TargetTriple;
7273
use rustc::session::config::get_cmd_lint_options;
7374

7475
#[macro_use]
75-
pub mod externalfiles;
76+
mod externalfiles;
7677

77-
pub mod clean;
78-
pub mod core;
79-
pub mod doctree;
80-
pub mod fold;
78+
mod clean;
79+
mod core;
80+
mod doctree;
81+
mod fold;
8182
pub mod html {
82-
pub mod highlight;
83-
pub mod escape;
84-
pub mod item_type;
85-
pub mod format;
86-
pub mod layout;
83+
crate mod highlight;
84+
crate mod escape;
85+
crate mod item_type;
86+
crate mod format;
87+
crate mod layout;
8788
pub mod markdown;
88-
pub mod render;
89-
pub mod toc;
89+
crate mod render;
90+
crate mod toc;
9091
}
91-
pub mod markdown;
92-
pub mod passes;
93-
pub mod visit_ast;
94-
pub mod visit_lib;
95-
pub mod test;
96-
pub mod theme;
92+
mod markdown;
93+
mod passes;
94+
mod visit_ast;
95+
mod visit_lib;
96+
mod test;
97+
mod theme;
9798

9899
use clean::AttributesExt;
99100

@@ -140,7 +141,7 @@ fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
140141
RustcOptGroup::unstable(name, f)
141142
}
142143

143-
pub fn opts() -> Vec<RustcOptGroup> {
144+
fn opts() -> Vec<RustcOptGroup> {
144145
vec![
145146
stable("h", |o| o.optflag("h", "help", "show this help message")),
146147
stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
@@ -334,15 +335,15 @@ pub fn opts() -> Vec<RustcOptGroup> {
334335
]
335336
}
336337

337-
pub fn usage(argv0: &str) {
338+
fn usage(argv0: &str) {
338339
let mut options = getopts::Options::new();
339340
for option in opts() {
340341
(option.apply)(&mut options);
341342
}
342343
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
343344
}
344345

345-
pub fn main_args(args: &[String]) -> isize {
346+
fn main_args(args: &[String]) -> isize {
346347
let mut options = getopts::Options::new();
347348
for option in opts() {
348349
(option.apply)(&mut options);

src/librustdoc/passes/mod.rs

+66-44
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::mem;
1515

1616
use clean::{self, GetDefId, Item};
1717
use fold;
18-
use fold::FoldItem::Strip;
18+
use fold::StripItem;
1919

2020
mod collapse_docs;
2121
pub use self::collapse_docs::collapse_docs;
@@ -35,24 +35,44 @@ pub use self::unindent_comments::unindent_comments;
3535
mod propagate_doc_cfg;
3636
pub use self::propagate_doc_cfg::propagate_doc_cfg;
3737

38-
type Pass = (&'static str, // name
39-
fn(clean::Crate) -> clean::Crate, // fn
40-
&'static str); // description
38+
type Pass = (
39+
&'static str, // name
40+
fn(clean::Crate) -> clean::Crate, // fn
41+
&'static str,
42+
); // description
4143

4244
pub const PASSES: &'static [Pass] = &[
43-
("strip-hidden", strip_hidden,
44-
"strips all doc(hidden) items from the output"),
45-
("unindent-comments", unindent_comments,
46-
"removes excess indentation on comments in order for markdown to like it"),
47-
("collapse-docs", collapse_docs,
48-
"concatenates all document attributes into one document attribute"),
49-
("strip-private", strip_private,
50-
"strips all private items from a crate which cannot be seen externally, \
51-
implies strip-priv-imports"),
52-
("strip-priv-imports", strip_priv_imports,
53-
"strips all private import statements (`use`, `extern crate`) from a crate"),
54-
("propagate-doc-cfg", propagate_doc_cfg,
55-
"propagates `#[doc(cfg(...))]` to child items"),
45+
(
46+
"strip-hidden",
47+
strip_hidden,
48+
"strips all doc(hidden) items from the output",
49+
),
50+
(
51+
"unindent-comments",
52+
unindent_comments,
53+
"removes excess indentation on comments in order for markdown to like it",
54+
),
55+
(
56+
"collapse-docs",
57+
collapse_docs,
58+
"concatenates all document attributes into one document attribute",
59+
),
60+
(
61+
"strip-private",
62+
strip_private,
63+
"strips all private items from a crate which cannot be seen externally, \
64+
implies strip-priv-imports",
65+
),
66+
(
67+
"strip-priv-imports",
68+
strip_priv_imports,
69+
"strips all private import statements (`use`, `extern crate`) from a crate",
70+
),
71+
(
72+
"propagate-doc-cfg",
73+
propagate_doc_cfg,
74+
"propagates `#[doc(cfg(...))]` to child items",
75+
),
5676
];
5777

5878
pub const DEFAULT_PASSES: &'static [&'static str] = &[
@@ -79,15 +99,9 @@ pub enum DefaultPassOption {
7999

80100
pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
81101
match default_set {
82-
DefaultPassOption::Default => {
83-
DEFAULT_PASSES
84-
},
85-
DefaultPassOption::Private => {
86-
DEFAULT_PRIVATE_PASSES
87-
},
88-
DefaultPassOption::None => {
89-
&[]
90-
},
102+
DefaultPassOption::Default => DEFAULT_PASSES,
103+
DefaultPassOption::Private => DEFAULT_PRIVATE_PASSES,
104+
DefaultPassOption::None => &[],
91105
}
92106
}
93107

@@ -110,14 +124,21 @@ impl<'a> fold::DocFolder for Stripper<'a> {
110124
return ret;
111125
}
112126
// These items can all get re-exported
113-
clean::ExistentialItem(..) |
114-
clean::TypedefItem(..) | clean::StaticItem(..) |
115-
clean::StructItem(..) | clean::EnumItem(..) |
116-
clean::TraitItem(..) | clean::FunctionItem(..) |
117-
clean::VariantItem(..) | clean::MethodItem(..) |
118-
clean::ForeignFunctionItem(..) | clean::ForeignStaticItem(..) |
119-
clean::ConstantItem(..) | clean::UnionItem(..) |
120-
clean::AssociatedConstItem(..) | clean::ForeignTypeItem => {
127+
clean::ExistentialItem(..)
128+
| clean::TypedefItem(..)
129+
| clean::StaticItem(..)
130+
| clean::StructItem(..)
131+
| clean::EnumItem(..)
132+
| clean::TraitItem(..)
133+
| clean::FunctionItem(..)
134+
| clean::VariantItem(..)
135+
| clean::MethodItem(..)
136+
| clean::ForeignFunctionItem(..)
137+
| clean::ForeignStaticItem(..)
138+
| clean::ConstantItem(..)
139+
| clean::UnionItem(..)
140+
| clean::AssociatedConstItem(..)
141+
| clean::ForeignTypeItem => {
121142
if i.def_id.is_local() {
122143
if !self.access_levels.is_exported(i.def_id) {
123144
return None;
@@ -127,14 +148,14 @@ impl<'a> fold::DocFolder for Stripper<'a> {
127148

128149
clean::StructFieldItem(..) => {
129150
if i.visibility != Some(clean::Public) {
130-
return Strip(i).fold();
151+
return StripItem(i).strip();
131152
}
132153
}
133154

134155
clean::ModuleItem(..) => {
135156
if i.def_id.is_local() && i.visibility != Some(clean::Public) {
136157
let old = mem::replace(&mut self.update_retained, false);
137-
let ret = Strip(self.fold_item_recur(i).unwrap()).fold();
158+
let ret = StripItem(self.fold_item_recur(i).unwrap()).strip();
138159
self.update_retained = old;
139160
return ret;
140161
}
@@ -167,7 +188,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
167188
clean::ImplItem(ref imp) if imp.trait_.is_some() => true,
168189
// Struct variant fields have inherited visibility
169190
clean::VariantItem(clean::Variant {
170-
kind: clean::VariantKind::Struct(..)
191+
kind: clean::VariantKind::Struct(..),
171192
}) => true,
172193
_ => false,
173194
};
@@ -192,7 +213,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
192213

193214
// This stripper discards all impls which reference stripped items
194215
struct ImplStripper<'a> {
195-
retained: &'a DefIdSet
216+
retained: &'a DefIdSet,
196217
}
197218

198219
impl<'a> fold::DocFolder for ImplStripper<'a> {
@@ -203,9 +224,7 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
203224
return None;
204225
}
205226
if let Some(did) = imp.for_.def_id() {
206-
if did.is_local() && !imp.for_.is_generic() &&
207-
!self.retained.contains(&did)
208-
{
227+
if did.is_local() && !imp.for_.is_generic() && !self.retained.contains(&did) {
209228
return None;
210229
}
211230
}
@@ -233,9 +252,12 @@ struct ImportStripper;
233252
impl fold::DocFolder for ImportStripper {
234253
fn fold_item(&mut self, i: Item) -> Option<Item> {
235254
match i.inner {
236-
clean::ExternCrateItem(..) |
237-
clean::ImportItem(..) if i.visibility != Some(clean::Public) => None,
238-
_ => self.fold_item_recur(i)
255+
clean::ExternCrateItem(..) | clean::ImportItem(..)
256+
if i.visibility != Some(clean::Public) =>
257+
{
258+
None
259+
}
260+
_ => self.fold_item_recur(i),
239261
}
240262
}
241263
}

src/librustdoc/passes/strip_hidden.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use clean::{self, AttributesExt, NestedAttributesExt};
1515
use clean::Item;
1616
use fold;
1717
use fold::DocFolder;
18-
use fold::FoldItem::Strip;
18+
use fold::StripItem;
1919
use passes::ImplStripper;
2020

2121
/// Strip items marked `#[doc(hidden)]`
@@ -49,7 +49,7 @@ impl<'a> fold::DocFolder for Stripper<'a> {
4949
// strip things like impl methods but when doing so
5050
// we must not add any items to the `retained` set.
5151
let old = mem::replace(&mut self.update_retained, false);
52-
let ret = Strip(self.fold_item_recur(i).unwrap()).fold();
52+
let ret = StripItem(self.fold_item_recur(i).unwrap()).strip();
5353
self.update_retained = old;
5454
return ret;
5555
}

0 commit comments

Comments
 (0)