Skip to content

Commit 90bd83c

Browse files
committed
Auto merge of #52196 - ollie27:rustdoc_ctor_imports, r=QuietMisdreavus
rustdoc: Hide struct and enum variant constructor imports This is fallout from #51425. The duplicate variant imports can be seen [here](https://doc.rust-lang.org/nightly/std/prelude/v1/index.html) for example. This is fixing a regression so could be backported to beta. r? @QuietMisdreavus
2 parents ce45cbb + 6b1d584 commit 90bd83c

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

Diff for: src/librustdoc/visit_ast.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
323323
});
324324
true
325325
}
326-
hir_map::NodeStructCtor(_) if !glob => {
327-
// struct constructors always show up alongside their struct definitions, we've
328-
// already processed that so just discard this
329-
true
330-
}
331326
_ => false,
332327
};
333328
self.view_item_stack.remove(&def_node_id);
@@ -375,6 +370,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
375370
hir::ItemUse(ref path, kind) => {
376371
let is_glob = kind == hir::UseKind::Glob;
377372

373+
// struct and variant constructors always show up alongside their definitions, we've
374+
// already processed them so just discard these.
375+
match path.def {
376+
Def::StructCtor(..) | Def::VariantCtor(..) => return,
377+
_ => {}
378+
}
379+
378380
// If there was a private module in the current path then don't bother inlining
379381
// anything as it will probably be stripped anyway.
380382
if item.vis.node.is_pub() && self.inside_public_path {

Diff for: src/test/rustdoc/constructor-imports.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 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+
#![crate_name = "foo"]
12+
13+
pub mod a {
14+
pub struct Foo;
15+
pub enum Bar {
16+
Baz,
17+
}
18+
}
19+
20+
// @count 'foo/index.html' '//*[code="pub use a::Foo;"]' 1
21+
#[doc(no_inline)]
22+
pub use a::Foo;
23+
// @count 'foo/index.html' '//*[code="pub use a::Bar::Baz;"]' 1
24+
#[doc(no_inline)]
25+
pub use a::Bar::Baz;

0 commit comments

Comments
 (0)