Skip to content

Commit 0f3183f

Browse files
committed
rustdoc: Don't duplicate inlined impl blocks
Closes #21474
1 parent ec412c2 commit 0f3183f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/librustdoc/visit_ast.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//! usable for clean
1313
1414
use std::collections::HashSet;
15+
use std::mem;
1516

1617
use syntax::abi;
1718
use syntax::ast;
@@ -40,6 +41,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
4041
pub cx: &'a core::DocContext<'tcx>,
4142
pub analysis: Option<&'a core::CrateAnalysis>,
4243
view_item_stack: HashSet<ast::NodeId>,
44+
inlining_from_glob: bool,
4345
}
4446

4547
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
@@ -54,6 +56,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
5456
cx: cx,
5557
analysis: analysis,
5658
view_item_stack: stack,
59+
inlining_from_glob: false,
5760
}
5861
}
5962

@@ -209,6 +212,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
209212
let ret = match tcx.map.get(def.node) {
210213
ast_map::NodeItem(it) => {
211214
if glob {
215+
let prev = mem::replace(&mut self.inlining_from_glob, true);
212216
match it.node {
213217
ast::ItemMod(ref m) => {
214218
for i in &m.items {
@@ -218,6 +222,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
218222
ast::ItemEnum(..) => {}
219223
_ => { panic!("glob not mapped to a module or enum"); }
220224
}
225+
self.inlining_from_glob = prev;
221226
} else {
222227
self.visit_item(it, renamed, om);
223228
}
@@ -356,7 +361,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
356361
vis: item.vis,
357362
stab: self.stability(item.id),
358363
};
359-
om.impls.push(i);
364+
// Don't duplicate impls when inlining glob imports, we'll pick
365+
// them up regardless of where they're located.
366+
if !self.inlining_from_glob {
367+
om.impls.push(i);
368+
}
360369
},
361370
ast::ItemDefaultImpl(unsafety, ref trait_ref) => {
362371
let i = DefaultImpl {
@@ -366,7 +375,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
366375
attrs: item.attrs.clone(),
367376
whence: item.span,
368377
};
369-
om.def_traits.push(i);
378+
// see comment above about ItemImpl
379+
if !self.inlining_from_glob {
380+
om.def_traits.push(i);
381+
}
370382
}
371383
ast::ItemForeignMod(ref fm) => {
372384
om.foreigns.push(fm.clone());

src/test/rustdoc/issue-21474.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2012-2014 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 use inner::*;
12+
13+
mod inner {
14+
impl super::Blah for super::What { }
15+
}
16+
17+
pub trait Blah { }
18+
19+
// @count issue_21474/struct.What.html \
20+
// '//*[@class="impl"]' 1
21+
pub struct What;

0 commit comments

Comments
 (0)