Don't emit sugg for pub-reexport extern std

This commit is contained in:
Roland Xu
2026-09-25 10:35:19 +08:00
parent e10ba5d3d9
commit b10ccb8e2e
4 changed files with 8 additions and 11 deletions

View File

@@ -840,7 +840,7 @@ pub(crate) struct PrivateExternCrateReexport {
style = "verbose",
applicability = "maybe-incorrect"
)]
pub sugg: Span,
pub sugg: Option<Span>,
}
#[derive(Subdiagnostic)]

View File

@@ -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,

View File

@@ -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

View File

@@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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;
| +++