Skip to content

Commit a67d371

Browse files
committed
Add deny(unreachable_pub) to rustc_borrowck.
1 parent bedd2e6 commit a67d371

20 files changed

+119
-118
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_span::Span;
88

99
impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
10-
pub fn dcx(&self) -> &'tcx DiagCtxt {
10+
pub(crate) fn dcx(&self) -> &'tcx DiagCtxt {
1111
self.infcx.dcx()
1212
}
1313

compiler/rustc_borrowck/src/dataflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ use std::fmt;
1515
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
1616

1717
/// The results of the dataflow analyses used by the borrow checker.
18-
pub struct BorrowckResults<'mir, 'tcx> {
18+
pub(crate) struct BorrowckResults<'mir, 'tcx> {
1919
pub(crate) borrows: Results<'tcx, Borrows<'mir, 'tcx>>,
2020
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>,
2121
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>,
2222
}
2323

2424
/// The transient state of the dataflow analyses used by the borrow checker.
2525
#[derive(Debug)]
26-
pub struct BorrowckFlowState<'mir, 'tcx> {
26+
pub(crate) struct BorrowckFlowState<'mir, 'tcx> {
2727
pub(crate) borrows: <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
2828
pub(crate) uninits: <MaybeUninitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
2929
pub(crate) ever_inits: <EverInitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,

compiler/rustc_borrowck/src/def_use.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use rustc_middle::mir::visit::{
44
};
55

66
#[derive(Eq, PartialEq, Clone)]
7-
pub enum DefUse {
7+
pub(crate) enum DefUse {
88
Def,
99
Use,
1010
Drop,
1111
}
1212

13-
pub fn categorize(context: PlaceContext) -> Option<DefUse> {
13+
pub(crate) fn categorize(context: PlaceContext) -> Option<DefUse> {
1414
match context {
1515
///////////////////////////////////////////////////////////////////////////
1616
// DEFS

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1820,10 +1820,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18201820
struct FindUselessClone<'tcx> {
18211821
tcx: TyCtxt<'tcx>,
18221822
typeck_results: &'tcx ty::TypeckResults<'tcx>,
1823-
pub clones: Vec<&'tcx hir::Expr<'tcx>>,
1823+
clones: Vec<&'tcx hir::Expr<'tcx>>,
18241824
}
18251825
impl<'tcx> FindUselessClone<'tcx> {
1826-
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
1826+
fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
18271827
Self { tcx, typeck_results: tcx.typeck(def_id), clones: vec![] }
18281828
}
18291829
}
@@ -1845,7 +1845,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
18451845
let body = hir.body(body_id).value;
18461846
expr_finder.visit_expr(body);
18471847

1848-
pub struct Holds<'tcx> {
1848+
struct Holds<'tcx> {
18491849
ty: Ty<'tcx>,
18501850
holds: bool,
18511851
}

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ pub(crate) use region_name::{RegionName, RegionNameSource};
6060
pub(crate) use rustc_middle::util::CallKind;
6161

6262
pub(super) struct DescribePlaceOpt {
63-
pub including_downcast: bool,
63+
including_downcast: bool,
6464

6565
/// Enable/Disable tuple fields.
6666
/// For example `x` tuple. if it's `true` `x.0`. Otherwise `x`
67-
pub including_tuple_field: bool,
67+
including_tuple_field: bool,
6868
}
6969

7070
pub(super) struct IncludingTupleField(pub(super) bool);

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::prefixes::PrefixSet;
1717
use crate::MirBorrowckCtxt;
1818

1919
#[derive(Debug)]
20-
pub enum IllegalMoveOriginKind<'tcx> {
20+
pub(crate) enum IllegalMoveOriginKind<'tcx> {
2121
/// Illegal move due to attempt to move from behind a reference.
2222
BorrowedContent {
2323
/// The place the reference refers to: if erroneous code was trying to

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ impl<'tcx> Visitor<'tcx> for BindingFinder {
13481348
}
13491349
}
13501350

1351-
pub fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
1351+
fn mut_borrow_of_mutable_ref(local_decl: &LocalDecl<'_>, local_name: Option<Symbol>) -> bool {
13521352
debug!("local_info: {:?}, ty.kind(): {:?}", local_decl.local_info, local_decl.ty.kind());
13531353

13541354
match *local_decl.local_info() {

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ enum SuggestedConstraint {
3131
///
3232
/// Adds a help note suggesting adding a where clause with the needed constraints.
3333
#[derive(Default)]
34-
pub struct OutlivesSuggestionBuilder {
34+
pub(crate) struct OutlivesSuggestionBuilder {
3535
/// The list of outlives constraints that need to be added. Specifically, we map each free
3636
/// region to all other regions that it must outlive. I will use the shorthand `fr:
3737
/// outlived_frs`. Not all of these regions will already have names necessarily. Some could be

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
7979
pub(crate) struct RegionErrors<'tcx>(Vec<(RegionErrorKind<'tcx>, ErrorGuaranteed)>, TyCtxt<'tcx>);
8080

8181
impl<'tcx> RegionErrors<'tcx> {
82-
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
82+
pub(crate) fn new(tcx: TyCtxt<'tcx>) -> Self {
8383
Self(vec![], tcx)
8484
}
8585
#[track_caller]
86-
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
86+
pub(crate) fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
8787
let val = val.into();
8888
let guar = self.1.sess.dcx().delayed_bug(format!("{val:?}"));
8989
self.0.push((val, guar));
9090
}
91-
pub fn is_empty(&self) -> bool {
91+
pub(crate) fn is_empty(&self) -> bool {
9292
self.0.is_empty()
9393
}
94-
pub fn into_iter(self) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
94+
fn into_iter(self) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
9595
self.0.into_iter()
9696
}
97-
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
97+
pub(crate) fn has_errors(&self) -> Option<ErrorGuaranteed> {
9898
self.0.get(0).map(|x| x.1)
9999
}
100100
}
@@ -148,7 +148,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
148148

149149
/// Information about the various region constraints involved in a borrow checker error.
150150
#[derive(Clone, Debug)]
151-
pub struct ErrorConstraintInfo<'tcx> {
151+
pub(crate) struct ErrorConstraintInfo<'tcx> {
152152
// fr: outlived_fr
153153
pub(super) fr: RegionVid,
154154
pub(super) fr_is_local: bool,

compiler/rustc_borrowck/src/lib.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! This query borrow-checks the MIR to (further) ensure it is not broken.
22
33
#![allow(internal_features)]
4+
#![deny(unreachable_pub)]
45
#![feature(rustdoc_internals)]
56
#![doc(rust_logo)]
67
#![feature(assert_matches)]
@@ -2433,7 +2434,7 @@ mod diags {
24332434
}
24342435
}
24352436

2436-
pub struct BorrowckDiags<'tcx> {
2437+
pub(crate) struct BorrowckDiags<'tcx> {
24372438
/// This field keeps track of move errors that are to be reported for given move indices.
24382439
///
24392440
/// There are situations where many errors can be reported for a single move out (see
@@ -2457,33 +2458,33 @@ mod diags {
24572458
}
24582459

24592460
impl<'tcx> BorrowckDiags<'tcx> {
2460-
pub fn new() -> Self {
2461+
pub(crate) fn new() -> Self {
24612462
BorrowckDiags {
24622463
buffered_move_errors: BTreeMap::new(),
24632464
buffered_mut_errors: Default::default(),
24642465
buffered_diags: Default::default(),
24652466
}
24662467
}
24672468

2468-
pub fn buffer_error(&mut self, diag: Diag<'tcx>) {
2469+
fn buffer_error(&mut self, diag: Diag<'tcx>) {
24692470
self.buffered_diags.push(BufferedDiag::Error(diag));
24702471
}
24712472

2472-
pub fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) {
2473+
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) {
24732474
self.buffered_diags.push(BufferedDiag::NonError(diag));
24742475
}
24752476
}
24762477

24772478
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
2478-
pub fn buffer_error(&mut self, diag: Diag<'tcx>) {
2479+
pub(crate) fn buffer_error(&mut self, diag: Diag<'tcx>) {
24792480
self.diags.buffer_error(diag);
24802481
}
24812482

2482-
pub fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) {
2483+
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'tcx, ()>) {
24832484
self.diags.buffer_non_error(diag);
24842485
}
24852486

2486-
pub fn buffer_move_error(
2487+
pub(crate) fn buffer_move_error(
24872488
&mut self,
24882489
move_out_indices: Vec<MoveOutIndex>,
24892490
place_and_err: (PlaceRef<'tcx>, Diag<'tcx>),
@@ -2499,16 +2500,16 @@ mod diags {
24992500
}
25002501
}
25012502

2502-
pub fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'tcx>, usize)> {
2503+
pub(crate) fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'tcx>, usize)> {
25032504
// FIXME(#120456) - is `swap_remove` correct?
25042505
self.diags.buffered_mut_errors.swap_remove(&span)
25052506
}
25062507

2507-
pub fn buffer_mut_error(&mut self, span: Span, diag: Diag<'tcx>, count: usize) {
2508+
pub(crate) fn buffer_mut_error(&mut self, span: Span, diag: Diag<'tcx>, count: usize) {
25082509
self.diags.buffered_mut_errors.insert(span, (diag, count));
25092510
}
25102511

2511-
pub fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
2512+
pub(crate) fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
25122513
let mut res = None;
25132514

25142515
// Buffer any move errors that we collected and de-duplicated.
@@ -2542,7 +2543,7 @@ mod diags {
25422543
self.diags.buffered_diags.is_empty()
25432544
}
25442545

2545-
pub fn has_move_error(
2546+
pub(crate) fn has_move_error(
25462547
&self,
25472548
move_out_indices: &[MoveOutIndex],
25482549
) -> Option<&(PlaceRef<'tcx>, Diag<'tcx>)> {

compiler/rustc_borrowck/src/nll.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub type PoloniusOutput = Output<RustcFacts>;
3838
/// The output of `nll::compute_regions`. This includes the computed `RegionInferenceContext`, any
3939
/// closure requirements to propagate, and any generated errors.
4040
pub(crate) struct NllOutput<'tcx> {
41-
pub regioncx: RegionInferenceContext<'tcx>,
42-
pub opaque_type_values: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
43-
pub polonius_input: Option<Box<AllFacts>>,
44-
pub polonius_output: Option<Rc<PoloniusOutput>>,
45-
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
46-
pub nll_errors: RegionErrors<'tcx>,
41+
pub(crate) regioncx: RegionInferenceContext<'tcx>,
42+
pub(crate) opaque_type_values: FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
43+
pub(crate) polonius_input: Option<Box<AllFacts>>,
44+
pub(crate) polonius_output: Option<Rc<PoloniusOutput>>,
45+
pub(crate) opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
46+
pub(crate) nll_errors: RegionErrors<'tcx>,
4747
}
4848

4949
/// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal

compiler/rustc_borrowck/src/prefixes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use super::MirBorrowckCtxt;
88

99
use rustc_middle::mir::{PlaceRef, ProjectionElem};
1010

11-
pub trait IsPrefixOf<'tcx> {
11+
pub(crate) trait IsPrefixOf<'tcx> {
1212
fn is_prefix_of(&self, other: PlaceRef<'tcx>) -> bool;
1313
}
1414

compiler/rustc_borrowck/src/region_infer/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod graphviz;
4444
mod opaque_types;
4545
mod reverse_sccs;
4646

47-
pub mod values;
47+
pub(crate) mod values;
4848

4949
pub struct RegionInferenceContext<'tcx> {
5050
pub var_infos: VarInfos,
@@ -213,19 +213,19 @@ pub(crate) enum Cause {
213213
/// `InferCtxt::process_registered_region_obligations` and
214214
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
215215
#[derive(Clone, Debug)]
216-
pub struct TypeTest<'tcx> {
216+
pub(crate) struct TypeTest<'tcx> {
217217
/// The type `T` that must outlive the region.
218-
pub generic_kind: GenericKind<'tcx>,
218+
pub(crate) generic_kind: GenericKind<'tcx>,
219219

220220
/// The region `'x` that the type must outlive.
221-
pub lower_bound: RegionVid,
221+
pub(crate) lower_bound: RegionVid,
222222

223223
/// The span to blame.
224-
pub span: Span,
224+
pub(crate) span: Span,
225225

226226
/// A test which, if met by the region `'x`, proves that this type
227227
/// constraint is satisfied.
228-
pub verify_bound: VerifyBound<'tcx>,
228+
pub(crate) verify_bound: VerifyBound<'tcx>,
229229
}
230230

231231
/// When we have an unmet lifetime constraint, we try to propagate it outward (e.g. to a closure
@@ -245,7 +245,7 @@ enum Trace<'tcx> {
245245
}
246246

247247
#[derive(Clone, PartialEq, Eq, Debug)]
248-
pub enum ExtraConstraintInfo {
248+
pub(crate) enum ExtraConstraintInfo {
249249
PlaceholderFromPredicate(Span),
250250
}
251251

@@ -2300,9 +2300,9 @@ impl<'tcx> RegionDefinition<'tcx> {
23002300
}
23012301

23022302
#[derive(Clone, Debug)]
2303-
pub struct BlameConstraint<'tcx> {
2304-
pub category: ConstraintCategory<'tcx>,
2305-
pub from_closure: bool,
2306-
pub cause: ObligationCause<'tcx>,
2307-
pub variance_info: ty::VarianceDiagInfo<'tcx>,
2303+
pub(crate) struct BlameConstraint<'tcx> {
2304+
pub(crate) category: ConstraintCategory<'tcx>,
2305+
pub(crate) from_closure: bool,
2306+
pub(crate) cause: ObligationCause<'tcx>,
2307+
pub(crate) variance_info: ty::VarianceDiagInfo<'tcx>,
23082308
}

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -467,20 +467,20 @@ struct LazyOpaqueTyEnv<'tcx> {
467467
}
468468

469469
impl<'tcx> LazyOpaqueTyEnv<'tcx> {
470-
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
470+
fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
471471
Self { tcx, def_id, canonical_args: std::cell::OnceCell::new() }
472472
}
473473

474-
pub fn param_equal_static(&self, param_index: usize) -> bool {
474+
fn param_equal_static(&self, param_index: usize) -> bool {
475475
self.get_canonical_args()[param_index].expect_region().is_static()
476476
}
477477

478-
pub fn params_equal(&self, param1: usize, param2: usize) -> bool {
478+
fn params_equal(&self, param1: usize, param2: usize) -> bool {
479479
let canonical_args = self.get_canonical_args();
480480
canonical_args[param1] == canonical_args[param2]
481481
}
482482

483-
pub fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> {
483+
fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> {
484484
self.get_canonical_args()[param_index].error_reported()
485485
}
486486

0 commit comments

Comments
 (0)