Skip to content

Commit 38a6b67

Browse files
committed
Add deny(unreachable_pub) to rustc_borrowck.
1 parent 413c9bf commit 38a6b67

18 files changed

+73
-67
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 1 addition & 1 deletion
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<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
10-
pub fn dcx(&self) -> DiagCtxtHandle<'infcx> {
10+
pub(crate) fn dcx(&self) -> DiagCtxtHandle<'infcx> {
1111
self.infcx.dcx()
1212
}
1313

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 2 additions & 2 deletions
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<'a, 'mir, 'tcx> {
18+
pub(crate) struct BorrowckResults<'a, 'mir, 'tcx> {
1919
pub(crate) borrows: Results<'tcx, Borrows<'a, 'mir, 'tcx>>,
2020
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'a, 'mir, 'tcx>>,
2121
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'a, 'mir, 'tcx>>,
2222
}
2323

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

compiler/rustc_borrowck/src/def_use.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,10 +1807,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
18071807
struct FindUselessClone<'tcx> {
18081808
tcx: TyCtxt<'tcx>,
18091809
typeck_results: &'tcx ty::TypeckResults<'tcx>,
1810-
pub clones: Vec<&'tcx hir::Expr<'tcx>>,
1810+
clones: Vec<&'tcx hir::Expr<'tcx>>,
18111811
}
18121812
impl<'tcx> FindUselessClone<'tcx> {
1813-
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
1813+
fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
18141814
Self { tcx, typeck_results: tcx.typeck(def_id), clones: vec![] }
18151815
}
18161816
}
@@ -1832,7 +1832,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
18321832
let body = hir.body(body_id).value;
18331833
expr_finder.visit_expr(body);
18341834

1835-
pub struct Holds<'tcx> {
1835+
struct Holds<'tcx> {
18361836
ty: Ty<'tcx>,
18371837
}
18381838

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ impl<'tcx> Visitor<'tcx> for BindingFinder {
13751375
}
13761376
}
13771377

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

13811381
match *local_decl.local_info() {

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,24 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
8080
pub(crate) struct RegionErrors<'tcx>(Vec<(RegionErrorKind<'tcx>, ErrorGuaranteed)>, TyCtxt<'tcx>);
8181

8282
impl<'tcx> RegionErrors<'tcx> {
83-
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
83+
pub(crate) fn new(tcx: TyCtxt<'tcx>) -> Self {
8484
Self(vec![], tcx)
8585
}
8686
#[track_caller]
87-
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
87+
pub(crate) fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
8888
let val = val.into();
8989
let guar = self.1.sess.dcx().delayed_bug(format!("{val:?}"));
9090
self.0.push((val, guar));
9191
}
92-
pub fn is_empty(&self) -> bool {
92+
pub(crate) fn is_empty(&self) -> bool {
9393
self.0.is_empty()
9494
}
95-
pub fn into_iter(self) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
95+
pub(crate) fn into_iter(
96+
self,
97+
) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
9698
self.0.into_iter()
9799
}
98-
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
100+
pub(crate) fn has_errors(&self) -> Option<ErrorGuaranteed> {
99101
self.0.get(0).map(|x| x.1)
100102
}
101103
}
@@ -149,7 +151,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
149151

150152
/// Information about the various region constraints involved in a borrow checker error.
151153
#[derive(Clone, Debug)]
152-
pub struct ErrorConstraintInfo<'tcx> {
154+
pub(crate) struct ErrorConstraintInfo<'tcx> {
153155
// fr: outlived_fr
154156
pub(super) fr: RegionVid,
155157
pub(super) fr_is_local: bool,

compiler/rustc_borrowck/src/lib.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
// tidy-alphabetical-start
44
#![allow(internal_features)]
5+
#![deny(unreachable_pub)]
56
#![doc(rust_logo)]
67
#![feature(assert_matches)]
78
#![feature(box_patterns)]
@@ -2441,7 +2442,7 @@ mod diags {
24412442
}
24422443
}
24432444

2444-
pub struct BorrowckDiags<'infcx, 'tcx> {
2445+
pub(crate) struct BorrowckDiags<'infcx, 'tcx> {
24452446
/// This field keeps track of move errors that are to be reported for given move indices.
24462447
///
24472448
/// There are situations where many errors can be reported for a single move out (see
@@ -2465,33 +2466,33 @@ mod diags {
24652466
}
24662467

24672468
impl<'infcx, 'tcx> BorrowckDiags<'infcx, 'tcx> {
2468-
pub fn new() -> Self {
2469+
pub(crate) fn new() -> Self {
24692470
BorrowckDiags {
24702471
buffered_move_errors: BTreeMap::new(),
24712472
buffered_mut_errors: Default::default(),
24722473
buffered_diags: Default::default(),
24732474
}
24742475
}
24752476

2476-
pub fn buffer_error(&mut self, diag: Diag<'infcx>) {
2477+
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
24772478
self.buffered_diags.push(BufferedDiag::Error(diag));
24782479
}
24792480

2480-
pub fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
2481+
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
24812482
self.buffered_diags.push(BufferedDiag::NonError(diag));
24822483
}
24832484
}
24842485

24852486
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
2486-
pub fn buffer_error(&mut self, diag: Diag<'infcx>) {
2487+
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
24872488
self.diags.buffer_error(diag);
24882489
}
24892490

2490-
pub fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
2491+
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
24912492
self.diags.buffer_non_error(diag);
24922493
}
24932494

2494-
pub fn buffer_move_error(
2495+
pub(crate) fn buffer_move_error(
24952496
&mut self,
24962497
move_out_indices: Vec<MoveOutIndex>,
24972498
place_and_err: (PlaceRef<'tcx>, Diag<'infcx>),
@@ -2507,16 +2508,19 @@ mod diags {
25072508
}
25082509
}
25092510

2510-
pub fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'infcx>, usize)> {
2511+
pub(crate) fn get_buffered_mut_error(
2512+
&mut self,
2513+
span: Span,
2514+
) -> Option<(Diag<'infcx>, usize)> {
25112515
// FIXME(#120456) - is `swap_remove` correct?
25122516
self.diags.buffered_mut_errors.swap_remove(&span)
25132517
}
25142518

2515-
pub fn buffer_mut_error(&mut self, span: Span, diag: Diag<'infcx>, count: usize) {
2519+
pub(crate) fn buffer_mut_error(&mut self, span: Span, diag: Diag<'infcx>, count: usize) {
25162520
self.diags.buffered_mut_errors.insert(span, (diag, count));
25172521
}
25182522

2519-
pub fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
2523+
pub(crate) fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
25202524
let mut res = None;
25212525

25222526
// Buffer any move errors that we collected and de-duplicated.
@@ -2550,7 +2554,7 @@ mod diags {
25502554
self.diags.buffered_diags.is_empty()
25512555
}
25522556

2553-
pub fn has_move_error(
2557+
pub(crate) fn has_move_error(
25542558
&self,
25552559
move_out_indices: &[MoveOutIndex],
25562560
) -> Option<&(PlaceRef<'tcx>, Diag<'infcx>)> {

0 commit comments

Comments
 (0)