Skip to content

Commit e584a49

Browse files
committed
Rollup merge of #31837 - mitaa:rdoc-inherent-assoc, r=alexcrichton
This effectively only records associated items from either inherent impls or trait definitions in the search-index. fixes #31808 r? @alexcrichton
2 parents 6078a86 + f5df7e0 commit e584a49

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/librustdoc/html/render.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ pub struct Cache {
243243

244244
stack: Vec<String>,
245245
parent_stack: Vec<DefId>,
246+
parent_is_trait_impl: bool,
246247
search_index: Vec<IndexItem>,
247248
privmod: bool,
248249
remove_priv: bool,
@@ -487,6 +488,7 @@ pub fn run(mut krate: clean::Crate,
487488
stack: Vec::new(),
488489
parent_stack: Vec::new(),
489490
search_index: Vec::new(),
491+
parent_is_trait_impl: false,
490492
extern_locations: HashMap::new(),
491493
primitive_locations: HashMap::new(),
492494
remove_priv: cx.passes.contains("strip-private"),
@@ -996,6 +998,11 @@ impl DocFolder for Cache {
996998
// Index this method for searching later on
997999
if let Some(ref s) = item.name {
9981000
let (parent, is_method) = match item.inner {
1001+
clean::AssociatedConstItem(..) |
1002+
clean::TypedefItem(_, true) if self.parent_is_trait_impl => {
1003+
// skip associated items in trait impls
1004+
((None, None), false)
1005+
}
9991006
clean::AssociatedTypeItem(..) |
10001007
clean::AssociatedConstItem(..) |
10011008
clean::TyMethodItem(..) |
@@ -1027,10 +1034,6 @@ impl DocFolder for Cache {
10271034
((Some(*last), path), true)
10281035
}
10291036
}
1030-
clean::TypedefItem(_, true) => {
1031-
// skip associated types in impls
1032-
((None, None), false)
1033-
}
10341037
_ => ((None, Some(&*self.stack)), false)
10351038
};
10361039
let hidden_field = match item.inner {
@@ -1116,12 +1119,15 @@ impl DocFolder for Cache {
11161119
}
11171120

11181121
// Maintain the parent stack
1122+
let orig_parent_is_trait_impl = self.parent_is_trait_impl;
11191123
let parent_pushed = match item.inner {
11201124
clean::TraitItem(..) | clean::EnumItem(..) | clean::StructItem(..) => {
11211125
self.parent_stack.push(item.def_id);
1126+
self.parent_is_trait_impl = false;
11221127
true
11231128
}
11241129
clean::ImplItem(ref i) => {
1130+
self.parent_is_trait_impl = i.trait_.is_some();
11251131
match i.for_ {
11261132
clean::ResolvedPath{ did, .. } => {
11271133
self.parent_stack.push(did);
@@ -1202,6 +1208,7 @@ impl DocFolder for Cache {
12021208
if pushed { self.stack.pop().unwrap(); }
12031209
if parent_pushed { self.parent_stack.pop().unwrap(); }
12041210
self.privmod = orig_privmod;
1211+
self.parent_is_trait_impl = orig_parent_is_trait_impl;
12051212
return ret;
12061213
}
12071214
}

src/test/rustdoc/issue-31808.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(associated_consts, associated_types)]
12+
13+
// Test that associated item impls on primitive types don't crash rustdoc
14+
15+
pub trait Foo {
16+
const BAR: usize;
17+
type BAZ;
18+
}
19+
20+
impl Foo for () {
21+
const BAR: usize = 0;
22+
type BAZ = usize;
23+
}

0 commit comments

Comments
 (0)