Skip to content

Commit b38a856

Browse files
committed
Don't show associated consts from trait impls
1 parent be7196a commit b38a856

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/librustdoc/html/render.rs

Lines changed: 10 additions & 0 deletions
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"),
@@ -995,6 +997,10 @@ impl DocFolder for Cache {
995997
// Index this method for searching later on
996998
if let Some(ref s) = item.name {
997999
let (parent, is_method) = match item.inner {
1000+
clean::AssociatedConstItem(..) if self.parent_is_trait_impl => {
1001+
// skip associated consts in trait impls
1002+
((None, None), false)
1003+
}
9981004
clean::AssociatedTypeItem(..) |
9991005
clean::AssociatedConstItem(..) |
10001006
clean::TyMethodItem(..) |
@@ -1115,12 +1121,15 @@ impl DocFolder for Cache {
11151121
}
11161122

11171123
// Maintain the parent stack
1124+
let orig_parent_is_trait_impl = self.parent_is_trait_impl;
11181125
let parent_pushed = match item.inner {
11191126
clean::TraitItem(..) | clean::EnumItem(..) | clean::StructItem(..) => {
11201127
self.parent_stack.push(item.def_id);
1128+
self.parent_is_trait_impl = false;
11211129
true
11221130
}
11231131
clean::ImplItem(ref i) => {
1132+
self.parent_is_trait_impl = i.trait_.is_some();
11241133
match i.for_ {
11251134
clean::ResolvedPath{ did, .. } => {
11261135
self.parent_stack.push(did);
@@ -1201,6 +1210,7 @@ impl DocFolder for Cache {
12011210
if pushed { self.stack.pop().unwrap(); }
12021211
if parent_pushed { self.parent_stack.pop().unwrap(); }
12031212
self.privmod = orig_privmod;
1213+
self.parent_is_trait_impl = orig_parent_is_trait_impl;
12041214
return ret;
12051215
}
12061216
}

src/test/rustdoc/issue-31808.rs

Lines changed: 23 additions & 0 deletions
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)