diff --git a/compiler/rustc_resolve/src/diagnostics/mod.rs b/compiler/rustc_resolve/src/diagnostics/mod.rs index e33255eec46d8..4a54269a30137 100644 --- a/compiler/rustc_resolve/src/diagnostics/mod.rs +++ b/compiler/rustc_resolve/src/diagnostics/mod.rs @@ -831,22 +831,26 @@ pub(crate) struct CannotBeReexportedCratePublic { #[derive(Diagnostic)] #[diag("`{$ident}` is private, and cannot be re-exported", code = E0365)] -#[note("consider declaring type or module `{$ident}` with `pub`")] pub(crate) struct CannotBeReexportedPrivateNS { #[primary_span] #[label("re-export of private `{$ident}`")] pub(crate) span: Span, pub(crate) ident: Ident, + #[note("consider declaring {$descr} `{$ident}` with `pub`")] + pub(crate) parent: Span, + pub(crate) descr: &'static str, } #[derive(Diagnostic)] #[diag("`{$ident}` is only public within the crate, and cannot be re-exported outside", code = E0365)] -#[note("consider declaring type or module `{$ident}` with `pub`")] pub(crate) struct CannotBeReexportedCratePublicNS { #[primary_span] #[label("re-export of crate public `{$ident}`")] pub(crate) span: Span, pub(crate) ident: Ident, + #[note("consider declaring {$descr} `{$ident}` with `pub`")] + pub(crate) parent: Span, + pub(crate) descr: &'static str, } #[derive(Diagnostic)] @@ -881,11 +885,12 @@ pub(crate) struct ConsiderMarkingAsPubCrate { } #[derive(Subdiagnostic)] -#[note("consider marking `{$ident}` as `pub` in the imported module")] +#[note("consider marking `{$ident}` as `pub` in the imported {$descr}")] pub(crate) struct ConsiderMarkingAsPub { #[primary_span] - pub(crate) span: Span, + pub(crate) span: MultiSpan, pub(crate) ident: Ident, + pub(crate) descr: &'static str, } #[derive(Diagnostic)] diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 9afbb425eeb9d..f7e86925800a3 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -6,10 +6,10 @@ use std::mem; use rustc_ast::NodeId; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::intern::Interned; -use rustc_errors::{Applicability, BufferedEarlyLint, Diagnostic}; +use rustc_errors::{Applicability, BufferedEarlyLint, Diagnostic, MultiSpan}; use rustc_expand::base::SyntaxExtensionKind; use rustc_hir::def::{self, DefKind}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; +use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId, LocalDefIdMap}; use rustc_lint_defs::LintId; use rustc_lint_defs::builtin::{ AMBIGUOUS_GLOB_REEXPORTS, EXPORTED_PRIVATE_DEPENDENCIES, HIDDEN_GLOB_REEXPORTS, @@ -20,7 +20,7 @@ use rustc_middle::ty::Visibility; use rustc_session::diagnostics::feature_err; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::hygiene::LocalExpnId; -use rustc_span::{Ident, OrdSpan, Span, Symbol, kw, span_bug, sym}; +use rustc_span::{DUMMY_SP, Ident, OrdSpan, Span, Symbol, kw, span_bug, sym}; use tracing::debug; use crate::Namespace::{self, *}; @@ -1685,10 +1685,24 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { diagnostic: diagnostic.into(), }); } else if ns == TypeNS { + let def_id = decl.res().def_id(); + let parent = if !def_id.is_crate_root() { self.def_span(def_id) } else { DUMMY_SP }; + let descr = self.tcx().def_descr(def_id); + if crate_private_reexport { - self.dcx().emit_err(CannotBeReexportedCratePublicNS { span: import.span, ident }); + self.dcx().emit_err(CannotBeReexportedCratePublicNS { + span: import.span, + ident, + parent, + descr, + }); } else { - self.dcx().emit_err(CannotBeReexportedPrivateNS { span: import.span, ident }); + self.dcx().emit_err(CannotBeReexportedPrivateNS { + span: import.span, + ident, + parent, + descr, + }); } } else { let mut err = if crate_private_reexport { @@ -1708,7 +1722,30 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { err.subdiagnostic(ConsiderMarkingAsPubCrate { vis_span: import.vis_span }); } _ => { - err.subdiagnostic(ConsiderMarkingAsPub { span: import.span, ident }); + let mut span: MultiSpan = decl.span.into(); + let descr = if decl.is_import() { + "re-export" + } else if let Some(def_id) = decl.res().opt_def_id() { + let parent = self.tcx().parent(def_id); + + if let DefKind::Variant = self.tcx().def_kind(parent) { + // We had the DefId for the variant's constructor, but we want to point at the enum. + span.push_span_context( + self.def_span(self.tcx().parent(parent)).shrink_to_lo(), + ); + self.tcx().def_descr(self.tcx().parent(parent)) + } else if CRATE_DEF_ID.to_def_id() != parent { + span.push_span_context(self.def_span(parent).shrink_to_lo()); + self.tcx().def_descr(parent) + } else { + self.tcx().def_descr(parent) + } + } else { + // unreachable, but provide fallback just in case + debug_assert!(false, "we have a DefId in {decl:?} with no parent?"); + "module" + }; + err.subdiagnostic(ConsiderMarkingAsPub { span, ident, descr }); } } err.emit(); diff --git a/tests/ui/error-codes/E0365.stderr b/tests/ui/error-codes/E0365.stderr index d6eb9d6c38339..4199459e12d1a 100644 --- a/tests/ui/error-codes/E0365.stderr +++ b/tests/ui/error-codes/E0365.stderr @@ -4,7 +4,13 @@ error[E0365]: `foo` is only public within the crate, and cannot be re-exported o LL | pub use foo as foo2; | ^^^^^^^^^^^ re-export of crate public `foo` | - = note: consider declaring type or module `foo` with `pub` +note: consider declaring module `foo` with `pub` + --> $DIR/E0365.rs:1:1 + | +LL | / mod foo { +LL | | pub const X: u32 = 1; +LL | | } + | |_^ error: aborting due to 1 previous error diff --git a/tests/ui/hygiene/privacy-early.stderr b/tests/ui/hygiene/privacy-early.stderr index 22a8db986ad3d..2c1ac643b9a33 100644 --- a/tests/ui/hygiene/privacy-early.stderr +++ b/tests/ui/hygiene/privacy-early.stderr @@ -9,13 +9,11 @@ LL | foo::m!(); | --------- in this macro invocation | note: consider marking `f` as `pub` in the imported module - --> $DIR/privacy-early.rs:10:13 + --> $DIR/privacy-early.rs:6:5 | -LL | use f as g; - | ^^^^^^ -... -LL | foo::m!(); - | --------- in this macro invocation +LL | mod foo { +LL | fn f() {} + | ^^^^^^^^^ error[E0364]: `f` is private, and cannot be re-exported --> $DIR/privacy-early.rs:10:13 @@ -28,14 +26,12 @@ LL | foo::m!(); | --------- in this macro invocation | note: consider marking `f` as `pub` in the imported module - --> $DIR/privacy-early.rs:10:13 + --> $DIR/privacy-early.rs:7:5 | -LL | use f as g; - | ^^^^^^ -... -LL | foo::m!(); - | --------- in this macro invocation - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +LL | mod foo { +LL | fn f() {} +LL | macro f() {} + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/imports/private-from-decl-macro.fail.stderr b/tests/ui/imports/private-from-decl-macro.fail.stderr index 80b6fde5e8539..9468c3535f7f1 100644 --- a/tests/ui/imports/private-from-decl-macro.fail.stderr +++ b/tests/ui/imports/private-from-decl-macro.fail.stderr @@ -10,13 +10,12 @@ LL | crate::m::mac_glob!(); | --------------------- in this macro invocation | note: consider marking `S` as `pub` in the imported module - --> $DIR/private-from-decl-macro.rs:18:13 + --> $DIR/private-from-decl-macro.rs:10:5 | -LL | use crate::m::*; - | ^^^^^^^^^^^ +LL | mod m { ... -LL | crate::m::mac_glob!(); - | --------------------- in this macro invocation +LL | const S: u8 = 0; + | ^^^^^^^^^^^^^^^^ error[E0423]: cannot find value `S` in this scope --> $DIR/private-from-decl-macro.rs:28:17 diff --git a/tests/ui/imports/reexports.stderr b/tests/ui/imports/reexports.stderr index cb3836305c1ab..18e7739622219 100644 --- a/tests/ui/imports/reexports.stderr +++ b/tests/ui/imports/reexports.stderr @@ -5,10 +5,11 @@ LL | pub use super::foo; | ^^^^^^^^^^ | note: consider marking `foo` as `pub` in the imported module - --> $DIR/reexports.rs:8:17 + --> $DIR/reexports.rs:4:5 | -LL | pub use super::foo; - | ^^^^^^^^^^ +LL | mod a { +LL | fn foo() {} + | ^^^^^^^^^^^ error[E0603]: module import `foo` is private --> $DIR/reexports.rs:36:22 diff --git a/tests/ui/modules/issue-56411.stderr b/tests/ui/modules/issue-56411.stderr index 6e8912146883d..06f603bc55921 100644 --- a/tests/ui/modules/issue-56411.stderr +++ b/tests/ui/modules/issue-56411.stderr @@ -27,7 +27,14 @@ LL | pub use self::$name; LL | import!(("issue-56411-aux.rs", issue_56411_aux)); | ------------------------------------------------ in this macro invocation | - = note: consider declaring type or module `issue_56411_aux` with `pub` +note: consider declaring module `issue_56411_aux` with `pub` + --> $DIR/issue-56411.rs:5:13 + | +LL | mod $name; + | ^^^^^^^^^^ +... +LL | import!(("issue-56411-aux.rs", issue_56411_aux)); + | ------------------------------------------------ in this macro invocation error: aborting due to 2 previous errors diff --git a/tests/ui/privacy/crate-private-reexport.stderr b/tests/ui/privacy/crate-private-reexport.stderr index 9b2626efacd2d..c092120972589 100644 --- a/tests/ui/privacy/crate-private-reexport.stderr +++ b/tests/ui/privacy/crate-private-reexport.stderr @@ -5,10 +5,10 @@ LL | pub use crate::f1; | ^^^^^^^^^ | note: consider marking `f1` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:8:13 + --> $DIR/crate-private-reexport.rs:1:1 | -LL | pub use crate::f1; - | ^^^^^^^^^ +LL | fn f1() {} + | ^^^^^^^^^^ error[E0365]: `S1` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:9:13 @@ -16,7 +16,14 @@ error[E0365]: `S1` is only public within the crate, and cannot be re-exported ou LL | pub use crate::S1; | ^^^^^^^^^ re-export of crate public `S1` | - = note: consider declaring type or module `S1` with `pub` +note: consider declaring struct `S1` with `pub` + --> $DIR/crate-private-reexport.rs:3:1 + | +LL | / struct S1 { +LL | | #[rustfmt::skip] +LL | | bar: i32, +LL | | } + | |_^ error[E0365]: `E1` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:10:13 @@ -24,7 +31,11 @@ error[E0365]: `E1` is only public within the crate, and cannot be re-exported ou LL | pub use crate::E1; | ^^^^^^^^^ re-export of crate public `E1` | - = note: consider declaring type or module `E1` with `pub` +note: consider declaring enum `E1` with `pub` + --> $DIR/crate-private-reexport.rs:2:1 + | +LL | enum E1 { V } + | ^^^^^^^^^^^^^ error[E0364]: `V` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:11:13 @@ -32,11 +43,11 @@ error[E0364]: `V` is only public within the crate, and cannot be re-exported out LL | pub use crate::E1::V; | ^^^^^^^^^^^^ | -note: consider marking `V` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:11:13 +note: consider marking `V` as `pub` in the imported enum + --> $DIR/crate-private-reexport.rs:2:11 | -LL | pub use crate::E1::V; - | ^^^^^^^^^^^^ +LL | enum E1 { V } + | ^ error[E0364]: `f2` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:23:13 @@ -45,10 +56,10 @@ LL | pub use crate::f2; | ^^^^^^^^^ | note: consider marking `f2` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:23:13 + --> $DIR/crate-private-reexport.rs:14:1 | -LL | pub use crate::f2; - | ^^^^^^^^^ +LL | pub(crate) fn f2() {} + | ^^^^^^^^^^^^^^^^^^^^^ error[E0365]: `S2` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:24:13 @@ -56,7 +67,14 @@ error[E0365]: `S2` is only public within the crate, and cannot be re-exported ou LL | pub use crate::S2; | ^^^^^^^^^ re-export of crate public `S2` | - = note: consider declaring type or module `S2` with `pub` +note: consider declaring struct `S2` with `pub` + --> $DIR/crate-private-reexport.rs:18:1 + | +LL | / pub(crate) struct S2 { +LL | | #[rustfmt::skip] +LL | | bar: i32, +LL | | } + | |_^ error[E0365]: `E2` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:25:13 @@ -64,7 +82,13 @@ error[E0365]: `E2` is only public within the crate, and cannot be re-exported ou LL | pub use crate::E2; | ^^^^^^^^^ re-export of crate public `E2` | - = note: consider declaring type or module `E2` with `pub` +note: consider declaring enum `E2` with `pub` + --> $DIR/crate-private-reexport.rs:15:1 + | +LL | / pub(crate) enum E2 { +LL | | V +LL | | } + | |_^ error[E0364]: `V` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:26:13 @@ -72,11 +96,12 @@ error[E0364]: `V` is only public within the crate, and cannot be re-exported out LL | pub use crate::E2::V; | ^^^^^^^^^^^^ | -note: consider marking `V` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:26:13 +note: consider marking `V` as `pub` in the imported enum + --> $DIR/crate-private-reexport.rs:16:5 | -LL | pub use crate::E2::V; - | ^^^^^^^^^^^^ +LL | pub(crate) enum E2 { +LL | V + | ^ error[E0364]: `f3` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:39:9 @@ -85,10 +110,11 @@ LL | pub use m3::f3; | ^^^^^^ | note: consider marking `f3` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:39:9 + --> $DIR/crate-private-reexport.rs:30:5 | -LL | pub use m3::f3; - | ^^^^^^ +LL | mod m3 { +LL | pub(crate) fn f3() {} + | ^^^^^^^^^^^^^^^^^^^^^ error[E0365]: `S3` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:40:9 @@ -96,7 +122,14 @@ error[E0365]: `S3` is only public within the crate, and cannot be re-exported ou LL | pub use m3::S3; | ^^^^^^ re-export of crate public `S3` | - = note: consider declaring type or module `S3` with `pub` +note: consider declaring struct `S3` with `pub` + --> $DIR/crate-private-reexport.rs:34:5 + | +LL | / pub(crate) struct S3 { +LL | | #[rustfmt::skip] +LL | | bar: i32, +LL | | } + | |_____^ error[E0365]: `E3` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:41:9 @@ -104,7 +137,13 @@ error[E0365]: `E3` is only public within the crate, and cannot be re-exported ou LL | pub use m3::E3; | ^^^^^^ re-export of crate public `E3` | - = note: consider declaring type or module `E3` with `pub` +note: consider declaring enum `E3` with `pub` + --> $DIR/crate-private-reexport.rs:31:5 + | +LL | / pub(crate) enum E3 { +LL | | V +LL | | } + | |_____^ error[E0364]: `V` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:42:9 @@ -112,11 +151,12 @@ error[E0364]: `V` is only public within the crate, and cannot be re-exported out LL | pub use m3::E3::V; | ^^^^^^^^^ | -note: consider marking `V` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:42:9 +note: consider marking `V` as `pub` in the imported enum + --> $DIR/crate-private-reexport.rs:32:9 | -LL | pub use m3::E3::V; - | ^^^^^^^^^ +LL | pub(crate) enum E3 { +LL | V + | ^ error[E0364]: `f4` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:45:9 @@ -125,10 +165,10 @@ LL | pub use crate::f4 as f5; | ^^^^^^^^^^^^^^^ | note: consider marking `f4` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:45:9 + --> $DIR/crate-private-reexport.rs:44:1 | -LL | pub use crate::f4 as f5; - | ^^^^^^^^^^^^^^^ +LL | pub(self) fn f4() {} + | ^^^^^^^^^^^^^^^^^^^^ error[E0364]: `f6` is private, and cannot be re-exported --> $DIR/crate-private-reexport.rs:53:13 @@ -137,10 +177,11 @@ LL | pub use self::m::f6; | ^^^^^^^^^^^ | note: consider marking `f6` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:53:13 + --> $DIR/crate-private-reexport.rs:49:9 | -LL | pub use self::m::f6; - | ^^^^^^^^^^^ +LL | pub mod m { +LL | pub(super) fn f6() {} + | ^^^^^^^^^^^^^^^^^^^^^ error[E0364]: `f7` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:54:13 @@ -149,10 +190,12 @@ LL | pub use self::m::f7; | ^^^^^^^^^^^ | note: consider marking `f7` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:54:13 + --> $DIR/crate-private-reexport.rs:50:9 | -LL | pub use self::m::f7; - | ^^^^^^^^^^^ +LL | pub mod m { +LL | pub(super) fn f6() {} +LL | pub(crate) fn f7() {} + | ^^^^^^^^^^^^^^^^^^^^^ error[E0364]: `f8` is private, and cannot be re-exported --> $DIR/crate-private-reexport.rs:55:13 @@ -161,10 +204,12 @@ LL | pub use self::m::f8; | ^^^^^^^^^^^ | note: consider marking `f8` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:55:13 + --> $DIR/crate-private-reexport.rs:51:9 | -LL | pub use self::m::f8; - | ^^^^^^^^^^^ +LL | pub mod m { +... +LL | pub(in crate::m10) fn f8() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0364]: `f7` is only public within the crate, and cannot be re-exported outside --> $DIR/crate-private-reexport.rs:58:9 @@ -173,10 +218,12 @@ LL | pub use m10::m::f7; | ^^^^^^^^^^ | note: consider marking `f7` as `pub` in the imported module - --> $DIR/crate-private-reexport.rs:58:9 + --> $DIR/crate-private-reexport.rs:50:9 | -LL | pub use m10::m::f7; - | ^^^^^^^^^^ +LL | pub mod m { +LL | pub(super) fn f6() {} +LL | pub(crate) fn f7() {} + | ^^^^^^^^^^^^^^^^^^^^^ error[E0603]: function `f6` is private --> $DIR/crate-private-reexport.rs:57:17 diff --git a/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr b/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr index f1701d547a62f..ea748ae5f0f60 100644 --- a/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr +++ b/tests/ui/privacy/issue-46209-private-enum-variant-reexport.stderr @@ -4,11 +4,12 @@ error[E0364]: `JuniorGrade` is private, and cannot be re-exported LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^^^^^^^^ | -note: consider marking `JuniorGrade` as `pub` in the imported module - --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:32 +note: consider marking `JuniorGrade` as `pub` in the imported enum + --> $DIR/issue-46209-private-enum-variant-reexport.rs:25:9 | -LL | pub use self::Lieutenant::{JuniorGrade, Full}; - | ^^^^^^^^^^^ +LL | enum Lieutenant { +LL | JuniorGrade, + | ^^^^^^^^^^^ error[E0364]: `Full` is private, and cannot be re-exported --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:45 @@ -16,11 +17,13 @@ error[E0364]: `Full` is private, and cannot be re-exported LL | pub use self::Lieutenant::{JuniorGrade, Full}; | ^^^^ | -note: consider marking `Full` as `pub` in the imported module - --> $DIR/issue-46209-private-enum-variant-reexport.rs:6:45 +note: consider marking `Full` as `pub` in the imported enum + --> $DIR/issue-46209-private-enum-variant-reexport.rs:26:9 | -LL | pub use self::Lieutenant::{JuniorGrade, Full}; - | ^^^^ +LL | enum Lieutenant { +LL | JuniorGrade, +LL | Full, + | ^^^^ error: glob import doesn't reexport anything with visibility `pub` because no imported item is public enough --> $DIR/issue-46209-private-enum-variant-reexport.rs:3:13 diff --git a/tests/ui/privacy/macro-private-reexport.stderr b/tests/ui/privacy/macro-private-reexport.stderr index aa02715c20298..33c68ce013d62 100644 --- a/tests/ui/privacy/macro-private-reexport.stderr +++ b/tests/ui/privacy/macro-private-reexport.stderr @@ -23,10 +23,12 @@ LL | pub use baz as _; | ^^^^^^^^ | note: consider marking `baz` as `pub` in the imported module - --> $DIR/macro-private-reexport.rs:14:13 + --> $DIR/macro-private-reexport.rs:12:5 | -LL | pub use baz as _; - | ^^^^^^^^ +LL | mod foo { +... +LL | macro baz() {} + | ^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/privacy/private-variant-reexport.stderr b/tests/ui/privacy/private-variant-reexport.stderr index aaa42d8d30dc5..6dd94028a9167 100644 --- a/tests/ui/privacy/private-variant-reexport.stderr +++ b/tests/ui/privacy/private-variant-reexport.stderr @@ -4,11 +4,11 @@ error[E0364]: `V` is only public within the crate, and cannot be re-exported out LL | pub use ::E::V; | ^^^^^^ | -note: consider marking `V` as `pub` in the imported module - --> $DIR/private-variant-reexport.rs:3:13 +note: consider marking `V` as `pub` in the imported enum + --> $DIR/private-variant-reexport.rs:21:10 | -LL | pub use ::E::V; - | ^^^^^^ +LL | enum E { V } + | ^ error[E0364]: `V` is only public within the crate, and cannot be re-exported outside --> $DIR/private-variant-reexport.rs:7:19 @@ -16,11 +16,11 @@ error[E0364]: `V` is only public within the crate, and cannot be re-exported out LL | pub use ::E::{V}; | ^ | -note: consider marking `V` as `pub` in the imported module - --> $DIR/private-variant-reexport.rs:7:19 +note: consider marking `V` as `pub` in the imported enum + --> $DIR/private-variant-reexport.rs:21:10 | -LL | pub use ::E::{V}; - | ^ +LL | enum E { V } + | ^ error[E0432]: unresolved import `E::V` --> $DIR/private-variant-reexport.rs:11:18 diff --git a/tests/ui/privacy/restricted/test.stderr b/tests/ui/privacy/restricted/test.stderr index f380da1ca344e..529bc9cf96766 100644 --- a/tests/ui/privacy/restricted/test.stderr +++ b/tests/ui/privacy/restricted/test.stderr @@ -5,10 +5,11 @@ LL | pub(super) use foo::bar::f as g; | ^^^^^^^^^^^^^^^^ | note: consider marking `f` as `pub` in the imported module - --> $DIR/test.rs:22:24 + --> $DIR/test.rs:9:9 | -LL | pub(super) use foo::bar::f as g; - | ^^^^^^^^^^^^^^^^ +LL | pub mod bar { +LL | pub(super) fn f() {} + | ^^^^^^^^^^^^^^^^^^^^ error[E0433]: cannot find module or crate `bad` in the crate root --> $DIR/test.rs:51:12 diff --git a/tests/ui/proc-macro/issue-79148.stderr b/tests/ui/proc-macro/issue-79148.stderr index 8adc4c6e0dbe4..008a1d16df992 100644 --- a/tests/ui/proc-macro/issue-79148.stderr +++ b/tests/ui/proc-macro/issue-79148.stderr @@ -4,7 +4,7 @@ error[E0364]: `Variant` is only public within the crate, and cannot be re-export LL | cause_ice!(); | ^^^^^^^^^^^^ | -note: consider marking `Variant` as `pub` in the imported module +note: consider marking `Variant` as `pub` in the imported enum --> $DIR/issue-79148.rs:8:1 | LL | cause_ice!(); diff --git a/tests/ui/resolve/decl-macro-use-no-ice.stderr b/tests/ui/resolve/decl-macro-use-no-ice.stderr index 1f47f757f6153..073537d1cabbd 100644 --- a/tests/ui/resolve/decl-macro-use-no-ice.stderr +++ b/tests/ui/resolve/decl-macro-use-no-ice.stderr @@ -9,13 +9,11 @@ LL | foo::m!(); | --------- in this macro invocation | note: consider marking `f` as `pub` in the imported module - --> $DIR/decl-macro-use-no-ice.rs:13:13 + --> $DIR/decl-macro-use-no-ice.rs:10:5 | -LL | use f; - | ^ -... -LL | foo::m!(); - | --------- in this macro invocation +LL | mod foo { +LL | macro f() {} + | ^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/use/pub-use-self-super-crate.stderr b/tests/ui/use/pub-use-self-super-crate.stderr index 0f9c87b93a098..9d6df994a4d79 100644 --- a/tests/ui/use/pub-use-self-super-crate.stderr +++ b/tests/ui/use/pub-use-self-super-crate.stderr @@ -4,7 +4,14 @@ error[E0365]: `self` is only public within the crate, and cannot be re-exported LL | pub use self as this; | ^^^^^^^^^^^^ re-export of crate public `self` | - = note: consider declaring type or module `self` with `pub` +note: consider declaring module `self` with `pub` + --> $DIR/pub-use-self-super-crate.rs:1:1 + | +LL | / mod foo { +LL | | pub use self as this; +... | +LL | | } + | |_^ error[E0365]: `super` is only public within the crate, and cannot be re-exported outside --> $DIR/pub-use-self-super-crate.rs:6:17 @@ -12,7 +19,14 @@ error[E0365]: `super` is only public within the crate, and cannot be re-exported LL | pub use super as parent; | ^^^^^^^^^^^^^^^ re-export of crate public `super` | - = note: consider declaring type or module `super` with `pub` +note: consider declaring module `super` with `pub` + --> $DIR/pub-use-self-super-crate.rs:1:1 + | +LL | / mod foo { +LL | | pub use self as this; +... | +LL | | } + | |_^ error[E0365]: `super` is only public within the crate, and cannot be re-exported outside --> $DIR/pub-use-self-super-crate.rs:8:17 @@ -20,7 +34,14 @@ error[E0365]: `super` is only public within the crate, and cannot be re-exported LL | pub use self::super as parent2; | ^^^^^^^^^^^^^^^^^^^^^^ re-export of crate public `super` | - = note: consider declaring type or module `super` with `pub` +note: consider declaring module `super` with `pub` + --> $DIR/pub-use-self-super-crate.rs:1:1 + | +LL | / mod foo { +LL | | pub use self as this; +... | +LL | | } + | |_^ error[E0365]: `self` is only public within the crate, and cannot be re-exported outside --> $DIR/pub-use-self-super-crate.rs:10:25 @@ -28,7 +49,14 @@ error[E0365]: `self` is only public within the crate, and cannot be re-exported LL | pub use super::{self as parent3}; | ^^^^^^^^^^^^^^^ re-export of crate public `self` | - = note: consider declaring type or module `self` with `pub` +note: consider declaring module `self` with `pub` + --> $DIR/pub-use-self-super-crate.rs:1:1 + | +LL | / mod foo { +LL | | pub use self as this; +... | +LL | | } + | |_^ error[E0365]: `super` is only public within the crate, and cannot be re-exported outside --> $DIR/pub-use-self-super-crate.rs:12:24 @@ -36,7 +64,14 @@ error[E0365]: `super` is only public within the crate, and cannot be re-exported LL | pub use self::{super as parent4}; | ^^^^^^^^^^^^^^^^ re-export of crate public `super` | - = note: consider declaring type or module `super` with `pub` +note: consider declaring module `super` with `pub` + --> $DIR/pub-use-self-super-crate.rs:1:1 + | +LL | / mod foo { +LL | | pub use self as this; +... | +LL | | } + | |_^ error: aborting due to 5 previous errors