Skip to content

Commit

Permalink
Rollup merge of rust-lang#31837 - mitaa:rdoc-inherent-assoc, r=alexcr…
Browse files Browse the repository at this point in the history
…ichton

This effectively only records associated items from either inherent impls or trait definitions in the search-index.

fixes rust-lang#31808

r? @alexcrichton
  • Loading branch information
Manishearth committed Feb 25, 2016
2 parents 6078a86 + f5df7e0 commit e584a49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pub struct Cache {

stack: Vec<String>,
parent_stack: Vec<DefId>,
parent_is_trait_impl: bool,
search_index: Vec<IndexItem>,
privmod: bool,
remove_priv: bool,
Expand Down Expand Up @@ -487,6 +488,7 @@ pub fn run(mut krate: clean::Crate,
stack: Vec::new(),
parent_stack: Vec::new(),
search_index: Vec::new(),
parent_is_trait_impl: false,
extern_locations: HashMap::new(),
primitive_locations: HashMap::new(),
remove_priv: cx.passes.contains("strip-private"),
Expand Down Expand Up @@ -996,6 +998,11 @@ impl DocFolder for Cache {
// Index this method for searching later on
if let Some(ref s) = item.name {
let (parent, is_method) = match item.inner {
clean::AssociatedConstItem(..) |
clean::TypedefItem(_, true) if self.parent_is_trait_impl => {
// skip associated items in trait impls
((None, None), false)
}
clean::AssociatedTypeItem(..) |
clean::AssociatedConstItem(..) |
clean::TyMethodItem(..) |
Expand Down Expand Up @@ -1027,10 +1034,6 @@ impl DocFolder for Cache {
((Some(*last), path), true)
}
}
clean::TypedefItem(_, true) => {
// skip associated types in impls
((None, None), false)
}
_ => ((None, Some(&*self.stack)), false)
};
let hidden_field = match item.inner {
Expand Down Expand Up @@ -1116,12 +1119,15 @@ impl DocFolder for Cache {
}

// Maintain the parent stack
let orig_parent_is_trait_impl = self.parent_is_trait_impl;
let parent_pushed = match item.inner {
clean::TraitItem(..) | clean::EnumItem(..) | clean::StructItem(..) => {
self.parent_stack.push(item.def_id);
self.parent_is_trait_impl = false;
true
}
clean::ImplItem(ref i) => {
self.parent_is_trait_impl = i.trait_.is_some();
match i.for_ {
clean::ResolvedPath{ did, .. } => {
self.parent_stack.push(did);
Expand Down Expand Up @@ -1202,6 +1208,7 @@ impl DocFolder for Cache {
if pushed { self.stack.pop().unwrap(); }
if parent_pushed { self.parent_stack.pop().unwrap(); }
self.privmod = orig_privmod;
self.parent_is_trait_impl = orig_parent_is_trait_impl;
return ret;
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/rustdoc/issue-31808.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2016 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(associated_consts, associated_types)]

// Test that associated item impls on primitive types don't crash rustdoc

pub trait Foo {
const BAR: usize;
type BAZ;
}

impl Foo for () {
const BAR: usize = 0;
type BAZ = usize;
}

0 comments on commit e584a49

Please sign in to comment.