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 { + 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 { 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 or the MIT license +// , 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) {} + } +}