From 1efcde5de01880b5d0cd45bdaca699c0727f5976 Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Thu, 23 Jun 2016 23:17:35 +0100 Subject: [PATCH] rustdoc: Fix panic caused by doc(hidden) trait methods --- src/librustdoc/html/render.rs | 23 +++++++++++++---------- src/test/rustdoc/issue-34423.rs | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/test/rustdoc/issue-34423.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 0d390a87d2050..f63d37b34032e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2652,16 +2652,19 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi if !is_static || render_static { if !is_default_item { if let Some(t) = trait_ { - let it = t.items.iter().find(|i| i.name == item.name).unwrap(); - // We need the stability of the item from the trait because - // impls can't have a stability. - document_stability(w, cx, it)?; - if item.doc_value().is_some() { - document_full(w, item)?; - } else { - // In case the item isn't documented, - // provide short documentation from the trait. - document_short(w, it, link)?; + // The trait item may have been stripped so we might not + // find any documentation or stability for it. + if let Some(it) = t.items.iter().find(|i| i.name == item.name) { + // We need the stability of the item from the trait + // because impls can't have a stability. + document_stability(w, cx, it)?; + if item.doc_value().is_some() { + document_full(w, item)?; + } else { + // In case the item isn't documented, + // provide short documentation from the trait. + document_short(w, it, link)?; + } } } else { document(w, cx, item)?; diff --git a/src/test/rustdoc/issue-34423.rs b/src/test/rustdoc/issue-34423.rs new file mode 100644 index 0000000000000..460462d8a6610 --- /dev/null +++ b/src/test/rustdoc/issue-34423.rs @@ -0,0 +1,20 @@ +// 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. + +pub struct Foo; + +pub trait Bar { + #[doc(hidden)] + fn bar() {} +} + +impl Bar for Foo { + fn bar() {} +}