Skip to content

Commit dc9112f

Browse files
authored
Auto merge of rust-lang#34439 - ollie27:rustdoc_panic_fix, r=alexcrichton
rustdoc: Fix panic caused by doc(hidden) trait methods Fixes: rust-lang#34423 r? @alexcrichton
2 parents 4b89deb + 1efcde5 commit dc9112f

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/librustdoc/html/render.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,16 +2652,19 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26522652
if !is_static || render_static {
26532653
if !is_default_item {
26542654
if let Some(t) = trait_ {
2655-
let it = t.items.iter().find(|i| i.name == item.name).unwrap();
2656-
// We need the stability of the item from the trait because
2657-
// impls can't have a stability.
2658-
document_stability(w, cx, it)?;
2659-
if item.doc_value().is_some() {
2660-
document_full(w, item)?;
2661-
} else {
2662-
// In case the item isn't documented,
2663-
// provide short documentation from the trait.
2664-
document_short(w, it, link)?;
2655+
// The trait item may have been stripped so we might not
2656+
// find any documentation or stability for it.
2657+
if let Some(it) = t.items.iter().find(|i| i.name == item.name) {
2658+
// We need the stability of the item from the trait
2659+
// because impls can't have a stability.
2660+
document_stability(w, cx, it)?;
2661+
if item.doc_value().is_some() {
2662+
document_full(w, item)?;
2663+
} else {
2664+
// In case the item isn't documented,
2665+
// provide short documentation from the trait.
2666+
document_short(w, it, link)?;
2667+
}
26652668
}
26662669
} else {
26672670
document(w, cx, item)?;

src/test/rustdoc/issue-34423.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
pub struct Foo;
12+
13+
pub trait Bar {
14+
#[doc(hidden)]
15+
fn bar() {}
16+
}
17+
18+
impl Bar for Foo {
19+
fn bar() {}
20+
}

0 commit comments

Comments
 (0)