Skip to content

Commit

Permalink
This doesn't seem necessary?
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Mar 4, 2016
1 parent d78f19e commit 938c8c1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
6 changes: 0 additions & 6 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,6 @@ impl attr::AttrMetaMethods for Attribute {
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
fn span(&self) -> codemap::Span { unimplemented!() }
}
impl<'a> attr::AttrMetaMethods for &'a Attribute {
fn name(&self) -> InternedString { (**self).name() }
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
fn meta_item_list(&self) -> Option<&[P<ast::MetaItem>]> { None }
fn span(&self) -> codemap::Span { unimplemented!() }
}

#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
pub struct TyParam {
Expand Down
40 changes: 14 additions & 26 deletions src/librustdoc/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// except according to those terms.

use clean::*;
use std::collections::HashMap;
use std::mem::{replace, swap};

pub trait DocFolder : Sized {
fn fold_item(&mut self, item: Item) -> Option<Item> {
Expand All @@ -20,42 +18,36 @@ pub trait DocFolder : Sized {
/// don't override!
fn fold_item_recur(&mut self, item: Item) -> Option<Item> {
let Item { attrs, name, source, visibility, def_id, inner, stability, deprecation } = item;
let inner = inner;
let inner = match inner {
StructItem(mut i) => {
let mut foo = Vec::new(); swap(&mut foo, &mut i.fields);
let num_fields = foo.len();
i.fields.extend(foo.into_iter().filter_map(|x| self.fold_item(x)));
let num_fields = i.fields.len();
i.fields = i.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
i.fields_stripped |= num_fields != i.fields.len();
StructItem(i)
},
ModuleItem(i) => {
ModuleItem(self.fold_mod(i))
},
EnumItem(mut i) => {
let mut foo = Vec::new(); swap(&mut foo, &mut i.variants);
let num_variants = foo.len();
i.variants.extend(foo.into_iter().filter_map(|x| self.fold_item(x)));
let num_variants = i.variants.len();
i.variants = i.variants.into_iter().filter_map(|x| self.fold_item(x)).collect();
i.variants_stripped |= num_variants != i.variants.len();
EnumItem(i)
},
TraitItem(mut i) => {
let mut foo = Vec::new(); swap(&mut foo, &mut i.items);
i.items.extend(foo.into_iter().filter_map(|x| self.fold_item(x)));
i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect();
TraitItem(i)
},
ImplItem(mut i) => {
let mut foo = Vec::new(); swap(&mut foo, &mut i.items);
i.items.extend(foo.into_iter().filter_map(|x| self.fold_item(x)));
i.items = i.items.into_iter().filter_map(|x| self.fold_item(x)).collect();
ImplItem(i)
},
VariantItem(i) => {
let i2 = i.clone(); // this clone is small
match i.kind {
StructVariant(mut j) => {
let mut foo = Vec::new(); swap(&mut foo, &mut j.fields);
let num_fields = foo.len();
j.fields.extend(foo.into_iter().filter_map(|x| self.fold_item(x)));
let num_fields = j.fields.len();
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
j.fields_stripped |= num_fields != j.fields.len();
VariantItem(Variant {kind: StructVariant(j), ..i2})
},
Expand All @@ -78,17 +70,13 @@ pub trait DocFolder : Sized {
}

fn fold_crate(&mut self, mut c: Crate) -> Crate {
c.module = match replace(&mut c.module, None) {
Some(module) => self.fold_item(module), None => None
};

let external_traits = replace(&mut c.external_traits, HashMap::new());
c.external_traits = external_traits.into_iter().map(|(k, mut v)| {
let items = replace(&mut v.items, Vec::new());
v.items = items.into_iter().filter_map(|i| self.fold_item(i))
.collect();
c.module = c.module.and_then(|module| {
self.fold_item(module)
});
c.external_traits = c.external_traits.into_iter().map(|(k, mut v)| {
v.items = v.items.into_iter().filter_map(|i| self.fold_item(i)).collect();
(k, v)
}).collect();
return c;
c
}
}
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn init_ids() -> HashMap<String, usize> {
"deref-methods",
"implementations",
"derived_implementations"
].into_iter().map(|id| (String::from(*id), 1)).collect::<HashMap<_, _>>()
].into_iter().map(|id| (String::from(*id), 1)).collect()
}

/// This method resets the local table of used ID attributes. This is typically
Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ impl<'a> fold::DocFolder for ImplStripper<'a> {
pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
struct CommentCleaner;
impl fold::DocFolder for CommentCleaner {
fn fold_item(&mut self, i: Item) -> Option<Item> {
let mut i = i;
fn fold_item(&mut self, mut i: Item) -> Option<Item> {
let mut avec: Vec<clean::Attribute> = Vec::new();
for attr in &i.attrs {
match attr {
Expand All @@ -268,9 +267,8 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
struct Collapser;
impl fold::DocFolder for Collapser {
fn fold_item(&mut self, i: Item) -> Option<Item> {
fn fold_item(&mut self, mut i: Item) -> Option<Item> {
let mut docstr = String::new();
let mut i = i;
for attr in &i.attrs {
if let clean::NameValue(ref x, ref s) = *attr {
if "doc" == *x {
Expand Down

0 comments on commit 938c8c1

Please sign in to comment.