diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 72d5cdcf1f3b6..10aa1b4019b3c 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -547,13 +547,6 @@ impl ModuleKind { ModuleKind::Def(.., name) => name, } } - - fn opt_def_id(&self) -> Option { - match self { - ModuleKind::Def(_, def_id, _) => Some(*def_id), - _ => None, - } - } } /// Combination of a symbol and its macros 2.0 normalized hygiene context. @@ -791,7 +784,10 @@ impl<'ra> Module<'ra> { } fn opt_def_id(self) -> Option { - self.kind.opt_def_id() + match self.kind { + ModuleKind::Def(_, def_id, _) => Some(def_id), + _ => None, + } } // `self` resolves to the first module ancestor that `is_normal`. @@ -1454,19 +1450,14 @@ impl<'ra> ResolverArenas<'ra> { &'ra self, parent: Option>, kind: ModuleKind, - vis: Visibility, 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_def_decl( - Res::Def(def_kind, def_id), - vis, - span, - LocalExpnId::ROOT, - None, - )), + ModuleKind::Def(def_kind, def_id, _) => { + Some(self.new_pub_def_decl(Res::Def(def_kind, def_id), span, LocalExpnId::ROOT)) + } ModuleKind::Block => None, }; Module(Interned::new_unchecked(self.modules.alloc(ModuleData::new( @@ -1648,7 +1639,6 @@ 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), @@ -1658,7 +1648,6 @@ 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, @@ -1760,9 +1749,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { span: Span, no_implicit_prelude: bool, ) -> Module<'ra> { - let vis = - kind.opt_def_id().map_or(Visibility::Public, |def_id| self.tcx.visibility(def_id)); - let module = self.arenas.new_module(parent, kind, vis, expn_id, span, no_implicit_prelude); + let module = self.arenas.new_module(parent, kind, 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); @@ -1778,9 +1765,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { span: Span, no_implicit_prelude: bool, ) -> Module<'ra> { - let vis = - kind.opt_def_id().map_or(Visibility::Public, |def_id| self.tcx.visibility(def_id)); - let module = self.arenas.new_module(parent, kind, vis, expn_id, span, no_implicit_prelude); + let module = self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude); self.extern_module_map.borrow_mut().insert(module.def_id(), module); module } diff --git a/tests/ui/use/pub-use-self-super-crate.rs b/tests/ui/use/pub-use-self-super-crate.rs deleted file mode 100644 index 1a799acb50fb9..0000000000000 --- a/tests/ui/use/pub-use-self-super-crate.rs +++ /dev/null @@ -1,24 +0,0 @@ -mod foo { - pub use self as this; - //~^ ERROR `self` is only public within the crate, and cannot be re-exported outside - - 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 crate as root; - pub use crate::{self as root2}; - pub use super::super as root3; - } -} - -pub use foo::*; -pub use foo::bar::*; - -pub fn main() {} diff --git a/tests/ui/use/pub-use-self-super-crate.stderr b/tests/ui/use/pub-use-self-super-crate.stderr deleted file mode 100644 index 3b336800a1800..0000000000000 --- a/tests/ui/use/pub-use-self-super-crate.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error[E0365]: `self` is only public within the crate, and cannot be re-exported outside - --> $DIR/pub-use-self-super-crate.rs:2:13 - | -LL | pub use self as this; - | ^^^^^^^^^^^^ re-export of crate public `self` - | - = note: consider declaring type or module `self` with `pub` - -error[E0365]: `super` is only public within the crate, and cannot be re-exported outside - --> $DIR/pub-use-self-super-crate.rs:6: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-self-super-crate.rs:8: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-self-super-crate.rs:10: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-self-super-crate.rs:12: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 5 previous errors - -For more information about this error, try `rustc --explain E0365`. diff --git a/tests/ui/use/use-path-segment-kw.rs b/tests/ui/use/use-path-segment-kw.rs index 164f645dc5c54..be64f239b9fc3 100644 --- a/tests/ui/use/use-path-segment-kw.rs +++ b/tests/ui/use/use-path-segment-kw.rs @@ -70,7 +70,7 @@ macro_rules! macro_dollar_crate { fn outer() {} -pub mod foo { +mod foo { pub mod bar { pub mod foobar { pub mod qux {