Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,14 +1450,19 @@ impl<'ra> ResolverArenas<'ra> {
&'ra self,
parent: Option<Module<'ra>>,
kind: ModuleKind,
vis: Visibility<DefId>,
expn_id: ExpnId,
span: Span,
no_implicit_prelude: bool,
) -> Module<'ra> {
let self_decl = match kind {
ModuleKind::Def(def_kind, def_id, _) => {
Some(self.new_pub_def_decl(Res::Def(def_kind, def_id), span, LocalExpnId::ROOT))
}
ModuleKind::Def(def_kind, def_id, _) => Some(self.new_def_decl(
Res::Def(def_kind, def_id),
vis,
span,
LocalExpnId::ROOT,
None,
)),
ModuleKind::Block => None,
};
Module(Interned::new_unchecked(self.modules.alloc(ModuleData::new(
Expand Down Expand Up @@ -1639,6 +1644,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let graph_root = arenas.new_module(
None,
ModuleKind::Def(DefKind::Mod, root_def_id, None),
Visibility::Public,
ExpnId::root(),
crate_span,
attr::contains_name(attrs, sym::no_implicit_prelude),
Expand All @@ -1648,6 +1654,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let empty_module = arenas.new_module(
None,
ModuleKind::Def(DefKind::Mod, root_def_id, None),
Visibility::Public,
ExpnId::root(),
DUMMY_SP,
true,
Expand Down Expand Up @@ -1749,7 +1756,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
span: Span,
no_implicit_prelude: bool,
) -> Module<'ra> {
let module = self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude);
let vis = match kind {
ModuleKind::Def(_, def_id, _) => {
self.tcx.local_visibility(def_id.expect_local()).to_def_id()
}
ModuleKind::Block => Visibility::Public,
};
let module = self.arenas.new_module(parent, kind, vis, expn_id, span, no_implicit_prelude);
self.local_modules.push(module);
if let Some(def_id) = module.opt_def_id() {
self.local_module_map.insert(def_id.expect_local(), module);
Expand All @@ -1765,7 +1778,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
span: Span,
no_implicit_prelude: bool,
) -> Module<'ra> {
let module = self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude);
let vis = match kind {
ModuleKind::Def(_, def_id, _) => self.tcx.visibility(def_id),
ModuleKind::Block => Visibility::Public,
};
let module = self.arenas.new_module(parent, kind, vis, expn_id, span, no_implicit_prelude);
self.extern_module_map.borrow_mut().insert(module.def_id(), module);
module
}
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/use/pub-use-self-of-private-mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ needs-rustc-debug-assertions

mod foo {
pub use self as ops; //~ ERROR `self` is only public within the crate, and cannot be re-exported outside
}

pub use foo::*;

pub fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/use/pub-use-self-of-private-mod.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0365]: `self` is only public within the crate, and cannot be re-exported outside
--> $DIR/pub-use-self-of-private-mod.rs:4:13
|
LL | pub use self as ops;
| ^^^^^^^^^^^ re-export of crate public `self`
|
= note: consider declaring type or module `self` with `pub`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0365`.
16 changes: 16 additions & 0 deletions tests/ui/use/pub-use-super-of-private-mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mod foo {
pub mod bar {
pub use super as parent;
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
pub use self::super as parent2;
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
pub use super::{self as parent3};
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
pub use self::{super as parent4};
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
}
}

pub use foo::bar::*;

pub fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/use/pub-use-super-of-private-mod.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
--> $DIR/pub-use-super-of-private-mod.rs:3:17
|
LL | pub use super as parent;
| ^^^^^^^^^^^^^^^ re-export of crate public `super`
|
= note: consider declaring type or module `super` with `pub`

error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
--> $DIR/pub-use-super-of-private-mod.rs:5:17
|
LL | pub use self::super as parent2;
| ^^^^^^^^^^^^^^^^^^^^^^ re-export of crate public `super`
|
= note: consider declaring type or module `super` with `pub`

error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
--> $DIR/pub-use-super-of-private-mod.rs:7:25
|
LL | pub use super::{self as parent3};
| ^^^^^^^^^^^^^^^ re-export of crate public `super`
|
= note: consider declaring type or module `super` with `pub`

error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
--> $DIR/pub-use-super-of-private-mod.rs:9:24
|
LL | pub use self::{super as parent4};
| ^^^^^^^^^^^^^^^^ re-export of crate public `super`
|
= note: consider declaring type or module `super` with `pub`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0365`.
2 changes: 1 addition & 1 deletion tests/ui/use/use-path-segment-kw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ macro_rules! macro_dollar_crate {

fn outer() {}

mod foo {
pub mod foo {
pub mod bar {
pub mod foobar {
pub mod qux {
Expand Down
Loading