From 0685c978434b21c18ae2575cbbd72b6234b7701e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sat, 6 Jul 2024 21:53:49 +1000 Subject: [PATCH] Add `warn(unreachable_pub)` to `rustc_borrowck`. --- .../rustc_borrowck/src/borrowck_errors.rs | 2 +- compiler/rustc_borrowck/src/dataflow.rs | 4 +- compiler/rustc_borrowck/src/def_use.rs | 4 +- .../src/diagnostics/conflict_errors.rs | 8 ++-- .../rustc_borrowck/src/diagnostics/mod.rs | 4 +- .../src/diagnostics/move_errors.rs | 2 +- .../src/diagnostics/mutability_errors.rs | 2 +- .../src/diagnostics/outlives_suggestion.rs | 2 +- .../src/diagnostics/region_errors.rs | 14 ++++--- compiler/rustc_borrowck/src/lib.rs | 26 +++++++----- compiler/rustc_borrowck/src/prefixes.rs | 2 +- .../rustc_borrowck/src/region_infer/mod.rs | 12 +++--- .../src/region_infer/opaque_types.rs | 8 ++-- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../src/type_check/relate_tys.rs | 4 +- .../rustc_borrowck/src/universal_regions.rs | 42 +++++++++---------- .../rustc_borrowck/src/util/collect_writes.rs | 2 +- compiler/rustc_borrowck/src/util/mod.rs | 2 +- 18 files changed, 74 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_borrowck/src/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs index 76e39fe94af..86f46b55bfb 100644 --- a/compiler/rustc_borrowck/src/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::Span; impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { - pub fn dcx(&self) -> DiagCtxtHandle<'infcx> { + pub(crate) fn dcx(&self) -> DiagCtxtHandle<'infcx> { self.infcx.dcx() } diff --git a/compiler/rustc_borrowck/src/dataflow.rs b/compiler/rustc_borrowck/src/dataflow.rs index 77794a8525f..2795bc7162f 100644 --- a/compiler/rustc_borrowck/src/dataflow.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -14,7 +14,7 @@ use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, Results, ResultsVisi use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext}; /// The results of the dataflow analyses used by the borrow checker. -pub struct BorrowckResults<'a, 'mir, 'tcx> { +pub(crate) struct BorrowckResults<'a, 'mir, 'tcx> { pub(crate) borrows: Results<'tcx, Borrows<'a, 'mir, 'tcx>>, pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'a, 'mir, 'tcx>>, pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'a, 'mir, 'tcx>>, @@ -22,7 +22,7 @@ pub struct BorrowckResults<'a, 'mir, 'tcx> { /// The transient state of the dataflow analyses used by the borrow checker. #[derive(Debug)] -pub struct BorrowckFlowState<'a, 'mir, 'tcx> { +pub(crate) struct BorrowckFlowState<'a, 'mir, 'tcx> { pub(crate) borrows: as AnalysisDomain<'tcx>>::Domain, pub(crate) uninits: as AnalysisDomain<'tcx>>::Domain, pub(crate) ever_inits: as AnalysisDomain<'tcx>>::Domain, diff --git a/compiler/rustc_borrowck/src/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs index 1f0b0981c8f..7eb9e689afe 100644 --- a/compiler/rustc_borrowck/src/def_use.rs +++ b/compiler/rustc_borrowck/src/def_use.rs @@ -4,13 +4,13 @@ use rustc_middle::mir::visit::{ }; #[derive(Eq, PartialEq, Clone)] -pub enum DefUse { +pub(crate) enum DefUse { Def, Use, Drop, } -pub fn categorize(context: PlaceContext) -> Option { +pub(crate) fn categorize(context: PlaceContext) -> Option { match context { /////////////////////////////////////////////////////////////////////////// // DEFS diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2b46e5597f7..cd35427b914 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -645,7 +645,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } } - pub fn suggest_reborrow( + pub(crate) fn suggest_reborrow( &self, err: &mut Diag<'infcx>, span: Span, @@ -1891,10 +1891,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { struct FindUselessClone<'tcx> { tcx: TyCtxt<'tcx>, typeck_results: &'tcx ty::TypeckResults<'tcx>, - pub clones: Vec<&'tcx hir::Expr<'tcx>>, + clones: Vec<&'tcx hir::Expr<'tcx>>, } impl<'tcx> FindUselessClone<'tcx> { - pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { + fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { Self { tcx, typeck_results: tcx.typeck(def_id), clones: vec![] } } } @@ -1916,7 +1916,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let body = hir.body(body_id).value; expr_finder.visit_expr(body); - pub struct Holds<'tcx> { + struct Holds<'tcx> { ty: Ty<'tcx>, } diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index a2e5c7b8514..33f91d7ad30 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -58,11 +58,11 @@ pub(crate) use region_name::{RegionName, RegionNameSource}; pub(crate) use rustc_middle::util::CallKind; pub(super) struct DescribePlaceOpt { - pub including_downcast: bool, + including_downcast: bool, /// Enable/Disable tuple fields. /// For example `x` tuple. if it's `true` `x.0`. Otherwise `x` - pub including_tuple_field: bool, + including_tuple_field: bool, } pub(super) struct IncludingTupleField(pub(super) bool); diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 792f1548e08..42b1ffd58ad 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -16,7 +16,7 @@ use crate::prefixes::PrefixSet; use crate::MirBorrowckCtxt; #[derive(Debug)] -pub enum IllegalMoveOriginKind<'tcx> { +pub(crate) enum IllegalMoveOriginKind<'tcx> { /// Illegal move due to attempt to move from behind a reference. BorrowedContent { /// The place the reference refers to: if erroneous code was trying to diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 0303b80cace..7b791928689 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -1374,7 +1374,7 @@ impl<'tcx> Visitor<'tcx> for BindingFinder { } } -pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option) -> bool { +fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option) -> bool { debug!("local_info: {:?}, ty.kind(): {:?}", local_decl.local_info, local_decl.ty.kind()); match *local_decl.local_info() { diff --git a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index de0df347429..a59b7b3cde9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -31,7 +31,7 @@ enum SuggestedConstraint { /// /// Adds a help note suggesting adding a where clause with the needed constraints. #[derive(Default)] -pub struct OutlivesSuggestionBuilder { +pub(crate) struct OutlivesSuggestionBuilder { /// The list of outlives constraints that need to be added. Specifically, we map each free /// region to all other regions that it must outlive. I will use the shorthand `fr: /// outlived_frs`. Not all of these regions will already have names necessarily. Some could be diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 451e8bcb16d..ab48a09cfa4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -72,22 +72,24 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> { pub(crate) struct RegionErrors<'tcx>(Vec<(RegionErrorKind<'tcx>, ErrorGuaranteed)>, TyCtxt<'tcx>); impl<'tcx> RegionErrors<'tcx> { - pub fn new(tcx: TyCtxt<'tcx>) -> Self { + pub(crate) fn new(tcx: TyCtxt<'tcx>) -> Self { Self(vec![], tcx) } #[track_caller] - pub fn push(&mut self, val: impl Into>) { + pub(crate) fn push(&mut self, val: impl Into>) { let val = val.into(); let guar = self.1.sess.dcx().delayed_bug(format!("{val:?}")); self.0.push((val, guar)); } - pub fn is_empty(&self) -> bool { + pub(crate) fn is_empty(&self) -> bool { self.0.is_empty() } - pub fn into_iter(self) -> impl Iterator, ErrorGuaranteed)> { + pub(crate) fn into_iter( + self, + ) -> impl Iterator, ErrorGuaranteed)> { self.0.into_iter() } - pub fn has_errors(&self) -> Option { + pub(crate) fn has_errors(&self) -> Option { self.0.get(0).map(|x| x.1) } } @@ -141,7 +143,7 @@ pub(crate) enum RegionErrorKind<'tcx> { /// Information about the various region constraints involved in a borrow checker error. #[derive(Clone, Debug)] -pub struct ErrorConstraintInfo<'tcx> { +pub(crate) struct ErrorConstraintInfo<'tcx> { // fr: outlived_fr pub(super) fr: RegionVid, pub(super) fr_is_local: bool, diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 30dd45d847c..5d54204bf80 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -12,6 +12,7 @@ #![feature(rustdoc_internals)] #![feature(stmt_expr_attributes)] #![feature(try_blocks)] +#![warn(unreachable_pub)] // tidy-alphabetical-end #[macro_use] @@ -2444,7 +2445,7 @@ mod diags { } } - pub struct BorrowckDiags<'infcx, 'tcx> { + pub(crate) struct BorrowckDiags<'infcx, 'tcx> { /// This field keeps track of move errors that are to be reported for given move indices. /// /// There are situations where many errors can be reported for a single move out (see @@ -2468,7 +2469,7 @@ mod diags { } impl<'infcx, 'tcx> BorrowckDiags<'infcx, 'tcx> { - pub fn new() -> Self { + pub(crate) fn new() -> Self { BorrowckDiags { buffered_move_errors: BTreeMap::new(), buffered_mut_errors: Default::default(), @@ -2476,25 +2477,25 @@ mod diags { } } - pub fn buffer_error(&mut self, diag: Diag<'infcx>) { + pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) { self.buffered_diags.push(BufferedDiag::Error(diag)); } - pub fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) { + pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) { self.buffered_diags.push(BufferedDiag::NonError(diag)); } } impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { - pub fn buffer_error(&mut self, diag: Diag<'infcx>) { + pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) { self.diags.buffer_error(diag); } - pub fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) { + pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) { self.diags.buffer_non_error(diag); } - pub fn buffer_move_error( + pub(crate) fn buffer_move_error( &mut self, move_out_indices: Vec, place_and_err: (PlaceRef<'tcx>, Diag<'infcx>), @@ -2510,16 +2511,19 @@ mod diags { } } - pub fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'infcx>, usize)> { + pub(crate) fn get_buffered_mut_error( + &mut self, + span: Span, + ) -> Option<(Diag<'infcx>, usize)> { // FIXME(#120456) - is `swap_remove` correct? self.diags.buffered_mut_errors.swap_remove(&span) } - pub fn buffer_mut_error(&mut self, span: Span, diag: Diag<'infcx>, count: usize) { + pub(crate) fn buffer_mut_error(&mut self, span: Span, diag: Diag<'infcx>, count: usize) { self.diags.buffered_mut_errors.insert(span, (diag, count)); } - pub fn emit_errors(&mut self) -> Option { + pub(crate) fn emit_errors(&mut self) -> Option { let mut res = None; // Buffer any move errors that we collected and de-duplicated. @@ -2553,7 +2557,7 @@ mod diags { self.diags.buffered_diags.is_empty() } - pub fn has_move_error( + pub(crate) fn has_move_error( &self, move_out_indices: &[MoveOutIndex], ) -> Option<&(PlaceRef<'tcx>, Diag<'infcx>)> { diff --git a/compiler/rustc_borrowck/src/prefixes.rs b/compiler/rustc_borrowck/src/prefixes.rs index d3bfd1c418f..39d831378cd 100644 --- a/compiler/rustc_borrowck/src/prefixes.rs +++ b/compiler/rustc_borrowck/src/prefixes.rs @@ -8,7 +8,7 @@ use rustc_middle::mir::{PlaceRef, ProjectionElem}; use super::MirBorrowckCtxt; -pub trait IsPrefixOf<'tcx> { +pub(crate) trait IsPrefixOf<'tcx> { fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool; } diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index c8dc012de4a..6cbdd890b5e 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -42,9 +42,9 @@ mod graphviz; mod opaque_types; mod reverse_sccs; -pub mod values; +pub(crate) mod values; -pub type ConstraintSccs = Sccs; +pub(crate) type ConstraintSccs = Sccs; /// An annotation for region graph SCCs that tracks /// the values of its elements. @@ -226,7 +226,7 @@ pub(crate) struct AppliedMemberConstraint { } #[derive(Debug)] -pub struct RegionDefinition<'tcx> { +pub(crate) struct RegionDefinition<'tcx> { /// What kind of variable is this -- a free region? existential /// variable? etc. (See the `NllRegionVariableOrigin` for more /// info.) @@ -288,7 +288,7 @@ pub(crate) enum Cause { /// `InferCtxt::process_registered_region_obligations` and /// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`. #[derive(Clone, Debug)] -pub struct TypeTest<'tcx> { +pub(crate) struct TypeTest<'tcx> { /// The type `T` that must outlive the region. pub generic_kind: GenericKind<'tcx>, @@ -320,7 +320,7 @@ enum Trace<'tcx> { } #[derive(Clone, PartialEq, Eq, Debug)] -pub enum ExtraConstraintInfo { +pub(crate) enum ExtraConstraintInfo { PlaceholderFromPredicate(Span), } @@ -2259,7 +2259,7 @@ impl<'tcx> RegionDefinition<'tcx> { } #[derive(Clone, Debug)] -pub struct BlameConstraint<'tcx> { +pub(crate) struct BlameConstraint<'tcx> { pub category: ConstraintCategory<'tcx>, pub from_closure: bool, pub cause: ObligationCause<'tcx>, diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 1073ea40694..cd66acd0a8f 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -473,20 +473,20 @@ struct LazyOpaqueTyEnv<'tcx> { } impl<'tcx> LazyOpaqueTyEnv<'tcx> { - pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { + fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { Self { tcx, def_id, canonical_args: std::cell::OnceCell::new() } } - pub fn param_equal_static(&self, param_index: usize) -> bool { + fn param_equal_static(&self, param_index: usize) -> bool { self.get_canonical_args()[param_index].expect_region().is_static() } - pub fn params_equal(&self, param1: usize, param2: usize) -> bool { + fn params_equal(&self, param1: usize, param2: usize) -> bool { let canonical_args = self.get_canonical_args(); canonical_args[param1] == canonical_args[param2] } - pub fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> { + fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> { self.get_canonical_args()[param_index].error_reported() } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index a2669da1b04..bbcc2bbdc10 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -86,7 +86,7 @@ macro_rules! span_mirbug_and_err { mod canonical; mod constraint_conversion; -pub mod free_region_relations; +pub(crate) mod free_region_relations; mod input_output; pub(crate) mod liveness; mod relate_tys; diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index 8da4d80badf..35d8e2573fe 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -57,7 +57,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } -pub struct NllTypeRelating<'me, 'bccx, 'tcx> { +struct NllTypeRelating<'me, 'bccx, 'tcx> { type_checker: &'me mut TypeChecker<'bccx, 'tcx>, /// Where (and why) is this relation taking place? @@ -82,7 +82,7 @@ pub struct NllTypeRelating<'me, 'bccx, 'tcx> { } impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> { - pub fn new( + fn new( type_checker: &'me mut TypeChecker<'bccx, 'tcx>, locations: Locations, category: ConstraintCategory<'tcx>, diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 1ad80cb122a..2e41c918774 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -39,7 +39,7 @@ use crate::renumber::RegionCtxt; use crate::BorrowckInferCtxt; #[derive(Debug)] -pub struct UniversalRegions<'tcx> { +pub(crate) struct UniversalRegions<'tcx> { indices: UniversalRegionIndices<'tcx>, /// The vid assigned to `'static` @@ -95,7 +95,7 @@ pub struct UniversalRegions<'tcx> { /// regions appear free in the defining type and late-bound regions /// appear bound in the signature. #[derive(Copy, Clone, Debug)] -pub enum DefiningTy<'tcx> { +pub(crate) enum DefiningTy<'tcx> { /// The MIR is a closure. The signature is found via /// `ClosureArgs::closure_sig_ty`. Closure(DefId, GenericArgsRef<'tcx>), @@ -131,7 +131,7 @@ impl<'tcx> DefiningTy<'tcx> { /// not a closure or coroutine, there are no upvars, and hence it /// will be an empty list. The order of types in this list will /// match up with the upvar order in the HIR, typesystem, and MIR. - pub fn upvar_tys(self) -> &'tcx ty::List> { + pub(crate) fn upvar_tys(self) -> &'tcx ty::List> { match self { DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(), DefiningTy::CoroutineClosure(_, args) => args.as_coroutine_closure().upvar_tys(), @@ -145,7 +145,7 @@ impl<'tcx> DefiningTy<'tcx> { /// Number of implicit inputs -- notably the "environment" /// parameter for closures -- that appear in MIR but not in the /// user's code. - pub fn implicit_inputs(self) -> usize { + pub(crate) fn implicit_inputs(self) -> usize { match self { DefiningTy::Closure(..) | DefiningTy::CoroutineClosure(..) @@ -154,15 +154,15 @@ impl<'tcx> DefiningTy<'tcx> { } } - pub fn is_fn_def(&self) -> bool { + pub(crate) fn is_fn_def(&self) -> bool { matches!(*self, DefiningTy::FnDef(..)) } - pub fn is_const(&self) -> bool { + pub(crate) fn is_const(&self) -> bool { matches!(*self, DefiningTy::Const(..) | DefiningTy::InlineConst(..)) } - pub fn def_id(&self) -> DefId { + pub(crate) fn def_id(&self) -> DefId { match *self { DefiningTy::Closure(def_id, ..) | DefiningTy::CoroutineClosure(def_id, ..) @@ -196,7 +196,7 @@ struct UniversalRegionIndices<'tcx> { } #[derive(Debug, PartialEq)] -pub enum RegionClassification { +pub(crate) enum RegionClassification { /// A **global** region is one that can be named from /// anywhere. There is only one, `'static`. Global, @@ -246,7 +246,7 @@ impl<'tcx> UniversalRegions<'tcx> { /// MIR -- that is, all the regions that appear in the function's /// signature. This will also compute the relationships that are /// known between those regions. - pub fn new( + pub(crate) fn new( infcx: &BorrowckInferCtxt<'tcx>, mir_def: LocalDefId, param_env: ty::ParamEnv<'tcx>, @@ -263,7 +263,7 @@ impl<'tcx> UniversalRegions<'tcx> { /// if the `ClosureRegionRequirements` contains something like /// `'1: '2`, then the caller would impose the constraint that /// `V[1]: V[2]`. - pub fn closure_mapping( + pub(crate) fn closure_mapping( tcx: TyCtxt<'tcx>, closure_args: GenericArgsRef<'tcx>, expected_num_vars: usize, @@ -289,13 +289,13 @@ impl<'tcx> UniversalRegions<'tcx> { } /// Returns `true` if `r` is a member of this set of universal regions. - pub fn is_universal_region(&self, r: RegionVid) -> bool { + pub(crate) fn is_universal_region(&self, r: RegionVid) -> bool { (FIRST_GLOBAL_INDEX..self.num_universals).contains(&r.index()) } /// Classifies `r` as a universal region, returning `None` if this /// is not a member of this set of universal regions. - pub fn region_classification(&self, r: RegionVid) -> Option { + pub(crate) fn region_classification(&self, r: RegionVid) -> Option { let index = r.index(); if (FIRST_GLOBAL_INDEX..self.first_extern_index).contains(&index) { Some(RegionClassification::Global) @@ -310,17 +310,17 @@ impl<'tcx> UniversalRegions<'tcx> { /// Returns an iterator over all the RegionVids corresponding to /// universally quantified free regions. - pub fn universal_regions(&self) -> impl Iterator { + pub(crate) fn universal_regions(&self) -> impl Iterator { (FIRST_GLOBAL_INDEX..self.num_universals).map(RegionVid::from_usize) } /// Returns `true` if `r` is classified as a local region. - pub fn is_local_free_region(&self, r: RegionVid) -> bool { + pub(crate) fn is_local_free_region(&self, r: RegionVid) -> bool { self.region_classification(r) == Some(RegionClassification::Local) } /// Returns the number of universal regions created in any category. - pub fn len(&self) -> usize { + pub(crate) fn len(&self) -> usize { self.num_universals } @@ -329,19 +329,19 @@ impl<'tcx> UniversalRegions<'tcx> { /// closure type (versus those bound in the closure /// signature). They are therefore the regions between which the /// closure may impose constraints that its creator must verify. - pub fn num_global_and_external_regions(&self) -> usize { + pub(crate) fn num_global_and_external_regions(&self) -> usize { self.first_local_index } /// Gets an iterator over all the early-bound regions that have names. - pub fn named_universal_regions<'s>( + pub(crate) fn named_universal_regions<'s>( &'s self, ) -> impl Iterator, ty::RegionVid)> + 's { self.indices.indices.iter().map(|(&r, &v)| (r, v)) } /// See `UniversalRegionIndices::to_region_vid`. - pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { + pub(crate) fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { self.indices.to_region_vid(r) } @@ -416,7 +416,7 @@ impl<'tcx> UniversalRegions<'tcx> { } } - pub fn tainted_by_errors(&self) -> Option { + pub(crate) fn tainted_by_errors(&self) -> Option { self.indices.tainted_by_errors.get() } } @@ -880,7 +880,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> { /// reference those regions from the `ParamEnv`. It is also used /// during initialization. Relies on the `indices` map having been /// fully initialized. - pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { + fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid { if let ty::ReVar(..) = *r { r.as_var() } else if let ty::ReError(guar) = *r { @@ -899,7 +899,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> { /// Replaces all free regions in `value` with region vids, as /// returned by `to_region_vid`. - pub fn fold_to_region_vids(&self, tcx: TyCtxt<'tcx>, value: T) -> T + fn fold_to_region_vids(&self, tcx: TyCtxt<'tcx>, value: T) -> T where T: TypeFoldable>, { diff --git a/compiler/rustc_borrowck/src/util/collect_writes.rs b/compiler/rustc_borrowck/src/util/collect_writes.rs index 93c7810b545..55f1073176a 100644 --- a/compiler/rustc_borrowck/src/util/collect_writes.rs +++ b/compiler/rustc_borrowck/src/util/collect_writes.rs @@ -1,7 +1,7 @@ use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{Body, Local, Location}; -pub trait FindAssignments { +pub(crate) trait FindAssignments { // Finds all statements that assign directly to local (i.e., X = ...) // and returns their locations. fn find_assignments(&self, local: Local) -> Vec; diff --git a/compiler/rustc_borrowck/src/util/mod.rs b/compiler/rustc_borrowck/src/util/mod.rs index 7377d4de727..5f2960b768b 100644 --- a/compiler/rustc_borrowck/src/util/mod.rs +++ b/compiler/rustc_borrowck/src/util/mod.rs @@ -1,3 +1,3 @@ mod collect_writes; -pub use collect_writes::FindAssignments; +pub(crate) use collect_writes::FindAssignments;