From 077e5cc09821cc3edbaf3fb0c924c6743c824dcf Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 17 Feb 2026 20:01:21 +0300 Subject: [PATCH 1/2] resolve: Do not create unnecessary `ParentScope` when building external modules --- compiler/rustc_resolve/src/build_reduced_graph.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 50977ba6cff5f..9153d1118d7cf 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -250,16 +250,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { pub(crate) fn build_reduced_graph_external(&self, module: Module<'ra>) { let def_id = module.def_id(); let children = self.tcx.module_children(def_id); - let parent_scope = ParentScope::module(module, self.arenas); for (i, child) in children.iter().enumerate() { - self.build_reduced_graph_for_external_crate_res(child, parent_scope, i, None) + self.build_reduced_graph_for_external_crate_res(child, module, i, None) } for (i, child) in self.cstore().ambig_module_children_untracked(self.tcx, def_id).enumerate() { self.build_reduced_graph_for_external_crate_res( &child.main, - parent_scope, + module, children.len() + i, Some(&child.second), ) @@ -270,11 +269,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { fn build_reduced_graph_for_external_crate_res( &self, child: &ModChild, - parent_scope: ParentScope<'ra>, + parent: Module<'ra>, child_index: usize, ambig_child: Option<&ModChild>, ) { - let parent = parent_scope.module; let child_span = |this: &Self, reexport_chain: &[Reexport], res: def::Res<_>| { this.def_span( reexport_chain @@ -287,7 +285,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let ident = IdentKey::new(orig_ident); let span = child_span(self, reexport_chain, res); let res = res.expect_non_local(); - let expansion = parent_scope.expansion; + let expansion = LocalExpnId::ROOT; let ambig = ambig_child.map(|ambig_child| { let ModChild { ident: _, res, vis, ref reexport_chain } = *ambig_child; let span = child_span(self, reexport_chain, res); From 5a354e538f422a6ee45380020cce512b54ee9b74 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 12 Apr 2026 23:21:55 +0300 Subject: [PATCH 2/2] resolve: Make sure visibilities of import declarations make sense That they are all ordered inside the module and not more private than the module itself The `import_decl_vis` logic is reused when reporting `ambiguous_import_visibilities` lint Some asserts are hardened Some relevant tests are added --- compiler/rustc_resolve/src/ident.rs | 26 +++---- compiler/rustc_resolve/src/imports.rs | 73 ++++++++++++++----- compiler/rustc_resolve/src/lib.rs | 13 +++- ...us-import-visibility-globglob-priv-pass.rs | 23 ++++++ ...biguous-import-visibility-globglob-priv.rs | 21 ++++++ ...ous-import-visibility-globglob-priv.stderr | 47 ++++++++++++ .../ambiguous-import-visibility-globglob.rs | 39 ++++++++++ .../private-from-decl-macro.fail.stderr | 27 +++++++ tests/ui/imports/private-from-decl-macro.rs | 35 +++++++++ tests/ui/privacy/restricted/decl-macros.rs | 15 ++++ .../ui/privacy/restricted/decl-macros.stderr | 25 +++++++ .../ui/pub/pub-reexport-priv-extern-crate.rs | 7 +- .../pub/pub-reexport-priv-extern-crate.stderr | 36 ++++++++- tests/ui/resolve/decl-macro-use-no-ice.rs | 2 +- tests/ui/resolve/decl-macro-use-no-ice.stderr | 29 +------- 15 files changed, 350 insertions(+), 68 deletions(-) create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-priv-pass.rs create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-priv.rs create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob.rs create mode 100644 tests/ui/imports/private-from-decl-macro.fail.stderr create mode 100644 tests/ui/imports/private-from-decl-macro.rs create mode 100644 tests/ui/privacy/restricted/decl-macros.rs create mode 100644 tests/ui/privacy/restricted/decl-macros.stderr diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 46b4a3aa25864..7066e4980465a 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -5,7 +5,6 @@ use Namespace::*; use rustc_ast::{self as ast, NodeId}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{DefKind, MacroKinds, Namespace, NonMacroAttrKind, PartialRes, PerNS}; -use rustc_middle::ty::Visibility; use rustc_middle::{bug, span_bug}; use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK; use rustc_session::parse::feature_err; @@ -24,9 +23,9 @@ use crate::late::{ use crate::macros::{MacroRulesScope, sub_namespace_match}; use crate::{ AmbiguityError, AmbiguityKind, AmbiguityWarning, BindingKey, CmResolver, Decl, DeclKind, - Determinacy, Finalize, IdentKey, ImportKind, LateDecl, Module, ModuleKind, ModuleOrUniformRoot, - ParentScope, PathResult, PrivacyError, Res, ResolutionError, Resolver, Scope, ScopeSet, - Segment, Stage, Symbol, Used, errors, + Determinacy, Finalize, IdentKey, ImportKind, ImportSummary, LateDecl, Module, ModuleKind, + ModuleOrUniformRoot, ParentScope, PathResult, PrivacyError, Res, ResolutionError, Resolver, + Scope, ScopeSet, Segment, Stage, Symbol, Used, errors, }; #[derive(Copy, Clone)] @@ -485,11 +484,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // We do not need to report them if we are either in speculative resolution, // or in late resolution when everything is already imported and expanded // and no ambiguities exist. - let import_vis = match finalize { + let import = match finalize { None | Some(Finalize { stage: Stage::Late, .. }) => { return ControlFlow::Break(Ok(decl)); } - Some(Finalize { import_vis, .. }) => import_vis, + Some(Finalize { import, .. }) => import, }; if let Some(&(innermost_decl, _)) = innermost_results.first() { @@ -503,7 +502,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { decl, scope, &innermost_results, - import_vis, + import, ) { // No need to search for more potential ambiguities, one is enough. return ControlFlow::Break(Ok(innermost_decl)); @@ -790,19 +789,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { decl: Decl<'ra>, scope: Scope<'ra>, innermost_results: &[(Decl<'ra>, Scope<'ra>)], - import_vis: Option, + import: Option, ) -> bool { let (innermost_decl, innermost_scope) = innermost_results[0]; let (res, innermost_res) = (decl.res(), innermost_decl.res()); let ambig_vis = if res != innermost_res { None - } else if let Some(import_vis) = import_vis - && let min = - (|d: Decl<'_>| d.vis().min(import_vis.to_def_id(), self.tcx).expect_local()) - && let (min1, min2) = (min(decl), min(innermost_decl)) - && min1 != min2 + } else if let Some(import) = import + && let vis1 = self.import_decl_vis(decl, import) + && let vis2 = self.import_decl_vis(innermost_decl, import) + && vis1 != vis2 { - Some((min1, min2)) + Some((vis1, vis2)) } else { return false; }; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index a94f3ea435e2c..471a7f606fba7 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -37,8 +37,9 @@ use crate::errors::{ use crate::ref_mut::CmCell; use crate::{ AmbiguityError, BindingKey, CmResolver, Decl, DeclData, DeclKind, Determinacy, Finalize, - IdentKey, ImportSuggestion, Module, ModuleOrUniformRoot, ParentScope, PathResult, PerNS, - ResolutionError, Resolver, ScopeSet, Segment, Used, module_to_string, names_to_string, + IdentKey, ImportSuggestion, ImportSummary, Module, ModuleOrUniformRoot, ParentScope, + PathResult, PerNS, ResolutionError, Resolver, ScopeSet, Segment, Used, module_to_string, + names_to_string, }; type Res = def::Res; @@ -269,6 +270,14 @@ impl<'ra> ImportData<'ra> { ImportKind::MacroExport => Reexport::MacroExport, } } + + fn summary(&self) -> ImportSummary { + ImportSummary { + vis: self.vis, + nearest_parent_mod: self.parent_scope.module.nearest_parent_mod().expect_local(), + is_single: matches!(self.kind, ImportKind::Single { .. }), + } + } } /// Records information about the resolution of a name in a namespace of a module. @@ -329,9 +338,9 @@ struct UnresolvedImportError { // Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;` // are permitted for backward-compatibility under a deprecation lint. -fn pub_use_of_private_extern_crate_hack(import: Import<'_>, decl: Decl<'_>) -> Option { - match (&import.kind, &decl.kind) { - (ImportKind::Single { .. }, DeclKind::Import { import: decl_import, .. }) +fn pub_use_of_private_extern_crate_hack(import: ImportSummary, decl: Decl<'_>) -> Option { + match (import.is_single, decl.kind) { + (true, DeclKind::Import { import: decl_import, .. }) if let ImportKind::ExternCrate { id, .. } = decl_import.kind && import.vis.is_public() => { @@ -363,23 +372,44 @@ fn remove_same_import<'ra>(d1: Decl<'ra>, d2: Decl<'ra>) -> (Decl<'ra>, Decl<'ra } impl<'ra, 'tcx> Resolver<'ra, 'tcx> { + pub(crate) fn import_decl_vis(&self, decl: Decl<'ra>, import: ImportSummary) -> Visibility { + assert!(import.vis.is_accessible_from(import.nearest_parent_mod, self.tcx)); + let decl_vis = decl.vis(); + let vis = if decl_vis.is_at_least(import.vis, self.tcx) { + // Ordered, import is less visible than the imported declaration, or the same, + // use the import's visibility. + import.vis + } else if decl_vis.is_accessible_from(import.nearest_parent_mod, self.tcx) { + // Ordered, imported declaration is less visible than the import, but is still visible + // from the current module, use the declaration's visibility. + assert!(import.vis.is_at_least(decl_vis, self.tcx)); + if pub_use_of_private_extern_crate_hack(import, decl).is_some() { + import.vis + } else { + decl_vis.expect_local() + } + } else { + // Ordered or not, the imported declaration is too private for the current module. + // It doesn't matter what visibility we choose here (except in the `PRIVATE_MACRO_USE` + // case), because either some error will be reported, or the import declaration + // will be thrown away (unfortunately cannot use delayed bug here for this reason). + // Use import visibility to keep the all declaration visibilities in a module ordered. + import.vis + }; + assert!(vis.is_accessible_from(import.nearest_parent_mod, self.tcx)); + vis + } + /// Given an import and the declaration that it points to, /// create the corresponding import declaration. pub(crate) fn new_import_decl(&self, decl: Decl<'ra>, import: Import<'ra>) -> Decl<'ra> { - let import_vis = import.vis.to_def_id(); - let vis = if decl.vis().is_at_least(import_vis, self.tcx) - || pub_use_of_private_extern_crate_hack(import, decl).is_some() - { - import_vis - } else { - decl.vis() - }; + let vis = self.import_decl_vis(decl, import.summary()); if let ImportKind::Glob { ref max_vis, .. } = import.kind - && (vis == import_vis + && (vis == import.vis || max_vis.get().is_none_or(|max_vis| vis.is_at_least(max_vis, self.tcx))) { - max_vis.set_unchecked(Some(vis.expect_local())) + max_vis.set_unchecked(Some(vis)) } self.arenas.alloc_decl(DeclData { @@ -387,7 +417,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ambiguity: CmCell::new(None), warn_ambiguity: CmCell::new(false), span: import.span, - vis: CmCell::new(vis), + vis: CmCell::new(vis.to_def_id()), expansion: import.parent_scope.expansion, parent_module: Some(import.parent_scope.module), }) @@ -450,6 +480,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } else if !old_glob_decl.vis().is_at_least(glob_decl.vis(), self.tcx) { // We are glob-importing the same item but with greater visibility. + // All visibilities here are ordered because all of them are ancestors of `module`. // FIXME: Update visibility in place, but without regressions // (#152004, #151124, #152347). glob_decl @@ -473,7 +504,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { decl: Decl<'ra>, warn_ambiguity: bool, ) -> Result<(), Decl<'ra>> { + assert!(!decl.warn_ambiguity.get()); + assert!(decl.ambiguity.get().is_none()); let module = decl.parent_module.unwrap(); + assert!(self.is_accessible_from(decl.vis(), module)); let res = decl.res(); self.check_reserved_macro_name(ident.name, orig_ident_span, res); // Even if underscore names cannot be looked up, we still need to add them to modules, @@ -489,7 +523,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { orig_ident_span, warn_ambiguity, |this, resolution| { - assert!(!decl.warn_ambiguity.get()); if decl.is_glob_import() { resolution.glob_decl = Some(match resolution.glob_decl { Some(old_decl) => this.select_glob_decl( @@ -1264,7 +1297,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { &import.parent_scope, Some(Finalize { report_private: false, - import_vis: Some(import.vis), + import: Some(import.summary()), ..finalize }), bindings[ns].get().decl(), @@ -1464,7 +1497,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // All namespaces must be re-exported with extra visibility for an error to occur. if !any_successful_reexport { let (ns, binding) = reexport_error.unwrap(); - if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import, binding) { + if let Some(extern_crate_id) = + pub_use_of_private_extern_crate_hack(import.summary(), binding) + { let extern_crate_sp = self.tcx.source_span(self.local_def_id(extern_crate_id)); self.lint_buffer.buffer_lint( PUB_USE_OF_PRIVATE_EXTERN_CRATE, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 7334131a1c01d..283d9edf93c9d 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2641,6 +2641,15 @@ enum Stage { Late, } +/// Parts of import data required for finalizing import resolution. +/// Does not carry a lifetime, so it can be stored in `Finalize`. +#[derive(Copy, Clone, Debug)] +struct ImportSummary { + vis: Visibility, + nearest_parent_mod: LocalDefId, + is_single: bool, +} + /// Invariant: if `Finalize` is used, expansion and import resolution must be complete. #[derive(Copy, Clone, Debug)] struct Finalize { @@ -2659,8 +2668,8 @@ struct Finalize { used: Used = Used::Other, /// Finalizing early or late resolution. stage: Stage = Stage::Early, - /// Nominal visibility of the import item, in case we are resolving an import's final segment. - import_vis: Option = None, + /// Some import data, in case we are resolving an import's final segment. + import: Option = None, } impl Finalize { diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-priv-pass.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-priv-pass.rs new file mode 100644 index 0000000000000..96d2953ab4cd4 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-priv-pass.rs @@ -0,0 +1,23 @@ +//@ check-pass + +mod m { + pub struct S {} +} + +mod one_private { + use crate::m::*; + pub use crate::m::*; +} + +// One of the ambiguous imports is not visible from here, +// and does not contribute to the ambiguity. +use crate::one_private::S; + +// Separate module to make visibilities `in crate::inner` and `in crate::one_private` unordered. +mod inner { + // One of the ambiguous imports is not visible from here, + // and does not contribute to the ambiguity. + use crate::one_private::S; +} + +fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-priv.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-priv.rs new file mode 100644 index 0000000000000..ac1a7d5182af5 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-priv.rs @@ -0,0 +1,21 @@ +mod m { + pub struct S {} +} + +mod both { + pub mod private { + use crate::m::*; + pub(super) use crate::m::*; + } +} + +use crate::both::private::S; +//~^ ERROR struct import `S` is private + +// Separate module to make visibilities `in crate::inner` and `in crate::both::private` unordered. +mod inner { + use crate::both::private::S; + //~^ ERROR struct import `S` is private +} + +fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr new file mode 100644 index 0000000000000..6e77808855a6c --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-priv.stderr @@ -0,0 +1,47 @@ +error[E0603]: struct import `S` is private + --> $DIR/ambiguous-import-visibility-globglob-priv.rs:12:27 + | +LL | use crate::both::private::S; + | ^ private struct import + | +note: the struct import `S` is defined here... + --> $DIR/ambiguous-import-visibility-globglob-priv.rs:8:24 + | +LL | pub(super) use crate::m::*; + | ^^^^^^^^^^^ +note: ...and refers to the struct `S` which is defined here + --> $DIR/ambiguous-import-visibility-globglob-priv.rs:2:5 + | +LL | pub struct S {} + | ^^^^^^^^^^^^ you could import this directly +help: import `S` through the re-export + | +LL - use crate::both::private::S; +LL + use m::S; + | + +error[E0603]: struct import `S` is private + --> $DIR/ambiguous-import-visibility-globglob-priv.rs:17:31 + | +LL | use crate::both::private::S; + | ^ private struct import + | +note: the struct import `S` is defined here... + --> $DIR/ambiguous-import-visibility-globglob-priv.rs:8:24 + | +LL | pub(super) use crate::m::*; + | ^^^^^^^^^^^ +note: ...and refers to the struct `S` which is defined here + --> $DIR/ambiguous-import-visibility-globglob-priv.rs:2:5 + | +LL | pub struct S {} + | ^^^^^^^^^^^^ you could import this directly +help: import `S` through the re-export + | +LL - use crate::both::private::S; +LL + use m::S; + | + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0603`. diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob.rs b/tests/ui/imports/ambiguous-import-visibility-globglob.rs new file mode 100644 index 0000000000000..5af32abd1c600 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob.rs @@ -0,0 +1,39 @@ +//@ check-pass + +// FIXME: should report "ambiguous import visibility" in all the cases below. + +mod m { + pub struct S {} +} + +mod min_vis_first { + use crate::m::*; + pub(crate) use crate::m::*; + pub use crate::m::*; + + pub use self::S as S1; + pub(crate) use self::S as S2; + use self::S as S3; // OK +} + +mod mid_vis_first { + pub(crate) use crate::m::*; + use crate::m::*; + pub use crate::m::*; + + pub use self::S as S1; + pub(crate) use self::S as S2; + use self::S as S3; // OK +} + +mod max_vis_first { + pub use crate::m::*; + use crate::m::*; + pub(crate) use crate::m::*; + + pub use self::S as S1; + pub(crate) use self::S as S2; + use self::S as S3; // OK +} + +fn main() {} diff --git a/tests/ui/imports/private-from-decl-macro.fail.stderr b/tests/ui/imports/private-from-decl-macro.fail.stderr new file mode 100644 index 0000000000000..e09c193f5e6ba --- /dev/null +++ b/tests/ui/imports/private-from-decl-macro.fail.stderr @@ -0,0 +1,27 @@ +error[E0423]: expected value, found struct `S` + --> $DIR/private-from-decl-macro.rs:27:17 + | +LL | pub struct S {} + | --------------- `S` defined here +... +LL | let s = S; + | ^ + | +note: constant `m::S` exists but is inaccessible + --> $DIR/private-from-decl-macro.rs:10:5 + | +LL | const S: u8 = 0; + | ^^^^^^^^^^^^^^^^ not accessible +help: use struct literal syntax instead + | +LL | let s = S {}; + | ++ +help: a local variable with a similar name exists (notice the capitalization) + | +LL - let s = S; +LL + let s = s; + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0423`. diff --git a/tests/ui/imports/private-from-decl-macro.rs b/tests/ui/imports/private-from-decl-macro.rs new file mode 100644 index 0000000000000..cdb3bb40ef7b5 --- /dev/null +++ b/tests/ui/imports/private-from-decl-macro.rs @@ -0,0 +1,35 @@ +//@ revisions: pass fail +//@[pass] check-pass + +#![feature(decl_macro)] + +mod m { + // Name in two namespaces, one public, one private. + // The private name is filtered away when importing, even from a macro 2.0 + pub struct S {} + const S: u8 = 0; + + pub macro mac_single($S:ident) { + use crate::m::$S; + } + + pub macro mac_glob() { + use crate::m::*; + } +} + +mod single { + crate::m::mac_single!(S); + + fn check() { + let s = S {}; + #[cfg(fail)] + let s = S; //[fail]~ ERROR expected value, found struct `S` + } +} + +mod glob { + crate::m::mac_glob!(); +} + +fn main() {} diff --git a/tests/ui/privacy/restricted/decl-macros.rs b/tests/ui/privacy/restricted/decl-macros.rs new file mode 100644 index 0000000000000..2e4dbddc8a872 --- /dev/null +++ b/tests/ui/privacy/restricted/decl-macros.rs @@ -0,0 +1,15 @@ +#![feature(decl_macro)] + +mod m { + pub macro mac() { + struct A {} + pub(self) struct B {} //~ ERROR visibilities can only be restricted to ancestor modules + pub(in crate::m) struct C {} //~ ERROR visibilities can only be restricted to ancestor modules + } +} + +mod n { + crate::m::mac!(); +} + +fn main() {} diff --git a/tests/ui/privacy/restricted/decl-macros.stderr b/tests/ui/privacy/restricted/decl-macros.stderr new file mode 100644 index 0000000000000..c932bb5fe9416 --- /dev/null +++ b/tests/ui/privacy/restricted/decl-macros.stderr @@ -0,0 +1,25 @@ +error[E0742]: visibilities can only be restricted to ancestor modules + --> $DIR/decl-macros.rs:6:13 + | +LL | pub(self) struct B {} + | ^^^^ +... +LL | crate::m::mac!(); + | ---------------- in this macro invocation + | + = note: this error originates in the macro `crate::m::mac` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0742]: visibilities can only be restricted to ancestor modules + --> $DIR/decl-macros.rs:7:16 + | +LL | pub(in crate::m) struct C {} + | ^^^^^^^^ +... +LL | crate::m::mac!(); + | ---------------- in this macro invocation + | + = note: this error originates in the macro `crate::m::mac` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0742`. diff --git a/tests/ui/pub/pub-reexport-priv-extern-crate.rs b/tests/ui/pub/pub-reexport-priv-extern-crate.rs index 9d615be30f450..bc91cf4bc7551 100644 --- a/tests/ui/pub/pub-reexport-priv-extern-crate.rs +++ b/tests/ui/pub/pub-reexport-priv-extern-crate.rs @@ -4,6 +4,8 @@ pub use core as reexported_core; //~ ERROR `core` is private and cannot be re-ex mod foo1 { extern crate core; + pub use self::core as core2; //~ ERROR extern crate `core` is private and cannot be re-exported + //~^ WARN this was previously accepted } mod foo2 { @@ -17,4 +19,7 @@ mod baz { pub use crate::foo2::bar::core; //~ ERROR crate import `core` is private } -fn main() {} +fn main() { + // Check that `foo1::core2` has the reexport's visibility and is accessible. + foo1::core2::mem::drop(()); +} diff --git a/tests/ui/pub/pub-reexport-priv-extern-crate.stderr b/tests/ui/pub/pub-reexport-priv-extern-crate.stderr index dbb080e1b0940..1b8279c643318 100644 --- a/tests/ui/pub/pub-reexport-priv-extern-crate.stderr +++ b/tests/ui/pub/pub-reexport-priv-extern-crate.stderr @@ -1,5 +1,5 @@ error[E0603]: crate import `core` is private - --> $DIR/pub-reexport-priv-extern-crate.rs:10:22 + --> $DIR/pub-reexport-priv-extern-crate.rs:12:22 | LL | use crate::foo1::core; | ^^^^ private crate import @@ -11,13 +11,13 @@ LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ error[E0603]: crate import `core` is private - --> $DIR/pub-reexport-priv-extern-crate.rs:17:31 + --> $DIR/pub-reexport-priv-extern-crate.rs:19:31 | LL | pub use crate::foo2::bar::core; | ^^^^ private crate import | note: the crate import `core` is defined here - --> $DIR/pub-reexport-priv-extern-crate.rs:12:9 + --> $DIR/pub-reexport-priv-extern-crate.rs:14:9 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ @@ -36,7 +36,20 @@ help: consider making the `extern crate` item publicly accessible LL | pub extern crate core; | +++ -error: aborting due to 3 previous errors +error[E0365]: extern crate `core` is private and cannot be re-exported + --> $DIR/pub-reexport-priv-extern-crate.rs:7:13 + | +LL | pub use self::core as core2; + | ^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #127909 +help: consider making the `extern crate` item publicly accessible + | +LL | pub extern crate core; + | +++ + +error: aborting due to 4 previous errors Some errors have detailed explanations: E0365, E0603. For more information about an error, try `rustc --explain E0365`. @@ -55,3 +68,18 @@ help: consider making the `extern crate` item publicly accessible LL | pub extern crate core; | +++ +Future breakage diagnostic: +error[E0365]: extern crate `core` is private and cannot be re-exported + --> $DIR/pub-reexport-priv-extern-crate.rs:7:13 + | +LL | pub use self::core as core2; + | ^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #127909 + = note: `#[deny(pub_use_of_private_extern_crate)]` (part of `#[deny(future_incompatible)]`) on by default +help: consider making the `extern crate` item publicly accessible + | +LL | pub extern crate core; + | +++ + diff --git a/tests/ui/resolve/decl-macro-use-no-ice.rs b/tests/ui/resolve/decl-macro-use-no-ice.rs index 39b9cb03fea0d..ec103ab3b2080 100644 --- a/tests/ui/resolve/decl-macro-use-no-ice.rs +++ b/tests/ui/resolve/decl-macro-use-no-ice.rs @@ -11,7 +11,7 @@ mod foo { pub macro m() { use f; //~ ERROR `f` is private, and cannot be re-exported - f!(); //~ ERROR macro import `f` is private + f!(); } } diff --git a/tests/ui/resolve/decl-macro-use-no-ice.stderr b/tests/ui/resolve/decl-macro-use-no-ice.stderr index 9fb75b48b428c..619a5737090e0 100644 --- a/tests/ui/resolve/decl-macro-use-no-ice.stderr +++ b/tests/ui/resolve/decl-macro-use-no-ice.stderr @@ -17,31 +17,6 @@ LL | foo::m!(); | --------- in this macro invocation = note: this error originates in the macro `foo::m` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0603]: macro import `f` is private - --> $DIR/decl-macro-use-no-ice.rs:14:9 - | -LL | f!(); - | ^ private macro import -... -LL | foo::m!(); - | --------- in this macro invocation - | -note: the macro import `f` is defined here... - --> $DIR/decl-macro-use-no-ice.rs:13:13 - | -LL | use f; - | ^ -... -LL | foo::m!(); - | --------- in this macro invocation -note: ...and refers to the macro `f` which is defined here - --> $DIR/decl-macro-use-no-ice.rs:10:5 - | -LL | macro f() {} - | ^^^^^^^^^ - = note: this error originates in the macro `foo::m` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0364, E0603. -For more information about an error, try `rustc --explain E0364`. +For more information about this error, try `rustc --explain E0364`.