From b10ccb8e2e3e3ddcd2fcc92d97c8ade0814e488e Mon Sep 17 00:00:00 2001 From: Roland Xu Date: Fri, 25 Sep 2026 10:35:19 +0800 Subject: [PATCH] Don't emit sugg for pub-reexport extern std --- compiler/rustc_resolve/src/diagnostics/mod.rs | 2 +- compiler/rustc_resolve/src/imports.rs | 7 +++++-- tests/ui/pub/pub-reexport-extern-std-issue-163293.rs | 2 ++ tests/ui/pub/pub-reexport-extern-std-issue-163293.stderr | 8 -------- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics/mod.rs b/compiler/rustc_resolve/src/diagnostics/mod.rs index d17e01425d2..38981426837 100644 --- a/compiler/rustc_resolve/src/diagnostics/mod.rs +++ b/compiler/rustc_resolve/src/diagnostics/mod.rs @@ -840,7 +840,7 @@ pub(crate) struct PrivateExternCrateReexport { style = "verbose", applicability = "maybe-incorrect" )] - pub sugg: Span, + pub sugg: Option, } #[derive(Subdiagnostic)] diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 938a6cb2903..5cd45c5de52 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1673,8 +1673,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import.summary(), decl) { let ImportKind::Single { id, .. } = import.kind else { unreachable!() }; - let sugg = self.tcx.source_span(extern_crate_id).shrink_to_lo(); - let diagnostic = crate::diagnostics::PrivateExternCrateReexport { ident, sugg }; + let sugg = self.tcx.source_span(extern_crate_id); + let diagnostic = crate::diagnostics::PrivateExternCrateReexport { + ident, + sugg: sugg.can_be_used_for_suggestions().then(|| sugg.shrink_to_lo()), + }; return Some(BufferedEarlyLint { lint_id: LintId::of(PUB_USE_OF_PRIVATE_EXTERN_CRATE), node_id: id, diff --git a/tests/ui/pub/pub-reexport-extern-std-issue-163293.rs b/tests/ui/pub/pub-reexport-extern-std-issue-163293.rs index ad3a07bbd5f..9189ca2fb41 100644 --- a/tests/ui/pub/pub-reexport-extern-std-issue-163293.rs +++ b/tests/ui/pub/pub-reexport-extern-std-issue-163293.rs @@ -1,4 +1,6 @@ pub use std as x; +//~^ ERROR extern crate `std` is private and cannot be re-exported +//~^^ WARN this was previously accepted by the compiler but is being phased out //@ edition: 2015 diff --git a/tests/ui/pub/pub-reexport-extern-std-issue-163293.stderr b/tests/ui/pub/pub-reexport-extern-std-issue-163293.stderr index 880a871601e..ee5ba1fc80a 100644 --- a/tests/ui/pub/pub-reexport-extern-std-issue-163293.stderr +++ b/tests/ui/pub/pub-reexport-extern-std-issue-163293.stderr @@ -7,10 +7,6 @@ LL | pub use std as x; = 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 pub use std as x; - | +++ error: aborting due to 1 previous error @@ -25,8 +21,4 @@ LL | pub use std as x; = 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 pub use std as x; - | +++