From 46ea798a94a9b5924518d64435e884f9d729b456 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 29 Aug 2024 15:10:38 +1000 Subject: [PATCH] Add `warn(unreachable_pub)` to `rustc_next_trait_solver`. --- compiler/rustc_next_trait_solver/src/lib.rs | 4 ++ .../src/solve/eval_ctxt/mod.rs | 6 +-- .../src/solve/inspect/build.rs | 49 +++++++++++-------- .../src/solve/normalizes_to/opaque_types.rs | 4 +- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_next_trait_solver/src/lib.rs b/compiler/rustc_next_trait_solver/src/lib.rs index 0a5b4278058..ea244b5107a 100644 --- a/compiler/rustc_next_trait_solver/src/lib.rs +++ b/compiler/rustc_next_trait_solver/src/lib.rs @@ -4,6 +4,10 @@ //! but were uplifted in the process of making the new trait solver generic. //! So if you got to this crate from the old solver, it's totally normal. +// tidy-alphabetical-start +#![warn(unreachable_pub)] +// tidy-alphabetical-end + pub mod canonicalizer; pub mod coherence; pub mod delegate; diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index e328284c001..3f2f34d3255 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -92,7 +92,7 @@ where #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))] // FIXME: This can be made crate-private once `EvalCtxt` also lives in this crate. -pub struct NestedGoals { +struct NestedGoals { /// These normalizes-to goals are treated specially during the evaluation /// loop. In each iteration we take the RHS of the projection, replace it with /// a fresh inference variable, and only after evaluating that goal do we @@ -109,11 +109,11 @@ pub struct NestedGoals { } impl NestedGoals { - pub fn new() -> Self { + fn new() -> Self { Self { normalizes_to_goals: Vec::new(), goals: Vec::new() } } - pub fn is_empty(&self) -> bool { + fn is_empty(&self) -> bool { self.normalizes_to_goals.is_empty() && self.goals.is_empty() } } diff --git a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs index 86fb036cd3d..742d45de7d3 100644 --- a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs +++ b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs @@ -222,13 +222,13 @@ impl, I: Interner> ProofTreeBuilder { self.state.as_deref_mut() } - pub fn take_and_enter_probe(&mut self) -> ProofTreeBuilder { + pub(crate) fn take_and_enter_probe(&mut self) -> ProofTreeBuilder { let mut nested = ProofTreeBuilder { state: self.state.take(), _infcx: PhantomData }; nested.enter_probe(); nested } - pub fn finalize(self) -> Option> { + pub(crate) fn finalize(self) -> Option> { match *self.state? { DebugSolver::GoalEvaluation(wip_goal_evaluation) => { Some(wip_goal_evaluation.finalize()) @@ -237,22 +237,22 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn new_maybe_root(generate_proof_tree: GenerateProofTree) -> ProofTreeBuilder { + pub(crate) fn new_maybe_root(generate_proof_tree: GenerateProofTree) -> ProofTreeBuilder { match generate_proof_tree { GenerateProofTree::No => ProofTreeBuilder::new_noop(), GenerateProofTree::Yes => ProofTreeBuilder::new_root(), } } - pub fn new_root() -> ProofTreeBuilder { + fn new_root() -> ProofTreeBuilder { ProofTreeBuilder::new(DebugSolver::Root) } - pub fn new_noop() -> ProofTreeBuilder { + fn new_noop() -> ProofTreeBuilder { ProofTreeBuilder { state: None, _infcx: PhantomData } } - pub fn is_noop(&self) -> bool { + pub(crate) fn is_noop(&self) -> bool { self.state.is_none() } @@ -272,7 +272,7 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn new_canonical_goal_evaluation( + pub(crate) fn new_canonical_goal_evaluation( &mut self, goal: CanonicalInput, ) -> ProofTreeBuilder { @@ -284,7 +284,10 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn canonical_goal_evaluation(&mut self, canonical_goal_evaluation: ProofTreeBuilder) { + pub(crate) fn canonical_goal_evaluation( + &mut self, + canonical_goal_evaluation: ProofTreeBuilder, + ) { if let Some(this) = self.as_mut() { match (this, *canonical_goal_evaluation.state.unwrap()) { ( @@ -299,7 +302,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn canonical_goal_evaluation_overflow(&mut self) { + pub(crate) fn canonical_goal_evaluation_overflow(&mut self) { if let Some(this) = self.as_mut() { match this { DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => { @@ -310,7 +313,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder) { + pub(crate) fn goal_evaluation(&mut self, goal_evaluation: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match this { DebugSolver::Root => *this = *goal_evaluation.state.unwrap(), @@ -322,7 +325,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn new_goal_evaluation_step( + pub(crate) fn new_goal_evaluation_step( &mut self, var_values: ty::CanonicalVarValues, instantiated_goal: QueryInput, @@ -340,7 +343,7 @@ impl, I: Interner> ProofTreeBuilder { }) } - pub fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder) { + pub(crate) fn goal_evaluation_step(&mut self, goal_evaluation_step: ProofTreeBuilder) { if let Some(this) = self.as_mut() { match (this, *goal_evaluation_step.state.unwrap()) { ( @@ -354,7 +357,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn add_var_value>(&mut self, arg: T) { + pub(crate) fn add_var_value>(&mut self, arg: T) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -364,7 +367,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn enter_probe(&mut self) { + fn enter_probe(&mut self) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -381,7 +384,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn probe_kind(&mut self, probe_kind: inspect::ProbeKind) { + pub(crate) fn probe_kind(&mut self, probe_kind: inspect::ProbeKind) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -392,7 +395,11 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn probe_final_state(&mut self, delegate: &D, max_input_universe: ty::UniverseIndex) { + pub(crate) fn probe_final_state( + &mut self, + delegate: &D, + max_input_universe: ty::UniverseIndex, + ) { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -409,7 +416,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn add_normalizes_to_goal( + pub(crate) fn add_normalizes_to_goal( &mut self, delegate: &D, max_input_universe: ty::UniverseIndex, @@ -423,7 +430,7 @@ impl, I: Interner> ProofTreeBuilder { ); } - pub fn add_goal( + pub(crate) fn add_goal( &mut self, delegate: &D, max_input_universe: ty::UniverseIndex, @@ -469,7 +476,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn make_canonical_response(&mut self, shallow_certainty: Certainty) { + pub(crate) fn make_canonical_response(&mut self, shallow_certainty: Certainty) { match self.as_mut() { Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { state @@ -482,7 +489,7 @@ impl, I: Interner> ProofTreeBuilder { } } - pub fn finish_probe(mut self) -> ProofTreeBuilder { + pub(crate) fn finish_probe(mut self) -> ProofTreeBuilder { match self.as_mut() { None => {} Some(DebugSolver::CanonicalGoalEvaluationStep(state)) => { @@ -497,7 +504,7 @@ impl, I: Interner> ProofTreeBuilder { self } - pub fn query_result(&mut self, result: QueryResult) { + pub(crate) fn query_result(&mut self, result: QueryResult) { if let Some(this) = self.as_mut() { match this { DebugSolver::CanonicalGoalEvaluation(canonical_goal_evaluation) => { diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs index 120f96d24bd..6a0703c5313 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/opaque_types.rs @@ -97,7 +97,7 @@ where /// Checks whether each generic argument is simply a unique generic placeholder. /// /// FIXME: Interner argument is needed to constrain the `I` parameter. -pub fn uses_unique_placeholders_ignoring_regions( +fn uses_unique_placeholders_ignoring_regions( _cx: I, args: I::GenericArgs, ) -> Result<(), NotUniqueParam> { @@ -130,7 +130,7 @@ pub fn uses_unique_placeholders_ignoring_regions( } // FIXME: This should check for dupes and non-params first, then infer vars. -pub enum NotUniqueParam { +enum NotUniqueParam { DuplicateParam(I::GenericArg), NotParam(I::GenericArg), }