diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c2a37a555d693..6c9ee52878201 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -507,12 +507,6 @@ impl attr::AttrMetaMethods for Attribute { fn meta_item_list<'a>(&'a self) -> Option<&'a [P]> { 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 { (**self).value_str() } - fn meta_item_list(&self) -> Option<&[P]> { None } - fn span(&self) -> codemap::Span { unimplemented!() } -} #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)] pub struct TyParam { diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index afe1387ad9fe6..ceec80402c01e 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -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 { @@ -20,12 +18,10 @@ pub trait DocFolder : Sized { /// don't override! fn fold_item_recur(&mut self, item: Item) -> Option { 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) }, @@ -33,29 +29,25 @@ pub trait DocFolder : Sized { 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}) }, @@ -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 } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d424c7383be3f..2cb2b299e4017 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -374,7 +374,7 @@ fn init_ids() -> HashMap { "deref-methods", "implementations", "derived_implementations" - ].into_iter().map(|id| (String::from(*id), 1)).collect::>() + ].into_iter().map(|id| (String::from(*id), 1)).collect() } /// This method resets the local table of used ID attributes. This is typically diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index 6293aa3c2725c..6f6a72fa9fe7d 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -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 { - let mut i = i; + fn fold_item(&mut self, mut i: Item) -> Option { let mut avec: Vec = Vec::new(); for attr in &i.attrs { match attr { @@ -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 { + fn fold_item(&mut self, mut i: Item) -> Option { 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 {