Add warn(unreachable_pub) to rustc_monomorphize.

This commit is contained in:
Nicholas Nethercote 2024-08-29 15:08:07 +10:00
parent 8a8dd3f33e
commit e3062147de
5 changed files with 22 additions and 17 deletions

View File

@ -242,12 +242,12 @@ use tracing::{debug, instrument, trace};
use crate::errors::{self, EncounteredErrorWhileInstantiating, NoOptimizedMir, RecursionLimit}; use crate::errors::{self, EncounteredErrorWhileInstantiating, NoOptimizedMir, RecursionLimit};
#[derive(PartialEq)] #[derive(PartialEq)]
pub enum MonoItemCollectionStrategy { pub(crate) enum MonoItemCollectionStrategy {
Eager, Eager,
Lazy, Lazy,
} }
pub struct UsageMap<'tcx> { pub(crate) struct UsageMap<'tcx> {
// Maps every mono item to the mono items used by it. // Maps every mono item to the mono items used by it.
used_map: UnordMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>>, used_map: UnordMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>>,
@ -306,13 +306,17 @@ impl<'tcx> UsageMap<'tcx> {
assert!(self.used_map.insert(user_item, used_items).is_none()); assert!(self.used_map.insert(user_item, used_items).is_none());
} }
pub fn get_user_items(&self, item: MonoItem<'tcx>) -> &[MonoItem<'tcx>] { pub(crate) fn get_user_items(&self, item: MonoItem<'tcx>) -> &[MonoItem<'tcx>] {
self.user_map.get(&item).map(|items| items.as_slice()).unwrap_or(&[]) self.user_map.get(&item).map(|items| items.as_slice()).unwrap_or(&[])
} }
/// Internally iterate over all inlined items used by `item`. /// Internally iterate over all inlined items used by `item`.
pub fn for_each_inlined_used_item<F>(&self, tcx: TyCtxt<'tcx>, item: MonoItem<'tcx>, mut f: F) pub(crate) fn for_each_inlined_used_item<F>(
where &self,
tcx: TyCtxt<'tcx>,
item: MonoItem<'tcx>,
mut f: F,
) where
F: FnMut(MonoItem<'tcx>), F: FnMut(MonoItem<'tcx>),
{ {
let used_items = self.used_map.get(&item).unwrap(); let used_items = self.used_map.get(&item).unwrap();
@ -1615,6 +1619,6 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
(mono_items, state.usage_map.into_inner()) (mono_items, state.usage_map.into_inner())
} }
pub fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
providers.hooks.should_codegen_locally = should_codegen_locally; providers.hooks.should_codegen_locally = should_codegen_locally;
} }

View File

@ -8,7 +8,7 @@ use crate::fluent_generated as fluent;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_recursion_limit)] #[diag(monomorphize_recursion_limit)]
pub struct RecursionLimit { pub(crate) struct RecursionLimit {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub shrunk: String, pub shrunk: String,
@ -22,13 +22,13 @@ pub struct RecursionLimit {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_no_optimized_mir)] #[diag(monomorphize_no_optimized_mir)]
pub struct NoOptimizedMir { pub(crate) struct NoOptimizedMir {
#[note] #[note]
pub span: Span, pub span: Span,
pub crate_name: Symbol, pub crate_name: Symbol,
} }
pub struct UnusedGenericParamsHint { pub(crate) struct UnusedGenericParamsHint {
pub span: Span, pub span: Span,
pub param_spans: Vec<Span>, pub param_spans: Vec<Span>,
pub param_names: Vec<String>, pub param_names: Vec<String>,
@ -53,7 +53,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for UnusedGenericParamsHint {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(monomorphize_large_assignments)] #[diag(monomorphize_large_assignments)]
#[note] #[note]
pub struct LargeAssignmentsLint { pub(crate) struct LargeAssignmentsLint {
#[label] #[label]
pub span: Span, pub span: Span,
pub size: u64, pub size: u64,
@ -62,7 +62,7 @@ pub struct LargeAssignmentsLint {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_symbol_already_defined)] #[diag(monomorphize_symbol_already_defined)]
pub struct SymbolAlreadyDefined { pub(crate) struct SymbolAlreadyDefined {
#[primary_span] #[primary_span]
pub span: Option<Span>, pub span: Option<Span>,
pub symbol: String, pub symbol: String,
@ -70,13 +70,13 @@ pub struct SymbolAlreadyDefined {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_couldnt_dump_mono_stats)] #[diag(monomorphize_couldnt_dump_mono_stats)]
pub struct CouldntDumpMonoStats { pub(crate) struct CouldntDumpMonoStats {
pub error: String, pub error: String,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_encountered_error_while_instantiating)] #[diag(monomorphize_encountered_error_while_instantiating)]
pub struct EncounteredErrorWhileInstantiating { pub(crate) struct EncounteredErrorWhileInstantiating {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,
pub formatted_item: String, pub formatted_item: String,
@ -85,10 +85,10 @@ pub struct EncounteredErrorWhileInstantiating {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_start_not_found)] #[diag(monomorphize_start_not_found)]
#[help] #[help]
pub struct StartNotFound; pub(crate) struct StartNotFound;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(monomorphize_unknown_cgu_collection_mode)] #[diag(monomorphize_unknown_cgu_collection_mode)]
pub struct UnknownCguCollectionMode<'a> { pub(crate) struct UnknownCguCollectionMode<'a> {
pub mode: &'a str, pub mode: &'a str,
} }

View File

@ -1,5 +1,6 @@
// tidy-alphabetical-start // tidy-alphabetical-start
#![feature(array_windows)] #![feature(array_windows)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end // tidy-alphabetical-end
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;

View File

@ -1300,7 +1300,7 @@ fn dump_mono_items_stats<'tcx>(
Ok(()) Ok(())
} }
pub fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
providers.collect_and_partition_mono_items = collect_and_partition_mono_items; providers.collect_and_partition_mono_items = collect_and_partition_mono_items;
providers.is_codegened_item = |tcx, def_id| { providers.is_codegened_item = |tcx, def_id| {

View File

@ -19,7 +19,7 @@ use tracing::{debug, instrument};
use crate::errors::UnusedGenericParamsHint; use crate::errors::UnusedGenericParamsHint;
/// Provide implementations of queries relating to polymorphization analysis. /// Provide implementations of queries relating to polymorphization analysis.
pub fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
providers.unused_generic_params = unused_generic_params; providers.unused_generic_params = unused_generic_params;
} }