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
This commit is contained in:
Alex Crichton 2015-04-07 17:35:23 -07:00
parent 1b568ba0fd
commit 77d164d809
3 changed files with 56 additions and 42 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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) {}
}
}