Skip to content

Commit

Permalink
rustdoc: Don't duplicate inlined impl blocks
Browse files Browse the repository at this point in the history
Closes #21474
  • Loading branch information
alexcrichton committed Apr 8, 2015
1 parent ec412c2 commit 0f3183f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//! usable for clean
use std::collections::HashSet;
use std::mem;

use syntax::abi;
use syntax::ast;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub struct RustdocVisitor<'a, 'tcx: 'a> {
pub cx: &'a core::DocContext<'tcx>,
pub analysis: Option<&'a core::CrateAnalysis>,
view_item_stack: HashSet<ast::NodeId>,
inlining_from_glob: bool,
}

impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
Expand All @@ -54,6 +56,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
cx: cx,
analysis: analysis,
view_item_stack: stack,
inlining_from_glob: false,
}
}

Expand Down Expand Up @@ -209,6 +212,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let ret = match tcx.map.get(def.node) {
ast_map::NodeItem(it) => {
if glob {
let prev = mem::replace(&mut self.inlining_from_glob, true);
match it.node {
ast::ItemMod(ref m) => {
for i in &m.items {
Expand All @@ -218,6 +222,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
ast::ItemEnum(..) => {}
_ => { panic!("glob not mapped to a module or enum"); }
}
self.inlining_from_glob = prev;
} else {
self.visit_item(it, renamed, om);
}
Expand Down Expand Up @@ -356,7 +361,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
vis: item.vis,
stab: self.stability(item.id),
};
om.impls.push(i);
// Don't duplicate impls when inlining glob imports, we'll pick
// them up regardless of where they're located.
if !self.inlining_from_glob {
om.impls.push(i);
}
},
ast::ItemDefaultImpl(unsafety, ref trait_ref) => {
let i = DefaultImpl {
Expand All @@ -366,7 +375,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
attrs: item.attrs.clone(),
whence: item.span,
};
om.def_traits.push(i);
// see comment above about ItemImpl
if !self.inlining_from_glob {
om.def_traits.push(i);
}
}
ast::ItemForeignMod(ref fm) => {
om.foreigns.push(fm.clone());
Expand Down
21 changes: 21 additions & 0 deletions src/test/rustdoc/issue-21474.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2012-2014 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub use inner::*;

mod inner {
impl super::Blah for super::What { }
}

pub trait Blah { }

// @count issue_21474/struct.What.html \
// '//*[@class="impl"]' 1
pub struct What;

0 comments on commit 0f3183f

Please sign in to comment.