From b38a856e3851cd9557a5d79f524cc2e69c5664fc Mon Sep 17 00:00:00 2001 From: mitaa Date: Tue, 23 Feb 2016 09:52:44 +0100 Subject: [PATCH 1/2] Don't show associated consts from trait impls --- src/librustdoc/html/render.rs | 10 ++++++++++ src/test/rustdoc/issue-31808.rs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/rustdoc/issue-31808.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 692d230446cda..a30c087bd8b85 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -243,6 +243,7 @@ pub struct Cache { stack: Vec, parent_stack: Vec, + parent_is_trait_impl: bool, search_index: Vec, privmod: bool, remove_priv: bool, @@ -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"), @@ -995,6 +997,10 @@ 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(..) if self.parent_is_trait_impl => { + // skip associated consts in trait impls + ((None, None), false) + } clean::AssociatedTypeItem(..) | clean::AssociatedConstItem(..) | clean::TyMethodItem(..) | @@ -1115,12 +1121,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); @@ -1201,6 +1210,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; } } diff --git a/src/test/rustdoc/issue-31808.rs b/src/test/rustdoc/issue-31808.rs new file mode 100644 index 0000000000000..46be8229d7c65 --- /dev/null +++ b/src/test/rustdoc/issue-31808.rs @@ -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 or the MIT license +// , 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; +} From f5df7e086516ba6398f2a1538c1c6d3193846f55 Mon Sep 17 00:00:00 2001 From: mitaa Date: Tue, 23 Feb 2016 10:24:53 +0100 Subject: [PATCH 2/2] Show associated types in inherent impls --- src/librustdoc/html/render.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index a30c087bd8b85..8a061e3a528e7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -997,8 +997,9 @@ 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(..) if self.parent_is_trait_impl => { - // skip associated consts in trait impls + clean::AssociatedConstItem(..) | + clean::TypedefItem(_, true) if self.parent_is_trait_impl => { + // skip associated items in trait impls ((None, None), false) } clean::AssociatedTypeItem(..) | @@ -1032,10 +1033,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 {