From 71bffef4f9d1f8d34a586031532d6629b0bb33dd Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 16:29:14 +1000 Subject: [PATCH] Add `warn(unreachable_pub)` to `rustc_privacy`. --- compiler/rustc_privacy/src/errors.rs | 18 +++++++++--------- compiler/rustc_privacy/src/lib.rs | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_privacy/src/errors.rs b/compiler/rustc_privacy/src/errors.rs index 89face10750..34553c2b90a 100644 --- a/compiler/rustc_privacy/src/errors.rs +++ b/compiler/rustc_privacy/src/errors.rs @@ -5,7 +5,7 @@ use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] #[diag(privacy_field_is_private, code = E0451)] -pub struct FieldIsPrivate { +pub(crate) struct FieldIsPrivate { #[primary_span] pub span: Span, pub field_name: Symbol, @@ -16,7 +16,7 @@ pub struct FieldIsPrivate { } #[derive(Subdiagnostic)] -pub enum FieldIsPrivateLabel { +pub(crate) enum FieldIsPrivateLabel { #[label(privacy_field_is_private_is_update_syntax_label)] IsUpdateSyntax { #[primary_span] @@ -32,7 +32,7 @@ pub enum FieldIsPrivateLabel { #[derive(Diagnostic)] #[diag(privacy_item_is_private)] -pub struct ItemIsPrivate<'a> { +pub(crate) struct ItemIsPrivate<'a> { #[primary_span] #[label] pub span: Span, @@ -42,7 +42,7 @@ pub struct ItemIsPrivate<'a> { #[derive(Diagnostic)] #[diag(privacy_unnamed_item_is_private)] -pub struct UnnamedItemIsPrivate { +pub(crate) struct UnnamedItemIsPrivate { #[primary_span] pub span: Span, pub kind: &'static str, @@ -50,7 +50,7 @@ pub struct UnnamedItemIsPrivate { #[derive(Diagnostic)] #[diag(privacy_in_public_interface, code = E0446)] -pub struct InPublicInterface<'a> { +pub(crate) struct InPublicInterface<'a> { #[primary_span] #[label] pub span: Span, @@ -63,7 +63,7 @@ pub struct InPublicInterface<'a> { #[derive(Diagnostic)] #[diag(privacy_report_effective_visibility)] -pub struct ReportEffectiveVisibility { +pub(crate) struct ReportEffectiveVisibility { #[primary_span] pub span: Span, pub descr: String, @@ -71,7 +71,7 @@ pub struct ReportEffectiveVisibility { #[derive(LintDiagnostic)] #[diag(privacy_from_private_dep_in_public_interface)] -pub struct FromPrivateDependencyInPublicInterface<'a> { +pub(crate) struct FromPrivateDependencyInPublicInterface<'a> { pub kind: &'a str, pub descr: DiagArgFromDisplay<'a>, pub krate: Symbol, @@ -79,7 +79,7 @@ pub struct FromPrivateDependencyInPublicInterface<'a> { #[derive(LintDiagnostic)] #[diag(privacy_unnameable_types_lint)] -pub struct UnnameableTypesLint<'a> { +pub(crate) struct UnnameableTypesLint<'a> { #[label] pub span: Span, pub kind: &'a str, @@ -93,7 +93,7 @@ pub struct UnnameableTypesLint<'a> { // See https://rust-lang.github.io/rfcs/2145-type-privacy.html for more details. #[derive(LintDiagnostic)] #[diag(privacy_private_interface_or_bounds_lint)] -pub struct PrivateInterfacesOrBoundsLint<'a> { +pub(crate) struct PrivateInterfacesOrBoundsLint<'a> { #[label(privacy_item_label)] pub item_span: Span, pub item_kind: &'a str, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 9f78215bfd1..572f71d7c77 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -6,6 +6,7 @@ #![feature(let_chains)] #![feature(rustdoc_internals)] #![feature(try_blocks)] +#![warn(unreachable_pub)] // tidy-alphabetical-end mod errors; @@ -1497,7 +1498,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx, '_> { self.effective_visibilities.effective_vis(def_id).copied() } - pub fn check_item(&mut self, id: ItemId) { + fn check_item(&mut self, id: ItemId) { let tcx = self.tcx; let def_id = id.owner_id.def_id; let item_visibility = tcx.local_visibility(def_id);