Skip to content

Commit

Permalink
Fix wrongly pushing down from_glob when visiting_mod_contents
Browse files Browse the repository at this point in the history
Signed-off-by: longfangsong <longfangsong@icloud.com>
  • Loading branch information
longfangsong committed Apr 15, 2021
1 parent 06b0273 commit 18f031f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl Module<'hir> {
}
}
(false, false) => {
error!("push_item: {:?} conflict with {:?}", existing_item, new_item);
// should report "defined multiple time" error before reach this
unreachable!()
}
Expand Down Expand Up @@ -142,6 +143,7 @@ impl Module<'hir> {
return;
}
(false, false) => {
error!("push_mod: {:?} conflict with {:?}", existing_mod.name, new_mod.name);
// should report "defined multiple time" error before reach this
unreachable!()
}
Expand Down
12 changes: 4 additions & 8 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
om.push_item(self.cx, Item::new(item, renamed, from_glob))
}
hir::ItemKind::Mod(ref m) => {
om.push_mod(self.visit_mod_contents(
item.span,
&item.vis,
item.hir_id(),
m,
name,
from_glob,
));
let mut mod_ =
self.visit_mod_contents(item.span, &item.vis, item.hir_id(), m, name, false);
mod_.from_glob = from_glob;
om.push_mod(mod_);
}
hir::ItemKind::Fn(..)
| hir::ItemKind::ExternCrate(..)
Expand Down
32 changes: 26 additions & 6 deletions src/test/rustdoc/glob-shadowing.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// @has 'glob_shadowing/index.html'
// @count - '//tr[@class="module-item"]' 4
// @count - '//tr[@class="module-item"]' 5
// @!has - '//tr[@class="module-item"]' 'sub1::describe'
// @has - '//tr[@class="module-item"]' 'sub2::describe'

// @!has - '//tr[@class="module-item"]' 'sub1::describe2'

// @!has - '//tr[@class="module-item"]' 'sub1::prelude'
// @has - '//tr[@class="module-item"]' 'mod::prelude'
// @has - '//tr[@class="module-item"]' 'sub2::describe'

// @has - '//tr[@class="module-item"]' 'sub1::Foo (struct)'
// @has - '//tr[@class="module-item"]' 'mod::Foo (function)'

// @has - '//tr[@class="module-item"]' 'sub4::inner::X'

// @has 'glob_shadowing/fn.describe.html'
// @has - '//div[@class="docblock"]' 'sub2::describe'

Expand All @@ -19,10 +26,9 @@ mod sub1 {
// this should be shadowed by mod::prelude
/// sub1::prelude
pub mod prelude {
pub use super::describe;
}

// this should *not* be shadowed, because sub1::Foo and mod::Foo are in different namespace
// this should *not* be shadowed, because sub1::Foo and mod::Foo are in different namespaces
/// sub1::Foo (struct)
pub struct Foo;

Expand Down Expand Up @@ -50,8 +56,16 @@ mod sub3 {
}
}

/// mod::prelude
pub mod prelude {}
mod sub4 {
// this should be shadowed by sub4::inner::X
/// sub4::X
pub const X: usize = 0;
pub mod inner {
pub use super::*;
/// sub4::inner::X
pub const X: usize = 1;
}
}

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

#[doc(inline)]
pub use sub3::*;

#[doc(inline)]
pub use sub4::inner::*;

/// mod::prelude
pub mod prelude {}

0 comments on commit 18f031f

Please sign in to comment.