about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustdoc/clean/auto_trait.rs51
-rw-r--r--src/librustdoc/clean/inline.rs8
-rw-r--r--src/librustdoc/clean/mod.rs3
-rw-r--r--src/test/rustdoc/auto-impl-primitive.rs17
4 files changed, 63 insertions, 16 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs
index 722dcb7fe6a..d655f570ab3 100644
--- a/src/librustdoc/clean/auto_trait.rs
+++ b/src/librustdoc/clean/auto_trait.rs
@@ -35,10 +35,29 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
                 AdtKind::Enum => Def::Enum,
                 AdtKind::Union => Def::Union,
             }
-            _ => panic!("Unexpected type {:?}", def_id),
+            ty::TyInt(_) |
+            ty::TyUint(_) |
+            ty::TyFloat(_) |
+            ty::TyStr |
+            ty::TyBool |
+            ty::TyChar => return self.get_auto_trait_impls(def_id, &move |_: DefId| {
+                match ty.sty {
+                    ty::TyInt(x) => Def::PrimTy(hir::TyInt(x)),
+                    ty::TyUint(x) => Def::PrimTy(hir::TyUint(x)),
+                    ty::TyFloat(x) => Def::PrimTy(hir::TyFloat(x)),
+                    ty::TyStr => Def::PrimTy(hir::TyStr),
+                    ty::TyBool => Def::PrimTy(hir::TyBool),
+                    ty::TyChar => Def::PrimTy(hir::TyChar),
+                    _ => unreachable!(),
+                }
+            }, None),
+            _ => {
+                debug!("Unexpected type {:?}", def_id);
+                return Vec::new()
+            }
         };
 
-        self.get_auto_trait_impls(def_id, def_ctor, None)
+        self.get_auto_trait_impls(def_id, &def_ctor, None)
     }
 
     pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec<Item> {
@@ -52,15 +71,16 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
             _ => panic!("Unexpected type {:?} {:?}", item, id),
         };
 
-        self.get_auto_trait_impls(did, def_ctor, Some(name))
+        self.get_auto_trait_impls(did, &def_ctor, Some(name))
     }
 
-    pub fn get_auto_trait_impls(
+    pub fn get_auto_trait_impls<F>(
         &self,
         def_id: DefId,
-        def_ctor: fn(DefId) -> Def,
+        def_ctor: &F,
         name: Option<String>,
-    ) -> Vec<Item> {
+    ) -> Vec<Item>
+    where F: Fn(DefId) -> Def {
         if self.cx
             .tcx
             .get_attrs(def_id)
@@ -68,9 +88,9 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
             .has_word("hidden")
         {
             debug!(
-                "get_auto_trait_impls(def_id={:?}, def_ctor={:?}): item has doc('hidden'), \
+                "get_auto_trait_impls(def_id={:?}, def_ctor=...): item has doc('hidden'), \
                  aborting",
-                def_id, def_ctor
+                def_id
             );
             return Vec::new();
         }
@@ -79,8 +99,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
         let generics = self.cx.tcx.generics_of(def_id);
 
         debug!(
-            "get_auto_trait_impls(def_id={:?}, def_ctor={:?}, generics={:?}",
-            def_id, def_ctor, generics
+            "get_auto_trait_impls(def_id={:?}, def_ctor=..., generics={:?}",
+            def_id, generics
         );
         let auto_traits: Vec<_> = self.cx
             .send_trait
@@ -110,23 +130,24 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
         auto_traits
     }
 
-    fn get_auto_trait_impl_for(
+    fn get_auto_trait_impl_for<F>(
         &self,
         def_id: DefId,
         name: Option<String>,
         generics: ty::Generics,
-        def_ctor: fn(DefId) -> Def,
+        def_ctor: &F,
         trait_def_id: DefId,
-    ) -> Option<Item> {
+    ) -> Option<Item>
+    where F: Fn(DefId) -> Def {
         if !self.cx
             .generated_synthetics
             .borrow_mut()
             .insert((def_id, trait_def_id))
         {
             debug!(
-                "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor={:?}, \
+                "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor=..., \
                  trait_def_id={:?}): already generated, aborting",
-                def_id, generics, def_ctor, trait_def_id
+                def_id, generics, trait_def_id
             );
             return None;
         }
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index a8f4848bf89..da04068107d 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -302,6 +302,14 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec<clean:
     for def_id in primitive_impls.iter().filter_map(|&def_id| def_id) {
         if !def_id.is_local() {
             build_impl(cx, def_id, &mut impls);
+
+            let auto_impls = get_auto_traits_with_def_id(cx, def_id);
+            let mut renderinfo = cx.renderinfo.borrow_mut();
+
+            let new_impls: Vec<clean::Item> = auto_impls.into_iter()
+                .filter(|i| renderinfo.inlined.insert(i.def_id)).collect();
+
+            impls.extend(new_impls);
         }
     }
 
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 7d3ba792829..1a3ff38797c 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -4124,7 +4124,8 @@ pub fn path_to_def(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
     }
 }
 
-fn get_path_for_type(tcx: TyCtxt, def_id: DefId, def_ctor: fn(DefId) -> Def) -> hir::Path {
+fn get_path_for_type<F>(tcx: TyCtxt, def_id: DefId, def_ctor: F) -> hir::Path
+where F: Fn(DefId) -> Def {
     struct AbsolutePathBuffer {
         names: Vec<String>,
     }
diff --git a/src/test/rustdoc/auto-impl-primitive.rs b/src/test/rustdoc/auto-impl-primitive.rs
new file mode 100644
index 00000000000..a3887b33cc2
--- /dev/null
+++ b/src/test/rustdoc/auto-impl-primitive.rs
@@ -0,0 +1,17 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+pub use std::fs::File;
+
+// @has 'foo/primitive.i16.html' '//h2[@id="synthetic-implementations"]' 'Auto Trait Implementation'
+#[doc(primitive = "i16")]
+/// I love poneys!
+mod prim {}