]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #34587 - ollie27:rustdoc_prim_titles, r=steveklabnik
authorbors <bors@rust-lang.org>
Wed, 6 Jul 2016 03:16:40 +0000 (20:16 -0700)
committerGitHub <noreply@github.com>
Wed, 6 Jul 2016 03:16:40 +0000 (20:16 -0700)
rustdoc: Remove paths from primitive page <title> tags

Currently primitive pages have a title like "std::u8 - Rust" this changes
it to "u8 - Rust" as "std::u8" is the name of a module not a primitive
type.

1  2 
src/librustdoc/clean/mod.rs
src/librustdoc/html/render.rs

index 139dedeb70fdf061cee3dc7dc1ee9277836134a3,bc3d9d83399f8340ab6b2a4dcb2cf720ea22915c..7827459baa87f310818813f69320e9982cbd0859
@@@ -317,6 -317,9 +317,9 @@@ impl Item 
      pub fn is_ty_method(&self) -> bool {
          ItemType::from_item(self) == ItemType::TyMethod
      }
+     pub fn is_primitive(&self) -> bool {
+         ItemType::from_item(self) == ItemType::Primitive
+     }
      pub fn is_stripped(&self) -> bool {
          match self.inner { StrippedItem(..) => true, _ => false }
      }
@@@ -2239,9 -2242,14 +2242,9 @@@ pub struct Impl 
      pub trait_: Option<Type>,
      pub for_: Type,
      pub items: Vec<Item>,
 -    pub derived: bool,
      pub polarity: Option<ImplPolarity>,
  }
  
 -fn detect_derived<M: AttrMetaMethods>(attrs: &[M]) -> bool {
 -    attr::contains_name(attrs, "automatically_derived")
 -}
 -
  impl Clean<Vec<Item>> for doctree::Impl {
      fn clean(&self, cx: &DocContext) -> Vec<Item> {
          let mut ret = Vec::new();
                  trait_: trait_,
                  for_: self.for_.clean(cx),
                  items: items,
 -                derived: detect_derived(&self.attrs),
                  polarity: Some(self.polarity.clean(cx)),
              }),
          });
index acf867561a6370aa6084c3426f6497071dd7118b,35be593b3bd817006b6b2034c2da2f999f6ce820..6ab2bcc768590f16a5285188725d06f0c147039d
@@@ -399,6 -399,7 +399,6 @@@ fn init_ids() -> HashMap<String, usize
       "methods",
       "deref-methods",
       "implementations",
 -     "derived_implementations"
       ].into_iter().map(|id| (String::from(*id), 1)).collect()
  }
  
@@@ -589,16 -590,19 +589,16 @@@ fn build_index(krate: &clean::Crate, ca
      // Attach all orphan methods to the type's definition if the type
      // has since been learned.
      for &(did, ref item) in orphan_methods {
 -        match paths.get(&did) {
 -            Some(&(ref fqp, _)) => {
 -                search_index.push(IndexItem {
 -                    ty: shortty(item),
 -                    name: item.name.clone().unwrap(),
 -                    path: fqp[..fqp.len() - 1].join("::"),
 -                    desc: Escape(&shorter(item.doc_value())).to_string(),
 -                    parent: Some(did),
 -                    parent_idx: None,
 -                    search_type: get_index_search_type(&item),
 -                });
 -            },
 -            None => {}
 +        if let Some(&(ref fqp, _)) = paths.get(&did) {
 +            search_index.push(IndexItem {
 +                ty: shortty(item),
 +                name: item.name.clone().unwrap(),
 +                path: fqp[..fqp.len() - 1].join("::"),
 +                desc: Escape(&shorter(item.doc_value())).to_string(),
 +                parent: Some(did),
 +                parent_idx: None,
 +                search_type: get_index_search_type(&item),
 +            });
          }
      }
  
@@@ -1304,7 -1308,12 +1304,12 @@@ impl Context 
                  *slot.borrow_mut() = cx.current.clone();
              });
  
-             let mut title = cx.current.join("::");
+             let mut title = if it.is_primitive() {
+                 // No need to include the namespace for primitive types
+                 String::new()
+             } else {
+                 cx.current.join("::")
+             };
              if pushname {
                  if !title.is_empty() {
                      title.push_str("::");
@@@ -1555,11 -1564,7 +1560,7 @@@ impl<'a> fmt::Display for Item<'a> 
              clean::PrimitiveItem(..) => write!(fmt, "Primitive Type ")?,
              _ => {}
          }
-         let is_primitive = match self.item.inner {
-             clean::PrimitiveItem(..) => true,
-             _ => false,
-         };
-         if !is_primitive {
+         if !self.item.is_primitive() {
              let cur = &self.cx.current;
              let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
              for (i, component) in cur.iter().enumerate().take(amt) {
          // [src] link in the downstream documentation will actually come back to
          // this page, and this link will be auto-clicked. The `id` attribute is
          // used to find the link to auto-click.
-         if self.cx.shared.include_sources && !is_primitive {
+         if self.cx.shared.include_sources && !self.item.is_primitive() {
              if let Some(l) = self.href() {
                  write!(fmt, "<a id='src-{}' class='srclink' \
                                href='{}' title='{}'>[src]</a>",
@@@ -2090,12 -2095,15 +2091,12 @@@ fn item_trait(w: &mut fmt::Formatter, c
          <h2 id='implementors'>Implementors</h2>
          <ul class='item-list' id='implementors-list'>
      ")?;
 -    match cache.implementors.get(&it.def_id) {
 -        Some(implementors) => {
 -            for i in implementors {
 -                write!(w, "<li><code>")?;
 -                fmt_impl_for_trait_page(&i.impl_, w)?;
 -                writeln!(w, "</code></li>")?;
 -            }
 +    if let Some(implementors) = cache.implementors.get(&it.def_id) {
 +        for i in implementors {
 +            write!(w, "<li><code>")?;
 +            fmt_impl_for_trait_page(&i.impl_, w)?;
 +            writeln!(w, "</code></li>")?;
          }
 -        None => {}
      }
      write!(w, "</ul>")?;
      write!(w, r#"<script type="text/javascript" async
@@@ -2520,11 -2528,25 +2521,11 @@@ fn render_assoc_items(w: &mut fmt::Form
          }
          write!(w, "<h2 id='implementations'>Trait \
                     Implementations</h2>")?;
 -        let (derived, manual): (Vec<_>, Vec<&Impl>) = traits.iter().partition(|i| {
 -            i.inner_impl().derived
 -        });
 -        for i in &manual {
 +        for i in &traits {
              let did = i.trait_did().unwrap();
              let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods);
              render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?;
          }
 -        if !derived.is_empty() {
 -            write!(w, "<h3 id='derived_implementations'>\
 -                           Derived Implementations \
 -                       </h3>")?;
 -            for i in &derived {
 -                let did = i.trait_did().unwrap();
 -                let assoc_link = AssocItemLink::GotoSource(did,
 -                                                           &i.inner_impl().provided_trait_methods);
 -                render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?;
 -            }
 -        }
      }
      Ok(())
  }