Skip to content

Commit 18f031f

Browse files
committed
Fix wrongly pushing down from_glob when visiting_mod_contents
Signed-off-by: longfangsong <[email protected]>
1 parent 06b0273 commit 18f031f

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

src/librustdoc/doctree.rs

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl Module<'hir> {
9898
}
9999
}
100100
(false, false) => {
101+
error!("push_item: {:?} conflict with {:?}", existing_item, new_item);
101102
// should report "defined multiple time" error before reach this
102103
unreachable!()
103104
}
@@ -142,6 +143,7 @@ impl Module<'hir> {
142143
return;
143144
}
144145
(false, false) => {
146+
error!("push_mod: {:?} conflict with {:?}", existing_mod.name, new_mod.name);
145147
// should report "defined multiple time" error before reach this
146148
unreachable!()
147149
}

src/librustdoc/visit_ast.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
316316
om.push_item(self.cx, Item::new(item, renamed, from_glob))
317317
}
318318
hir::ItemKind::Mod(ref m) => {
319-
om.push_mod(self.visit_mod_contents(
320-
item.span,
321-
&item.vis,
322-
item.hir_id(),
323-
m,
324-
name,
325-
from_glob,
326-
));
319+
let mut mod_ =
320+
self.visit_mod_contents(item.span, &item.vis, item.hir_id(), m, name, false);
321+
mod_.from_glob = from_glob;
322+
om.push_mod(mod_);
327323
}
328324
hir::ItemKind::Fn(..)
329325
| hir::ItemKind::ExternCrate(..)

src/test/rustdoc/glob-shadowing.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// @has 'glob_shadowing/index.html'
2-
// @count - '//tr[@class="module-item"]' 4
2+
// @count - '//tr[@class="module-item"]' 5
33
// @!has - '//tr[@class="module-item"]' 'sub1::describe'
4+
// @has - '//tr[@class="module-item"]' 'sub2::describe'
5+
46
// @!has - '//tr[@class="module-item"]' 'sub1::describe2'
7+
8+
// @!has - '//tr[@class="module-item"]' 'sub1::prelude'
59
// @has - '//tr[@class="module-item"]' 'mod::prelude'
6-
// @has - '//tr[@class="module-item"]' 'sub2::describe'
10+
711
// @has - '//tr[@class="module-item"]' 'sub1::Foo (struct)'
812
// @has - '//tr[@class="module-item"]' 'mod::Foo (function)'
13+
14+
// @has - '//tr[@class="module-item"]' 'sub4::inner::X'
15+
916
// @has 'glob_shadowing/fn.describe.html'
1017
// @has - '//div[@class="docblock"]' 'sub2::describe'
1118

@@ -19,10 +26,9 @@ mod sub1 {
1926
// this should be shadowed by mod::prelude
2027
/// sub1::prelude
2128
pub mod prelude {
22-
pub use super::describe;
2329
}
2430

25-
// this should *not* be shadowed, because sub1::Foo and mod::Foo are in different namespace
31+
// this should *not* be shadowed, because sub1::Foo and mod::Foo are in different namespaces
2632
/// sub1::Foo (struct)
2733
pub struct Foo;
2834

@@ -50,8 +56,16 @@ mod sub3 {
5056
}
5157
}
5258

53-
/// mod::prelude
54-
pub mod prelude {}
59+
mod sub4 {
60+
// this should be shadowed by sub4::inner::X
61+
/// sub4::X
62+
pub const X: usize = 0;
63+
pub mod inner {
64+
pub use super::*;
65+
/// sub4::inner::X
66+
pub const X: usize = 1;
67+
}
68+
}
5569

5670
/// mod::Foo (function)
5771
pub fn Foo() {}
@@ -64,3 +78,9 @@ pub use sub1::*;
6478

6579
#[doc(inline)]
6680
pub use sub3::*;
81+
82+
#[doc(inline)]
83+
pub use sub4::inner::*;
84+
85+
/// mod::prelude
86+
pub mod prelude {}

0 commit comments

Comments
 (0)