Skip to content

Commit ccf6b1c

Browse files
committed
Add deny(unreachable_pub) to rustc_borrowck.
1 parent dc4db38 commit ccf6b1c

18 files changed

+74
-68
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

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

1111
impl<'infcx, 'tcx> crate::MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
12-
pub fn dcx(&self) -> DiagCtxtHandle<'infcx> {
12+
pub(crate) fn dcx(&self) -> DiagCtxtHandle<'infcx> {
1313
self.infcx.dcx()
1414
}
1515

compiler/rustc_borrowck/src/dataflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use rustc_mir_dataflow::{Analysis, AnalysisDomain, GenKill, Results, ResultsVisi
1414
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
1515

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
645645
}
646646
}
647647

648-
pub fn suggest_reborrow(
648+
pub(crate) fn suggest_reborrow(
649649
&self,
650650
err: &mut Diag<'infcx>,
651651
span: Span,
@@ -1891,10 +1891,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
18911891
struct FindUselessClone<'tcx> {
18921892
tcx: TyCtxt<'tcx>,
18931893
typeck_results: &'tcx ty::TypeckResults<'tcx>,
1894-
pub clones: Vec<&'tcx hir::Expr<'tcx>>,
1894+
clones: Vec<&'tcx hir::Expr<'tcx>>,
18951895
}
18961896
impl<'tcx> FindUselessClone<'tcx> {
1897-
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
1897+
fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
18981898
Self { tcx, typeck_results: tcx.typeck(def_id), clones: vec![] }
18991899
}
19001900
}
@@ -1916,7 +1916,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
19161916
let body = hir.body(body_id).value;
19171917
expr_finder.visit_expr(body);
19181918

1919-
pub struct Holds<'tcx> {
1919+
struct Holds<'tcx> {
19201920
ty: Ty<'tcx>,
19211921
}
19221922

compiler/rustc_borrowck/src/diagnostics/mod.rs

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

6060
pub(super) struct DescribePlaceOpt {
61-
pub including_downcast: bool,
61+
including_downcast: bool,
6262

6363
/// Enable/Disable tuple fields.
6464
/// For example `x` tuple. if it's `true` `x.0`. Otherwise `x`
65-
pub including_tuple_field: bool,
65+
including_tuple_field: bool,
6666
}
6767

6868
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
@@ -16,7 +16,7 @@ use crate::prefixes::PrefixSet;
1616
use crate::MirBorrowckCtxt;
1717

1818
#[derive(Debug)]
19-
pub enum IllegalMoveOriginKind<'tcx> {
19+
pub(crate) enum IllegalMoveOriginKind<'tcx> {
2020
/// Illegal move due to attempt to move from behind a reference.
2121
BorrowedContent {
2222
/// 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
@@ -1374,7 +1374,7 @@ impl<'tcx> Visitor<'tcx> for BindingFinder {
13741374
}
13751375
}
13761376

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

13801380
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

+8-6
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,24 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
7272
pub(crate) struct RegionErrors<'tcx>(Vec<(RegionErrorKind<'tcx>, ErrorGuaranteed)>, TyCtxt<'tcx>);
7373

7474
impl<'tcx> RegionErrors<'tcx> {
75-
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
75+
pub(crate) fn new(tcx: TyCtxt<'tcx>) -> Self {
7676
Self(vec![], tcx)
7777
}
7878
#[track_caller]
79-
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
79+
pub(crate) fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
8080
let val = val.into();
8181
let guar = self.1.sess.dcx().delayed_bug(format!("{val:?}"));
8282
self.0.push((val, guar));
8383
}
84-
pub fn is_empty(&self) -> bool {
84+
pub(crate) fn is_empty(&self) -> bool {
8585
self.0.is_empty()
8686
}
87-
pub fn into_iter(self) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
87+
pub(crate) fn into_iter(
88+
self,
89+
) -> impl Iterator<Item = (RegionErrorKind<'tcx>, ErrorGuaranteed)> {
8890
self.0.into_iter()
8991
}
90-
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
92+
pub(crate) fn has_errors(&self) -> Option<ErrorGuaranteed> {
9193
self.0.get(0).map(|x| x.1)
9294
}
9395
}
@@ -141,7 +143,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
141143

