Skip to content

Commit 01795c3

Browse files
committed
Init self_decl with a correct vis
1 parent 9df8317 commit 01795c3

File tree

4 files changed

+92
-10
lines changed

4 files changed

+92
-10
lines changed

‎compiler/rustc_resolve/src/lib.rs‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ impl ModuleKind {
547547
ModuleKind::Def(.., name) => name,
548548
}
549549
}
550+
551+
fn opt_def_id(&self) -> Option<DefId> {
552+
match self {
553+
ModuleKind::Def(_, def_id, _) => Some(*def_id),
554+
_ => None,
555+
}
556+
}
550557
}
551558

552559
/// Combination of a symbol and its macros 2.0 normalized hygiene context.
@@ -784,10 +791,7 @@ impl<'ra> Module<'ra> {
784791
}
785792

786793
fn opt_def_id(self) -> Option<DefId> {
787-
match self.kind {
788-
ModuleKind::Def(_, def_id, _) => Some(def_id),
789-
_ => None,
790-
}
794+
self.kind.opt_def_id()
791795
}
792796

793797
// `self` resolves to the first module ancestor that `is_normal`.
@@ -1450,14 +1454,19 @@ impl<'ra> ResolverArenas<'ra> {
14501454
&'ra self,
14511455
parent: Option<Module<'ra>>,
14521456
kind: ModuleKind,
1457+
vis: Visibility<DefId>,
14531458
expn_id: ExpnId,
14541459
span: Span,
14551460
no_implicit_prelude: bool,
14561461
) -> Module<'ra> {
14571462
let self_decl = match kind {
1458-
ModuleKind::Def(def_kind, def_id, _) => {
1459-
Some(self.new_pub_def_decl(Res::Def(def_kind, def_id), span, LocalExpnId::ROOT))
1460-
}
1463+
ModuleKind::Def(def_kind, def_id, _) => Some(self.new_def_decl(
1464+
Res::Def(def_kind, def_id),
1465+
vis,
1466+
span,
1467+
LocalExpnId::ROOT,
1468+
None,
1469+
)),
14611470
ModuleKind::Block => None,
14621471
};
14631472
Module(Interned::new_unchecked(self.modules.alloc(ModuleData::new(
@@ -1639,6 +1648,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16391648
let graph_root = arenas.new_module(
16401649
None,
16411650
ModuleKind::Def(DefKind::Mod, root_def_id, None),
1651+
Visibility::Public,
16421652
ExpnId::root(),
16431653
crate_span,
16441654
attr::contains_name(attrs, sym::no_implicit_prelude),
@@ -1648,6 +1658,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16481658
let empty_module = arenas.new_module(
16491659
None,
16501660
ModuleKind::Def(DefKind::Mod, root_def_id, None),
1661+
Visibility::Public,
16511662
ExpnId::root(),
16521663
DUMMY_SP,
16531664
true,
@@ -1749,7 +1760,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17491760
span: Span,
17501761
no_implicit_prelude: bool,
17511762
) -> Module<'ra> {
1752-
let module = self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude);
1763+
let vis =
1764+
kind.opt_def_id().map_or(Visibility::Public, |def_id| self.tcx.visibility(def_id));
1765+
let module = self.arenas.new_module(parent, kind, vis, expn_id, span, no_implicit_prelude);
17531766
self.local_modules.push(module);
17541767
if let Some(def_id) = module.opt_def_id() {
17551768
self.local_module_map.insert(def_id.expect_local(), module);
@@ -1765,7 +1778,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17651778
span: Span,
17661779
no_implicit_prelude: bool,
17671780
) -> Module<'ra> {
1768-
let module = self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude);
1781+
let vis =
1782+
kind.opt_def_id().map_or(Visibility::Public, |def_id| self.tcx.visibility(def_id));
1783+
let module = self.arenas.new_module(parent, kind, vis, expn_id, span, no_implicit_prelude);
17691784
self.extern_module_map.borrow_mut().insert(module.def_id(), module);
17701785
module
17711786
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
mod foo {
2+
pub use self as this;
3+
//~^ ERROR `self` is only public within the crate, and cannot be re-exported outside
4+
5+
pub mod bar {
6+
pub use super as parent;
7+
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
8+
pub use self::super as parent2;
9+
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
10+
pub use super::{self as parent3};
11+
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
12+
pub use self::{super as parent4};
13+
//~^ ERROR `super` is only public within the crate, and cannot be re-exported outside
14+
15+
pub use crate as root;
16+
pub use crate::{self as root2};
17+
pub use super::super as root3;
18+
}
19+
}
20+
21+
pub use foo::*;
22+
pub use foo::bar::*;
23+
24+
pub fn main() {}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0365]: `self` is only public within the crate, and cannot be re-exported outside
2+
--> $DIR/pub-use-self-super-crate.rs:2:13
3+
|
4+
LL | pub use self as this;
5+
| ^^^^^^^^^^^^ re-export of crate public `self`
6+
|
7+
= note: consider declaring type or module `self` with `pub`
8+
9+
error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
10+
--> $DIR/pub-use-self-super-crate.rs:6:17
11+
|
12+
LL | pub use super as parent;
13+
| ^^^^^^^^^^^^^^^ re-export of crate public `super`
14+
|
15+
= note: consider declaring type or module `super` with `pub`
16+
17+
error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
18+
--> $DIR/pub-use-self-super-crate.rs:8:17
19+
|
20+
LL | pub use self::super as parent2;
21+
| ^^^^^^^^^^^^^^^^^^^^^^ re-export of crate public `super`
22+
|
23+
= note: consider declaring type or module `super` with `pub`
24+
25+
error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
26+
--> $DIR/pub-use-self-super-crate.rs:10:25
27+
|
28+
LL | pub use super::{self as parent3};
29+
| ^^^^^^^^^^^^^^^ re-export of crate public `super`
30+
|
31+
= note: consider declaring type or module `super` with `pub`
32+
33+
error[E0365]: `super` is only public within the crate, and cannot be re-exported outside
34+
--> $DIR/pub-use-self-super-crate.rs:12:24
35+
|
36+
LL | pub use self::{super as parent4};
37+
| ^^^^^^^^^^^^^^^^ re-export of crate public `super`
38+
|
39+
= note: consider declaring type or module `super` with `pub`
40+
41+
error: aborting due to 5 previous errors
42+
43+
For more information about this error, try `rustc --explain E0365`.

‎tests/ui/use/use-path-segment-kw.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ macro_rules! macro_dollar_crate {
7070

7171
fn outer() {}
7272

73-
mod foo {
73+
pub mod foo {
7474
pub mod bar {
7575
pub mod foobar {
7676
pub mod qux {

0 commit comments

Comments
 (0)