]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #31837 - mitaa:rdoc-inherent-assoc, r=alexcrichton
authorManish Goregaokar <manishsmail@gmail.com>
Thu, 25 Feb 2016 06:11:02 +0000 (11:41 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Thu, 25 Feb 2016 09:36:07 +0000 (15:06 +0530)
This effectively only records associated items from either inherent impls or trait definitions in the search-index.

fixes #31808

r? @alexcrichton

1  2 
src/librustdoc/html/render.rs

index 42cf23aff03e104cd8dca0b7a2dc56c28e9b1ffd,8a061e3a528e78d5269a834946509f9c32774b15..d7100f9f2204684c8a6c41d12f9951c98a9212b6
@@@ -46,7 -46,7 +46,7 @@@ use std::io::prelude::*
  use std::io::{self, BufWriter, BufReader};
  use std::iter::repeat;
  use std::mem;
 -use std::path::{PathBuf, Path};
 +use std::path::{PathBuf, Path, Component};
  use std::str;
  use std::sync::Arc;
  
@@@ -243,6 -243,7 +243,7 @@@ pub struct Cache 
  
      stack: Vec<String>,
      parent_stack: Vec<DefId>,
+     parent_is_trait_impl: bool,
      search_index: Vec<IndexItem>,
      privmod: bool,
      remove_priv: bool,
@@@ -487,6 -488,7 +488,7 @@@ pub fn run(mut krate: clean::Crate
          stack: Vec::new(),
          parent_stack: Vec::new(),
          search_index: Vec::new(),
+         parent_is_trait_impl: false,
          extern_locations: HashMap::new(),
          primitive_locations: HashMap::new(),
          remove_priv: cx.passes.contains("strip-private"),
@@@ -810,17 -812,16 +812,17 @@@ fn clean_srcpath<F>(src_root: &Path, p
      // make it relative, if possible
      let p = p.strip_prefix(src_root).unwrap_or(p);
  
 -    let mut iter = p.iter().map(|x| x.to_str().unwrap()).peekable();
 +    let mut iter = p.components().peekable();
 +
      while let Some(c) = iter.next() {
          if !keep_filename && iter.peek().is_none() {
              break;
          }
  
 -        if ".." == c {
 -            f("up");
 -        } else {
 -            f(c)
 +        match c {
 +            Component::ParentDir => f("up"),
 +            Component::Normal(c) => f(c.to_str().unwrap()),
 +            _ => continue,
          }
      }
  }
@@@ -872,7 -873,7 +874,7 @@@ impl<'a> DocFolder for SourceCollector<
              // entire crate. The other option is maintaining this mapping on a
              // per-file basis, but that's probably not worth it...
              self.cx
 -                .include_sources = match self.emit_source(&item.source .filename) {
 +                .include_sources = match self.emit_source(&item.source.filename) {
                  Ok(()) => true,
                  Err(e) => {
                      println!("warning: source code was requested to be rendered, \
@@@ -996,6 -997,11 +998,11 @@@ impl DocFolder for Cache 
          // Index this method for searching later on
          if let Some(ref s) = item.name {
              let (parent, is_method) = match item.inner {
+                 clean::AssociatedConstItem(..) |
+                 clean::TypedefItem(_, true) if self.parent_is_trait_impl => {
+                     // skip associated items in trait impls
+                     ((None, None), false)
+                 }
                  clean::AssociatedTypeItem(..) |
                  clean::AssociatedConstItem(..) |
                  clean::TyMethodItem(..) |
                          ((Some(*last), path), true)
                      }
                  }
-                 clean::TypedefItem(_, true) => {
-                     // skip associated types in impls
-                     ((None, None), false)
-                 }
                  _ => ((None, Some(&*self.stack)), false)
              };
              let hidden_field = match item.inner {
          }
  
          // Maintain the parent stack
+         let orig_parent_is_trait_impl = self.parent_is_trait_impl;
          let parent_pushed = match item.inner {
              clean::TraitItem(..) | clean::EnumItem(..) | clean::StructItem(..) => {
                  self.parent_stack.push(item.def_id);
+                 self.parent_is_trait_impl = false;
                  true
              }
              clean::ImplItem(ref i) => {
+                 self.parent_is_trait_impl = i.trait_.is_some();
                  match i.for_ {
                      clean::ResolvedPath{ did, .. } => {
                          self.parent_stack.push(did);
          if pushed { self.stack.pop().unwrap(); }
          if parent_pushed { self.parent_stack.pop().unwrap(); }
          self.privmod = orig_privmod;
+         self.parent_is_trait_impl = orig_parent_is_trait_impl;
          return ret;
      }
  }
@@@ -1490,11 -1496,9 +1497,11 @@@ impl<'a> Item<'a> 
                            true, |component| {
                  path.push(component.to_string());
              });
 +
              // If the span points into an external macro the
              // source-file will be bogus, i.e `<foo macros>`
 -            if Path::new(&self.item.source.filename).is_file() {
 +            let filename = &self.item.source.filename;
 +            if !(filename.starts_with("<") && filename.ends_with("macros>")) {
                  Some(format!("{root}src/{krate}/{path}.html#{href}",
                               root = self.cx.root_path,
                               krate = self.cx.layout.krate,
@@@ -2737,19 -2741,18 +2744,19 @@@ fn make_item_keywords(it: &clean::Item
  
  fn get_index_search_type(item: &clean::Item,
                           parent: Option<String>) -> Option<IndexItemFunctionType> {
 -    let decl = match item.inner {
 -        clean::FunctionItem(ref f) => &f.decl,
 -        clean::MethodItem(ref m) => &m.decl,
 -        clean::TyMethodItem(ref m) => &m.decl,
 +    let (decl, selfty) = match item.inner {
 +        clean::FunctionItem(ref f) => (&f.decl, None),
 +        clean::MethodItem(ref m) => (&m.decl, Some(&m.self_)),
 +        clean::TyMethodItem(ref m) => (&m.decl, Some(&m.self_)),
          _ => return None
      };
  
      let mut inputs = Vec::new();
  
      // Consider `self` an argument as well.
 -    if let Some(name) = parent {
 -        inputs.push(Type { name: Some(name.to_ascii_lowercase()) });
 +    match parent.and_then(|p| selfty.map(|s| (p, s)) ) {
 +        Some((_, &clean::SelfStatic)) | None => (),
 +        Some((name, _)) => inputs.push(Type { name: Some(name.to_ascii_lowercase()) }),
      }
  
      inputs.extend(&mut decl.inputs.values.iter().map(|arg| {