142144
/// Information about the various region constraints involved in a borrow checker error.
143145
#[derive(Clone, Debug)]
144-
pub struct ErrorConstraintInfo<'tcx> {
146+
pub(crate) struct ErrorConstraintInfo<'tcx> {
145147
// fr: outlived_fr
146148
pub(super) fr: RegionVid,
147149
pub(super) fr_is_local: bool,

compiler/rustc_borrowck/src/lib.rs

+15-11
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)]
@@ -2444,7 +2445,7 @@ mod diags {
24442445
}
24452446
}
24462447

2447-
pub struct BorrowckDiags<'infcx, 'tcx> {
2448+
pub(crate) struct BorrowckDiags<'infcx, 'tcx> {
24482449
/// This field keeps track of move errors that are to be reported for given move indices.
24492450
///
24502451
/// There are situations where many errors can be reported for a single move out (see
@@ -2468,33 +2469,33 @@ mod diags {
24682469
}
24692470

24702471
impl<'infcx, 'tcx> BorrowckDiags<'infcx, 'tcx> {
2471-
pub fn new() -> Self {
2472+
pub(crate) fn new() -> Self {
24722473
BorrowckDiags {
24732474
buffered_move_errors: BTreeMap::new(),
24742475
buffered_mut_errors: Default::default(),
24752476
buffered_diags: Default::default(),
24762477
}
24772478
}
24782479

2479-
pub fn buffer_error(&mut self, diag: Diag<'infcx>) {
2480+
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
24802481
self.buffered_diags.push(BufferedDiag::Error(diag));
24812482
}
24822483

2483-
pub fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
2484+
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
24842485
self.buffered_diags.push(BufferedDiag::NonError(diag));
24852486
}
24862487
}
24872488

24882489
impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
2489-
pub fn buffer_error(&mut self, diag: Diag<'infcx>) {
2490+
pub(crate) fn buffer_error(&mut self, diag: Diag<'infcx>) {
24902491
self.diags.buffer_error(diag);
24912492
}
24922493

2493-
pub fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
2494+
pub(crate) fn buffer_non_error(&mut self, diag: Diag<'infcx, ()>) {
24942495
self.diags.buffer_non_error(diag);
24952496
}
24962497

2497-
pub fn buffer_move_error(
2498+
pub(crate) fn buffer_move_error(
24982499
&mut self,
24992500
move_out_indices: Vec<MoveOutIndex>,
25002501
place_and_err: (PlaceRef<'tcx>, Diag<'infcx>),
@@ -2510,16 +2511,19 @@ mod diags {
25102511
}
25112512
}
25122513

2513-
pub fn get_buffered_mut_error(&mut self, span: Span) -> Option<(Diag<'infcx>, usize)> {
2514+
pub(crate) fn get_buffered_mut_error(
2515+
&mut self,
2516+
span: Span,
2517+
) -> Option<(Diag<'infcx>, usize)> {
25142518
// FIXME(#120456) - is `swap_remove` correct?
25152519
self.diags.buffered_mut_errors.swap_remove(&span)
25162520
}
25172521

2518-
pub fn buffer_mut_error(&mut self, span: Span, diag: Diag<'infcx>, count: usize) {
2522+
pub(crate) fn buffer_mut_error(&mut self, span: Span, diag: Diag<'infcx>, count: usize) {
25192523
self.diags.buffered_mut_errors.insert(span, (diag, count));
25202524
}
25212525

2522-
pub fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
2526+
pub(crate) fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
25232527
let mut res = None;
25242528

25252529
// Buffer any move errors that we collected and de-duplicated.
@@ -2553,7 +2557,7 @@ mod diags {
25532557
self.diags.buffered_diags.is_empty()
25542558
}
25552559

2556-
pub fn has_move_error(
2560+
pub(crate) fn has_move_error(
25572561
&self,
25582562
move_out_indices: &[MoveOutIndex],
25592563
) -> Option<&(PlaceRef<'tcx>, Diag<'infcx>)> {

compiler/rustc_borrowck/src/prefixes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::{PlaceRef, ProjectionElem};
88

99
use super::MirBorrowckCtxt;
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ mod graphviz;
4242
mod opaque_types;
4343
mod reverse_sccs;
4444

45-
pub mod values;
45+
pub(crate) mod values;
4646

47-
pub type ConstraintSccs = Sccs<RegionVid, ConstraintSccIndex, RegionTracker>;
47+
pub(crate) type ConstraintSccs = Sccs<RegionVid, ConstraintSccIndex, RegionTracker>;
4848

4949
/// An annotation for region graph SCCs that tracks
5050
/// the values of its elements.
@@ -226,7 +226,7 @@ pub(crate) struct AppliedMemberConstraint {
226226
}
227227

228228
#[derive(Debug)]
229-
pub struct RegionDefinition<'tcx> {
229+
pub(crate) struct RegionDefinition<'tcx> {
230230
/// What kind of variable is this -- a free region? existential
231231
/// variable? etc. (See the `NllRegionVariableOrigin` for more
232232
/// info.)
@@ -288,7 +288,7 @@ pub(crate) enum Cause {
288288
/// `InferCtxt::process_registered_region_obligations` and
289289
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
290290
#[derive(Clone, Debug)]
291-
pub struct TypeTest<'tcx> {
291+
pub(crate) struct TypeTest<'tcx> {
292292
/// The type `T` that must outlive the region.
293293
pub generic_kind: GenericKind<'tcx>,
294294

@@ -320,7 +320,7 @@ enum Trace<'tcx> {
320320
}
321321

322322
#[derive(Clone, PartialEq, Eq, Debug)]
323-
pub enum ExtraConstraintInfo {
323+
pub(crate) enum ExtraConstraintInfo {
324324
PlaceholderFromPredicate(Span),
325325
}
326326

@@ -2259,7 +2259,7 @@ impl<'tcx> RegionDefinition<'tcx> {
22592259
}
22602260

22612261
#[derive(Clone, Debug)]
2262-
pub struct BlameConstraint<'tcx> {
2262+
pub(crate) struct BlameConstraint<'tcx> {
22632263
pub category: ConstraintCategory<'tcx>,
22642264
pub from_closure: bool,
22652265
pub cause: ObligationCause<'tcx>,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -473,20 +473,20 @@ struct LazyOpaqueTyEnv<'tcx> {
473473
}
474474

475475
impl<'tcx> LazyOpaqueTyEnv<'tcx> {
476-
pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
476+
fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self {
477477
Self { tcx, def_id, canonical_args: std::cell::OnceCell::new() }
478478
}
479479

480-
pub fn param_equal_static(&self, param_index: usize) -> bool {
480+
fn param_equal_static(&self, param_index: usize) -> bool {
481481
self.get_canonical_args()[param_index].expect_region().is_static()
482482
}
483483

484-
pub fn params_equal(&self, param1: usize, param2: usize) -> bool {
484+
fn params_equal(&self, param1: usize, param2: usize) -> bool {
485485
let canonical_args = self.get_canonical_args();
486486
canonical_args[param1] == canonical_args[param2]
487487
}
488488

489-
pub fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> {
489+
fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> {
490490
self.get_canonical_args()[param_index].error_reported()
491491
}
492492

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ macro_rules! span_mirbug_and_err {
8686

8787
mod canonical;
8888
mod constraint_conversion;
89-
pub mod free_region_relations;
89+
pub(crate) mod free_region_relations;
9090
mod input_output;
9191
pub(crate) mod liveness;
9292
mod relate_tys;

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
5757
}
5858
}
5959

60-
pub struct NllTypeRelating<'me, 'bccx, 'tcx> {
60+
struct NllTypeRelating<'me, 'bccx, 'tcx> {
6161
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
6262

6363
/// Where (and why) is this relation taking place?
@@ -82,7 +82,7 @@ pub struct NllTypeRelating<'me, 'bccx, 'tcx> {
8282
}
8383

8484
impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
85-
pub fn new(
85+
fn new(
8686
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
8787
locations: Locations,
8888
category: ConstraintCategory<'tcx>,

0 commit comments

Comments
 (0)