about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-04-07 17:35:23 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-04-07 17:54:35 -0700
commit77d164d8099abc17f97aa50442245e4fc88b36a2 (patch)
tree5d7789e68dcb263dfde71a22529f5dada93e5332
parent1b568ba0fd531ff33d45cb52d5c8cbfe1908be86 (diff)
downloadrust-77d164d8099abc17f97aa50442245e4fc88b36a2.tar.gz
rust-77d164d8099abc17f97aa50442245e4fc88b36a2.zip
rustdoc: Index inherent methods on primitives
The set of types which can have an inherent impl changed slightly and rustdoc
just needed to catch up to understand what it means to see a `impl str`!

Closes #23511
-rw-r--r--src/librustdoc/clean/mod.rs15
-rw-r--r--src/librustdoc/html/render.rs59
-rw-r--r--src/test/rustdoc/issue-23511.rs24
3 files changed, 56 insertions, 42 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 6c59205cd3e..38df0339e42 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1428,6 +1428,21 @@ pub enum TypeKind {
     TypeTypedef,
 }
 
+impl Type {
+    pub fn primitive_type(&self) -> Option<PrimitiveType> {
+        match *self {
+            Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p),
+            Vector(..) | BorrowedRef{ type_: box Vector(..), ..  } => Some(Slice),
+            FixedVector(..) | BorrowedRef { type_: box FixedVector(..), .. } => {
+                Some(Array)
+            }
+            Tuple(..) => Some(PrimitiveTuple),
+            RawPointer(..) => Some(PrimitiveRawPointer),
+            _ => None,
+        }
+    }
+}
+
 impl PrimitiveType {
     fn from_str(s: &str) -> Option<PrimitiveType> {
         match s {
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index a1ec58cd3dd..8e33a9bd80b 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1025,7 +1025,16 @@ impl DocFolder for Cache {
                         self.parent_stack.push(did);
                         true
                     }
-                    _ => false
+                    ref t => {
+                        match t.primitive_type() {
+                            Some(prim) => {
+                                let did = ast_util::local_def(prim.to_node_id());
+                                self.parent_stack.push(did);
+                                true
+                            }
+                            _ => false,
+                        }
+                    }
                 }
             }
             _ => false
@@ -1037,11 +1046,6 @@ impl DocFolder for Cache {
             Some(item) => {
                 match item {
                     clean::Item{ attrs, inner: clean::ImplItem(i), .. } => {
-                        use clean::{Primitive, Vector, ResolvedPath, BorrowedRef};
-                        use clean::PrimitiveType::{Array, Slice, PrimitiveTuple};
-                        use clean::PrimitiveType::{PrimitiveRawPointer};
-                        use clean::{FixedVector, Tuple, RawPointer};
-
                         // extract relevant documentation for this impl
                         let dox = match attrs.into_iter().find(|a| {
                             match *a {
@@ -1059,47 +1063,18 @@ impl DocFolder for Cache {
                         // Figure out the id of this impl. This may map to a
                         // primitive rather than always to a struct/enum.
                         let did = match i.for_ {
-                            ResolvedPath { did, .. } |
-                            BorrowedRef {
-                                type_: box ResolvedPath { did, .. }, ..
+                            clean::ResolvedPath { did, .. } |
+                            clean::BorrowedRef {
+                                type_: box clean::ResolvedPath { did, .. }, ..
                             } => {
                                 Some(did)
                             }
 
-                            // References to primitives are picked up as well to
-                            // recognize implementations for &str, this may not
-                            // be necessary in a DST world.
-                            Primitive(p) |
-                                BorrowedRef { type_: box Primitive(p), ..} =>
-                            {
-                                Some(ast_util::local_def(p.to_node_id()))
+                            ref t => {
+                                t.primitive_type().map(|p| {
+                                    ast_util::local_def(p.to_node_id())
+                                })
                             }
-
-                            FixedVector(..) |
-                                BorrowedRef { type_: box FixedVector(..), .. } =>
-                            {
-                                Some(ast_util::local_def(Array.to_node_id()))
-                            }
-
-                            // In a DST world, we may only need Vector, but for
-                            // now we also pick up borrowed references
-                            Vector(..) |
-                                BorrowedRef{ type_: box Vector(..), ..  } =>
-                            {
-                                Some(ast_util::local_def(Slice.to_node_id()))
-                            }
-
-                            Tuple(..) => {
-                                let id = PrimitiveTuple.to_node_id();
-                                Some(ast_util::local_def(id))
-                            }
-
-                            RawPointer(..) => {
-                                let id = PrimitiveRawPointer.to_node_id();
-                                Some(ast_util::local_def(id))
-                            }
-
-                            _ => None,
                         };
 
                         if let Some(did) = did {
diff --git a/src/test/rustdoc/issue-23511.rs b/src/test/rustdoc/issue-23511.rs
new file mode 100644
index 00000000000..6582ca0eba9
--- /dev/null
+++ b/src/test/rustdoc/issue-23511.rs
@@ -0,0 +1,24 @@
+// Copyright 2015 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.
+
+#![feature(no_std, lang_items, core)]
+#![no_std]
+
+extern crate core;
+
+pub mod str {
+    #![doc(primitive = "str")]
+
+    #[lang = "str"]
+    impl str {
+        // @has search-index.js foo
+        pub fn foo(&self) {}
+    }
+}